diff --git a/README.md b/README.md index 91007b69..927ed34a 100644 --- a/README.md +++ b/README.md @@ -1066,6 +1066,8 @@ You can find more examples in the `examples` directory of this repository. * **highWaterMark** - _integer_ - This is the `highWaterMark` to use for the parser stream. **Default:** `32 * 1024` + * **server** - _object_ - This option allow you to explicitly define the tcp server `ssh2` is going to use. **Default:** `new net.Server()` + * **debug** - _function_ - Set this to a function that receives a single string argument to get detailed (local) debug information. **Default:** (none) #### Connection events diff --git a/lib/server.js b/lib/server.js index 9137cdf9..fdf0e806 100644 --- a/lib/server.js +++ b/lib/server.js @@ -318,7 +318,10 @@ class Server extends EventEmitter { const ident = (cfg.ident ? Buffer.from(cfg.ident) : undefined); const offer = new KexInit(algorithms); - this._srv = new netServer((socket) => { + this._srv = cfg.server || new netServer(); + + this._srv.on('connection', (socket) => { + if (this._connections >= this.maxConnections) { socket.destroy(); return;