starts filling the buffer before a tor instance is live

This commit is contained in:
Zachary Boyd 2017-03-25 21:14:46 -04:00
parent a8841a2f40
commit 1cc2a57394
3 changed files with 30 additions and 31 deletions

View file

@ -1,6 +1,6 @@
{
"name": "tor-router",
"version": "3.0.1",
"version": "3.0.2",
"main": "src/index.js",
"repository": "git@github.com:znetstar/tor-router.git",
"author": "Zachary Boyd <zachary@zacharyboyd.nyc>",

View file

@ -8,8 +8,8 @@ class DNSServer extends UDPServer {
this.tor_pool = tor_pool;
this.on('request', (req, res) => {
for (let question of req.question) {
let connect = (tor_instance) => {
let connect = (tor_instance) => {
for (let question of req.question) {
let dns_port = (tor_instance.dns_port);
let outbound_req = dns.Request({
question,
@ -37,14 +37,13 @@ class DNSServer extends UDPServer {
outbound_req.send();
};
if (this.tor_pool.instances.length) {
connect(this.tor_pool.next());
}
else {
this.log.debug(`[dns]: a connection has been attempted, but no tor instances are live... waiting for an instance to come online`);
this.tor_pool.once('instance_created', connect);
}
};
if (this.tor_pool.instances.length) {
connect(this.tor_pool.next());
}
else {
this.log.debug(`[dns]: a connection has been attempted, but no tor instances are live... waiting for an instance to come online`);
this.tor_pool.once('instance_created', connect);
}
});
}

View file

@ -12,32 +12,32 @@ class SOCKSServer extends SOCKS5Server{
var outbound_socket;
let buffer = [];
let onInboundData = (data) => buffer.push(data)
let onClose = (error) => {
inbound_socket && inbound_socket.end();
outbound_socket && outbound_socket.end();
inbound_socket = outbound_socket = buffer = void(0);
if (error)
this.logger.error(`[socks]: an error occured: ${error.message}`)
d.exit();
};
if (!inbound_socket) return;
inbound_socket.on('close', onClose);
inbound_socket.on('data', onInboundData);
inbound_socket.on('error', onClose);
let connect = (tor_instance) => {
let socks_port = tor_instance.socks_port;
logger && logger.info(`[socks]: ${info.srcAddr}:${info.srcPort} → 127.0.0.1:${socks_port}${info.dstAddr}:${info.dstPort}`)
let onClose = (error) => {
inbound_socket && inbound_socket.end();
outbound_socket && outbound_socket.end();
inbound_socket = outbound_socket = buffer = void(0);
if (error)
this.logger.error(`[socks]: an error occured: ${error.message}`)
d.exit();
};
d.on('error', onClose);
let onInboundData = (data) => buffer.push(data)
if (!inbound_socket) return;
inbound_socket.on('close', onClose);
inbound_socket.on('data', onInboundData);
inbound_socket.on('error', onClose);
d.run(() => {
socks.connect({
host: info.dstAddr,