bunch of changes
This commit is contained in:
+10
-7
@@ -1,10 +1,10 @@
|
||||
import { Agent } from 'http';
|
||||
import net from 'net';
|
||||
import assert from 'assert';
|
||||
import log from 'book';
|
||||
import Debug from 'debug';
|
||||
|
||||
const DEFAULT_MAX_SOCKETS = 10;
|
||||
const DEFAULT_SOCKET_TIMEOUT = 10 * 60 * 1000;
|
||||
|
||||
// Implements an http.Agent interface to a pool of tunnel sockets
|
||||
// A tunnel socket is a connection _from_ a client that will
|
||||
@@ -33,6 +33,8 @@ class TunnelAgent extends Agent {
|
||||
|
||||
// new tcp server to service requests for this client
|
||||
this.server = net.createServer();
|
||||
|
||||
this._socketTimeout = options.socketTimeout || DEFAULT_SOCKET_TIMEOUT;
|
||||
|
||||
// flag to avoid double starts
|
||||
this.started = false;
|
||||
@@ -46,15 +48,14 @@ class TunnelAgent extends Agent {
|
||||
}
|
||||
|
||||
listen() {
|
||||
const server = this.server;
|
||||
if (this.started) {
|
||||
throw new Error('already started');
|
||||
}
|
||||
this.started = true;
|
||||
|
||||
server.on('close', this._onClose.bind(this));
|
||||
server.on('connection', this._onConnection.bind(this));
|
||||
server.on('error', (err) => {
|
||||
this.server.on('close', this._onClose.bind(this));
|
||||
this.server.on('connection', this._onConnection.bind(this));
|
||||
this.server.on('error', (err) => {
|
||||
// These errors happen from killed connections, we don't worry about them
|
||||
if (err.code == 'ECONNRESET' || err.code == 'ETIMEDOUT') {
|
||||
return;
|
||||
@@ -63,8 +64,8 @@ class TunnelAgent extends Agent {
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
server.listen(() => {
|
||||
const port = server.address().port;
|
||||
this.server.listen(() => {
|
||||
const port = this.server.address().port;
|
||||
this.debug('tcp server listening on port: %d', port);
|
||||
|
||||
resolve({
|
||||
@@ -88,6 +89,8 @@ class TunnelAgent extends Agent {
|
||||
|
||||
// new socket connection from client for tunneling requests to client
|
||||
_onConnection(socket) {
|
||||
console.log('!!!!!!', socket);
|
||||
socket.setTimeout(this._socketTimeout);
|
||||
// no more socket connections allowed
|
||||
if (this.connectedSockets >= this.maxTcpSockets) {
|
||||
this.debug('no more sockets allowed');
|
||||
|
||||
Reference in New Issue
Block a user