Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server: function (onConnection, cb) {
if(!opts.server) return
var serverOpts = {
proxy: proxyOpts,
command: "bind",
destination: {
host: opts.host,
port: opts.port
}
}
var controlSocket = null
socks.createConnection(serverOpts, function (err, socket) {
if(err) {
console.error('unable to find local tor server.')
console.error('will be able receive tor connections') // << ???
return
}
controlSocket = socket
socket.on('data', function(stream) {
stream = toPull.duplex(stream)
stream.address = 'onion:'
onConnection(stream)
})
cb(null, true);
if (!host) {
throw new Error('No `host` defined!');
}
if (lookup) {
// Client-side DNS resolution for "4" and "5" socks proxy versions.
host = await dnsLookup(host);
}
const socksOpts: SocksClientOptions = {
proxy,
destination: { host, port },
command: 'connect'
};
debug('Creating socks proxy connection: %o', socksOpts);
const { socket } = await SocksClient.createConnection(socksOpts);
debug('Successfully created socks proxy connection');
if (opts.secureEndpoint) {
const servername = opts.servername || opts.host;
if (!servername) {
throw new Error('Could not determine "servername"');
}
// The proxy is connecting to a TLS server, so upgrade
// this socket connection to a TLS connection.
debug('Upgrading socket connection to TLS');
return tls.connect({
...omit(opts, 'host', 'hostname', 'path', 'port'),
socket,
servername
});
}
timeout: readyTimeout
}
request(opts)
.on('error', (e) => {
console.error(`fail to connect proxy: ${e.message}`)
reject(e)
})
.on('connect', (res, socket) => {
resolve({ socket: socket })
})
.end()
})
}
// use socks proxy
return SocksClient.createConnection(options)
}
client: function (opts, cb) {
var started = false, _socket, destroy
var connectOpts = {
proxy: proxyOpts,
command: "connect",
destination: {
host: opts.host,
port: opts.port
}
}
socks.createConnection(connectOpts, function(err, result) {
if (err) return cb(err)
var socket = result.socket
if(destroy) return socket.destroy()
_socket = socket
var duplexStream = toPull.duplex(socket)
duplexStream.address = 'onion:'+connectOpts.destination.host+':'+connectOpts.destination.port
cb(null, duplexStream)
// Remember to resume the socket stream.
socket.resume()
})
return function () {
}
if (this.frameUpdateTimer) {
clearInterval(this.frameUpdateTimer);
this.frameUpdateTimer = null;
}
if (this.projectiles.length > 0) {
this.projectiles = [];
}
if (this.projectileUpdateTimer) {
clearInterval(this.projectileUpdateTimer);
this.projectileUpdateTimer = null;
}
if (this.proxy) {
Logger.log(this.alias, 'Establishing proxy', LogLevel.Info);
SocksClient.createConnection({
proxy: {
ipaddress: this.proxy.host,
port: this.proxy.port,
type: this.proxy.type,
userId: this.proxy.userId,
password: this.proxy.password
},
command: 'connect',
destination: {
host: this.internalServer.address,
port: 2050
}
}).then((info) => {
Logger.log(this.alias, 'Established proxy!', LogLevel.Success);
this.clientSocket = info.socket;
this.initSocket(false);