Permalink
Browse files

basic proxy test passes

  • Loading branch information...
1 parent 28815eb commit d82e500705173e857d5916f239efb77af1c5b01c @substack substack committed Dec 14, 2010
Showing with 13 additions and 11 deletions.
  1. +3 −4 lib/clients/socks5.js
  2. +0 −1 lib/servers/socks5.js
  3. +10 −6 test/proxy.js
View
@@ -39,6 +39,8 @@ function fromStream (stream, cb) {
};
stream.on('end', function () { self.emit('end') });
+ self.end = stream.end.bind(stream);
+ self.destroy = stream.destroy.bind(stream);
self.connect = function (addr, port) {
if (stream.readyState === 'open' || stream.readyState === 'readOnly') {
@@ -64,8 +66,6 @@ function fromStream (stream, cb) {
.word8('ver')
.word8('method')
.tap(function (vars) {
- console.dir(vars);
-
if (vars.method === 0xff) {
console.log('No supported methods');
}
@@ -74,7 +74,6 @@ function fromStream (stream, cb) {
stream.on('data', self.emit.bind(self, 'data'));
var dst = atype(addr);
- console.dir(dst.buffer);
Put()
.word8(5)
.word8(1) // connect
@@ -105,7 +104,7 @@ function atype (addr) {
if (ipv === 0) {
var buf = new Buffer('x' + addr);
- buf[0] = buf.length;
+ buf[0] = buf.length - 1;
return {
code : 0x03,
name : 'domain',
View
@@ -71,7 +71,6 @@ function session (stream, cb) {
host : dst.addr,
port : dst.port,
}, stream);
- console.log(dst.addr + ':' + dst.port);
})
})
;
View
@@ -2,23 +2,25 @@ var socks5 = require('prox').socks5;
exports.socks5 = function (assert) {
var port = Math.floor(10000 + Math.random() * (Math.pow(2,16) - 10000));
- var to = setTimeout(function () {
- assert.fail('Never got request');
- }, 500);
-
var tc = setTimeout(function () {
assert.fail('Never connected');
}, 500);
var td = setTimeout(function () {
assert.fail('Never got data');
}, 500);
+
+ var to = setTimeout(function () {
+ assert.fail('Never ended');
+ }, 500);
- socks5.createServer(function (err, req, stream) {
+ var server = socks5.createServer(function (err, req, stream) {
assert.eql(req.host, 'moo');
assert.eql(req.port, 8080);
stream.write(new Buffer('oh hello'));
- }).listen(port, ready);
+ stream.end();
+ });
+ server.listen(port, ready);
function ready () {
var stream = socks5
@@ -33,10 +35,12 @@ exports.socks5 = function (assert) {
stream.on('data', function (buf) {
clearTimeout(td);
assert.eql(buf.toString(), 'oh hello');
+ stream.end();
});
stream.on('end', function () {
clearTimeout(to);
+ server.close();
});
}
};

0 comments on commit d82e500

Please sign in to comment.