dispatch-proxy
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -29,2 +29,9 @@ var Dispatcher, SocksDispatcher, colog, net, socks, | ||
}); | ||
_this.emit('connection', { | ||
client: clientConnection, | ||
server: serverConnection, | ||
localAddress: localAddress, | ||
host: host, | ||
port: port | ||
}); | ||
serverConnection.on('connect', function() { | ||
@@ -35,10 +42,2 @@ var _base, _name; | ||
return _this.connectionsTotal++; | ||
}).on('error', function(err) { | ||
clientConnection.end(); | ||
return _this.emit('error', { | ||
type: 'serverConnection', | ||
host: host, | ||
port: port, | ||
localAddress: localAddress | ||
}, err); | ||
}).on('end', function() { | ||
@@ -50,11 +49,2 @@ _this.connectionsTotal--; | ||
}); | ||
clientConnection.on('error', function(err) { | ||
serverConnection.end(); | ||
return _this.emit('error', { | ||
type: 'clientConnection', | ||
host: host, | ||
port: port, | ||
localAddress: localAddress | ||
}, err); | ||
}); | ||
clientConnection.pipe(serverConnection); | ||
@@ -64,5 +54,3 @@ return serverConnection.pipe(clientConnection); | ||
this.server.on('error', function(err) { | ||
return _this.emit('error', { | ||
type: 'server' | ||
}, err); | ||
return _this.emit('error', err); | ||
}); | ||
@@ -69,0 +57,0 @@ this.server.listen(listenPort, listenHost); |
@@ -1,2 +0,2 @@ | ||
var HttpDispatcher, SocksDispatcher, colog, os, print, program, | ||
var HttpDispatcher, SocksDispatcher, colog, crypto, os, print, program, | ||
__slice = [].slice; | ||
@@ -8,2 +8,4 @@ | ||
crypto = require('crypto'); | ||
program = require('commander'); | ||
@@ -46,6 +48,6 @@ | ||
program.command('start').usage('[options] [addresses]').description('start a proxy server').option('-H, --host <h>', 'which host to accept connections from (defaults to localhost)', String).option('-p, --port <p>', 'which port to listen to for connections (defaults to 8080 for HTTP proxy, 1080 for SOCKS proxy)', Number).option('--http', 'start an http proxy server', Boolean).action(function() { | ||
var addr, address, addresses, addrs, arg, args, dispatcher, host, http, https, name, port, priority, type, _arg, _i, _j, _k, _len, _len1, _ref, _ref1; | ||
program.command('start').usage('[options] [addresses]').description('start a proxy server').option('-H, --host <h>', 'which host to accept connections from (defaults to localhost)', String).option('-p, --port <p>', 'which port to listen to for connections (defaults to 8080 for HTTP proxy, 1080 for SOCKS proxy)', Number).option('--http', 'start an http proxy server', Boolean).option('--debug', 'logs connections and errors', Boolean).action(function() { | ||
var addr, address, addresses, addrs, arg, args, debug, dispatcher, host, http, https, name, port, priority, type, _arg, _i, _j, _k, _len, _len1, _ref, _ref1; | ||
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), _arg = arguments[_i++]; | ||
port = _arg.port, host = _arg.host, http = _arg.http, https = _arg.https; | ||
port = _arg.port, host = _arg.host, http = _arg.http, https = _arg.https, debug = _arg.debug; | ||
addresses = []; | ||
@@ -86,4 +88,26 @@ if (args.length === 0) { | ||
dispatcher = new SocksDispatcher(addresses, port, host); | ||
if (debug) { | ||
dispatcher.on('connection', function(_arg1) { | ||
var client, host, id, localAddress, port, server; | ||
client = _arg1.client, server = _arg1.server, host = _arg1.host, port = _arg1.port, localAddress = _arg1.localAddress; | ||
id = (crypto.randomBytes(3)).toString('hex'); | ||
console.log("" + (colog.yellow(id)) + " - Received connection to " + (colog.cyan("" + host + ":" + port)) + ", dispatching to " + (colog.cyan("" + localAddress.address + "@" + localAddress.priority)) + "."); | ||
server.on('connect', function() { | ||
return console.log("" + (colog.green(id)) + " - Successfully connected to " + (colog.cyan("" + host + ":" + port)) + " (" + (colog.cyan("" + server.remoteAddress + ":" + server.remotePort)) + ") from " + (colog.cyan("" + server.localAddress + ":" + server.localPort)) + "."); | ||
}).on('error', function(err) { | ||
return console.log("" + (colog.red(id)) + " - serverConnection error\n" + (' ' + (err.stack.replace(/\n/g, '\n ')))); | ||
}).on('end', function() { | ||
return console.log("" + (colog.yellow(id)) + " - serverConnection ended"); | ||
}); | ||
return client.on('error', function(err) { | ||
return console.log("" + (colog.red(id)) + " - clientConnection error\n" + (' ' + (err.stack.replace(/\n/g, '\n ')))); | ||
}).on('end', function() { | ||
return console.log("" + (colog.yellow(id)) + " - clientConnection ended"); | ||
}); | ||
}).on('error', function(err) { | ||
return console.log("" + (colog.red("server error")) + "\n" + err.stack); | ||
}); | ||
} | ||
} | ||
console.log("" + type + " server started on " + (colog.green("" + host + ":" + port)) + "\nDispatching to addresses " + (((function() { | ||
return console.log("" + type + " server started on " + (colog.green("" + host + ":" + port)) + "\nDispatching to addresses " + (((function() { | ||
var _l, _len2, _ref2, _results; | ||
@@ -97,14 +121,4 @@ _results = []; | ||
})()).join(', '))); | ||
return dispatcher.on('error', function(_arg1, err) { | ||
var host, localAddress , port, type; | ||
type = _arg1.type, host = _arg1.host, port = _arg1.port, localAddress = _arg1.localAddress ; | ||
if (type === 'server') { | ||
console.log("" + (colog.red("" + type + " error"))); | ||
} else { | ||
console.log("" + (colog.red("" + type + " error: ")) + " " + host + ":" + port + " on " + localAddress.address); | ||
} | ||
return print(err.stack); | ||
}); | ||
}); | ||
program.parse(process.argv); |
@@ -5,3 +5,3 @@ { | ||
"author": "Alexandre Kirszenberg <a.kirszenberg@gmail.com>", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
@@ -8,0 +8,0 @@ "repository": { |
23624
503