added option to specify port range for client ports
This commit is contained in:
+19
-7
@@ -4,8 +4,12 @@ import assert from 'assert';
|
||||
import log from 'book';
|
||||
import Debug from 'debug';
|
||||
|
||||
import { getPort } from 'portfinder';
|
||||
const DEFAULT_MAX_SOCKETS = 10;
|
||||
|
||||
const DEFAULT_MIN_PORT_RANGE = 1024;
|
||||
const DEFAULT_MAX_PORT_RANGE = 65535;
|
||||
|
||||
// Implements an http.Agent interface to a pool of tunnel sockets
|
||||
// A tunnel socket is a connection _from_ a client that will
|
||||
// service http requests. This agent is usable wherever one can use an http.Agent
|
||||
@@ -31,6 +35,9 @@ class TunnelAgent extends Agent {
|
||||
this.connectedSockets = 0;
|
||||
this.maxTcpSockets = options.maxTcpSockets || DEFAULT_MAX_SOCKETS;
|
||||
|
||||
this.client_min_port_range = options.client_min_port_range || DEFAULT_MIN_PORT_RANGE;
|
||||
this.client_max_port_range = options.client_max_port_range || DEFAULT_MAX_PORT_RANGE;
|
||||
|
||||
// new tcp server to service requests for this client
|
||||
this.server = net.createServer();
|
||||
|
||||
@@ -63,14 +70,19 @@ class TunnelAgent extends Agent {
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
server.listen(() => {
|
||||
const port = server.address().port;
|
||||
this.debug('tcp server listening on port: %d', port);
|
||||
getPort({
|
||||
port: this.client_min_port_range, // minimum port
|
||||
stopPort: this.client_max_port_range // maximum port
|
||||
}, (err,port) => {
|
||||
server.listen(port,() => {
|
||||
const port = server.address().port;
|
||||
this.debug('tcp server listening on port: %d', port);
|
||||
|
||||
resolve({
|
||||
// port for lt client tcp connections
|
||||
port: port,
|
||||
});
|
||||
resolve({
|
||||
// port for lt client tcp connections
|
||||
port: port,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user