socks: error handling.
This commit is contained in:
parent
b8cd9893fb
commit
c6aad6448c
@ -67,23 +67,26 @@ SOCKS.errors = [
|
|||||||
'Unknown proxy error'
|
'Unknown proxy error'
|
||||||
];
|
];
|
||||||
|
|
||||||
SOCKS.prototype.error = function error(msg) {
|
SOCKS.prototype.error = function error(err) {
|
||||||
|
var msg;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (msg instanceof Error) {
|
if (err instanceof Error) {
|
||||||
this.emit('error', msg);
|
this.emit('error', err);
|
||||||
this.destroy();
|
this.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msg = util.fmt.apply(util, arguments);
|
||||||
this.emit('error', new Error(msg));
|
this.emit('error', new Error(msg));
|
||||||
this.destroy();
|
this.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
SOCKS.prototype.getError = function getError(code) {
|
SOCKS.prototype.getError = function getError(code) {
|
||||||
if (code >= SOCKS.errors.length)
|
if (code >= SOCKS.errors.length)
|
||||||
return 'Unknown';
|
return SOCKS.errors[9];
|
||||||
|
|
||||||
return SOCKS.errors[code];
|
return SOCKS.errors[code];
|
||||||
};
|
};
|
||||||
@ -108,7 +111,7 @@ SOCKS.prototype.startTimeout = function startTimeout() {
|
|||||||
this.timeout = setTimeout(function() {
|
this.timeout = setTimeout(function() {
|
||||||
var state = SOCKS.statesByVal[self.state];
|
var state = SOCKS.statesByVal[self.state];
|
||||||
self.timeout = null;
|
self.timeout = null;
|
||||||
self.error('SOCKS request timed out (state=' + state + ').');
|
self.error('SOCKS request timed out (state=%s).', state);
|
||||||
}, 8000);
|
}, 8000);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -210,7 +213,7 @@ SOCKS.prototype.handleClose = function handleClose() {
|
|||||||
|
|
||||||
if (this.state !== this.target) {
|
if (this.state !== this.target) {
|
||||||
state = SOCKS.statesByVal[this.target];
|
state = SOCKS.statesByVal[this.target];
|
||||||
this.error('SOCKS request destroyed (target=' + state + ').');
|
this.error('SOCKS request destroyed (state=%s).', state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +294,7 @@ SOCKS.prototype.handleHandshake = function handleHandshake(data) {
|
|||||||
this.auth();
|
this.auth();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.error('SOCKS handshake error: ' + data[1]);
|
this.error('SOCKS handshake error: %d.', data[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -339,7 +342,7 @@ SOCKS.prototype.handleAuth = function handleAuth(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data[1] !== 0x00) {
|
if (data[1] !== 0x00) {
|
||||||
this.error('SOCKS auth failure: ' + data[0]);
|
this.error('SOCKS auth failure: %d.', data[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +410,7 @@ SOCKS.prototype.sendProxy = function sendProxy() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SOCKS.prototype.handleProxy = function handleProxy(data) {
|
SOCKS.prototype.handleProxy = function handleProxy(data) {
|
||||||
var br, len, host, port, err;
|
var br, len, host, port, msg;
|
||||||
|
|
||||||
if (data.length < 6) {
|
if (data.length < 6) {
|
||||||
this.error('Bad packet size for SOCKS connect.');
|
this.error('Bad packet size for SOCKS connect.');
|
||||||
@ -420,8 +423,8 @@ SOCKS.prototype.handleProxy = function handleProxy(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data[1] !== 0x00) {
|
if (data[1] !== 0x00) {
|
||||||
err = this.getError(data[1]);
|
msg = this.getError(data[1]);
|
||||||
this.error('SOCKS connect error: ' + err);
|
this.error('SOCKS connect error: %s.', msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +463,7 @@ SOCKS.prototype.handleProxy = function handleProxy(data) {
|
|||||||
port = br.readU16BE();
|
port = br.readU16BE();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.error('Unknown SOCKS connect response: ' + data[4]);
|
this.error('Unknown SOCKS address type: %d.', data[4]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,7 +494,7 @@ SOCKS.prototype.sendResolve = function sendResolve() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SOCKS.prototype.handleResolve = function handleResolve(data) {
|
SOCKS.prototype.handleResolve = function handleResolve(data) {
|
||||||
var ip, err;
|
var ip, msg;
|
||||||
|
|
||||||
if (data.length !== 10) {
|
if (data.length !== 10) {
|
||||||
this.error('Bad packet size for tor resolve.');
|
this.error('Bad packet size for tor resolve.');
|
||||||
@ -504,13 +507,13 @@ SOCKS.prototype.handleResolve = function handleResolve(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data[1] !== 0x00) {
|
if (data[1] !== 0x00) {
|
||||||
err = this.getError(data[1]);
|
msg = this.getError(data[1]);
|
||||||
this.emit('Tor resolve error: ' + err + ' (' + this.name + ')');
|
this.error('Tor resolve error: %s (%s).', msg, this.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[2] !== 0x00) {
|
if (data[2] !== 0x00) {
|
||||||
this.error('Unknown tor resolve error: ' + data[2]);
|
this.error('Unknown tor resolve error: %d.', data[2]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user