Permalink
Browse files

parsing version end-to-end, buffer size miscalculated

  • Loading branch information...
1 parent 329191f commit 28815eb4bfd13eda172bf66096cc2d6593ff2b6c @substack substack committed Dec 14, 2010
Showing with 24 additions and 15 deletions.
  1. +16 −9 lib/clients/socks5.js
  2. +2 −1 lib/servers/socks5.js
  3. +6 −5 test/proxy.js
View
@@ -1,6 +1,7 @@
var Put = require('put');
var Binary = require('binary');
var net = require('net');
+var EventEmitter = require('events').EventEmitter;
module.exports = function () {
var params = {};
@@ -29,14 +30,17 @@ module.exports = function () {
}
};
-function fromStream (stream) {
+function fromStream (stream, cb) {
var auth = null;
- stream.auth = function (user, pass) {
+ var self = new EventEmitter;
+
+ self.auth = function (user, pass) {
return self;
};
- var binary = Binary(stream);
- stream.connect = function (addr, port) {
+ stream.on('end', function () { self.emit('end') });
+
+ self.connect = function (addr, port) {
if (stream.readyState === 'open' || stream.readyState === 'readOnly') {
connect(addr, port);
}
@@ -46,7 +50,7 @@ function fromStream (stream) {
});
}
- return stream;
+ return self;
};
var methods = new Buffer([
@@ -56,7 +60,7 @@ function fromStream (stream) {
]);
function connect (addr, port) {
- binary = binary
+ Binary(stream)
.word8('ver')
.word8('method')
.tap(function (vars) {
@@ -66,8 +70,11 @@ function fromStream (stream) {
console.log('No supported methods');
}
else {
- var dst = atype(addr);
+ self.emit('connect');
+ stream.on('data', self.emit.bind(self, 'data'));
+ var dst = atype(addr);
+ console.dir(dst.buffer);
Put()
.word8(5)
.word8(1) // connect
@@ -89,12 +96,12 @@ function fromStream (stream) {
.write(stream)
;
- return stream;
+ return self;
}
module.exports.atype = atype;
function atype (addr) {
- var ipv = process.binding('net').isIp(addr);
+ var ipv = process.binding('net').isIP(addr);
if (ipv === 0) {
var buf = new Buffer('x' + addr);
View
@@ -17,7 +17,8 @@ function session (stream, cb) {
var methods = [].slice.call(vars.methods)
.reduce(function (acc,m) { acc[m] = true; return acc }, {});
// username + password only
- var method = methods[2] ? 0x02 : 0xff;
+ //var method = methods[2] ? 0x02 : 0xff;
+ var method = methods[0] ? 0x00 : 0xff;
Put().word8(5).word8(method).write(stream);
})
View
@@ -9,6 +9,10 @@ exports.socks5 = function (assert) {
var tc = setTimeout(function () {
assert.fail('Never connected');
}, 500);
+
+ var td = setTimeout(function () {
+ assert.fail('Never got data');
+ }, 500);
socks5.createServer(function (err, req, stream) {
assert.eql(req.host, 'moo');
@@ -26,12 +30,9 @@ exports.socks5 = function (assert) {
clearTimeout(tc);
});
- stream.on('error', function (msg) {
- assert.fail(msg);
- });
-
stream.on('data', function (buf) {
- assert.eql(buf, new Buffer('oh hello'));
+ clearTimeout(td);
+ assert.eql(buf.toString(), 'oh hello');
});
stream.on('end', function () {

0 comments on commit 28815eb

Please sign in to comment.