@applitools/eg-socks5-proxy-server
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "@applitools/eg-socks5-proxy-server", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -26,8 +26,21 @@ const net = require('net') | ||
destination.write(clientHandshakeBuffer, () => { | ||
let isTimeoutCalled = false | ||
const handshakeTimeout = setTimeout(()=> { | ||
proxyServer.onHandshakeTimeout() | ||
isTimeoutCalled = true | ||
}, 10000) | ||
destination.once('data', () => { | ||
destination.write(args.requestBuffer, () => { | ||
destination.pipe(originalSocket) | ||
originalSocket.pipe(destination) | ||
}) | ||
proxyServer.onHandShakeCompleted && proxyServer.onHandShakeCompleted() | ||
clearTimeout(handshakeTimeout) | ||
if (!isTimeoutCalled){ | ||
destination.write(args.requestBuffer, () => { | ||
destination.pipe(originalSocket) | ||
originalSocket.pipe(destination) | ||
}) | ||
proxyServer.onHandShakeCompleted && proxyServer.onHandShakeCompleted() | ||
} | ||
else{ | ||
destination.destroy() | ||
} | ||
}) | ||
@@ -34,0 +47,0 @@ }) |
143
src/index.js
@@ -33,3 +33,5 @@ const { | ||
REMOTE_PROXY_HANDSHAKE_COMPLETED: 'remote-proxy-handshake-completed', | ||
REMOTE_PROXY_HANDSHAKE_TIMEOUT: 'remote-proxy-handshake-timeout', | ||
ORIGIN_SOCKET_ERROR: 'orgin-socket-error', | ||
@@ -264,2 +266,4 @@ REMOTE_SOCKET_ERROR: 'remote-socket-error', | ||
let createExecuterAndRegisterToEvents | ||
if (proxyServer){ | ||
@@ -269,2 +273,7 @@ proxyServer.onHandShakeCompleted = () => { | ||
} | ||
proxyServer.onHandshakeTimeout = () => { | ||
self.server.emit(EVENTS.REMOTE_PROXY_HANDSHAKE_TIMEOUT, {originInfo, destinationInfo, proxyServer}) | ||
createExecuterAndRegisterToEvents() | ||
} | ||
} | ||
@@ -277,72 +286,76 @@ | ||
}) | ||
let connectionTimeout = setTimeout( | ||
() => | ||
self.server.emit(EVENTS.REMOTE_CONNECTION_TIMEOUT_ERROR, { | ||
createExecuterAndRegisterToEvents = () => { | ||
let connectionTimeout = setTimeout( | ||
() => | ||
self.server.emit(EVENTS.REMOTE_CONNECTION_TIMEOUT_ERROR, { | ||
originInfo, | ||
destinationInfo, | ||
proxyServer, | ||
}), | ||
120000, | ||
) | ||
const clearConnectionTimeout = () => { | ||
connectionTimeout && clearTimeout(connectionTimeout) | ||
connectionTimeout = null | ||
} | ||
let destination = createRequestExecuter({ | ||
originalSocket: socket, | ||
clientHandshakeBuffer, | ||
proxyServer, | ||
args, | ||
}) | ||
self.destinationSockets.push(socket) | ||
destination.on('connect', () => { | ||
connectionFilterDomain.exit() | ||
clearConnectionTimeout() | ||
// close destination socket when after original socket was closed | ||
socket.on('close', () => { | ||
destination.destroy() | ||
self.destinationSockets.splice(self.destinationSockets.indexOf(socket), 1) | ||
}) | ||
const event = proxyServer | ||
? EVENTS.CONNECTED_TO_REMOTE_PROXY | ||
: EVENTS.CONNECTED_TO_REMOTE_ADDRESS | ||
self.server.emit(event, {destinationInfo, originInfo, proxyServer}) | ||
}) | ||
destination.on('error', (err) => { | ||
// exit the connection filter domain | ||
connectionFilterDomain.exit() | ||
clearConnectionTimeout() | ||
// notify of connection error | ||
err.addr = args.dst.addr | ||
err.atyp = args.atyp | ||
err.port = args.dst.port | ||
self.server.emit(EVENTS.REMOTE_SOCKET_ERROR, { | ||
err, | ||
destination, | ||
args, | ||
originInfo, | ||
destinationInfo, | ||
proxyServer, | ||
}), | ||
120000, | ||
) | ||
const clearConnectionTimeout = () => { | ||
connectionTimeout && clearTimeout(connectionTimeout) | ||
connectionTimeout = null | ||
}) | ||
if (err.code && err.code === 'EADDRNOTAVAIL') { | ||
return end(RFC_1928_REPLIES.HOST_UNREACHABLE, args) | ||
} | ||
if (err.code && err.code === 'ECONNREFUSED') { | ||
return end(RFC_1928_REPLIES.CONNECTION_REFUSED, args) | ||
} | ||
return end(RFC_1928_REPLIES.NETWORK_UNREACHABLE, args) | ||
}) | ||
} | ||
let destination = createRequestExecuter({ | ||
originalSocket: socket, | ||
clientHandshakeBuffer, | ||
proxyServer, | ||
args, | ||
}) | ||
self.destinationSockets.push(socket) | ||
destination.on('connect', () => { | ||
connectionFilterDomain.exit() | ||
clearConnectionTimeout() | ||
// close destination socket when after original socket was closed | ||
socket.on('close', () => { | ||
destination.destroy() | ||
self.destinationSockets.splice(self.destinationSockets.indexOf(socket), 1) | ||
}) | ||
const event = proxyServer | ||
? EVENTS.CONNECTED_TO_REMOTE_PROXY | ||
: EVENTS.CONNECTED_TO_REMOTE_ADDRESS | ||
self.server.emit(event, {destinationInfo, originInfo, proxyServer}) | ||
}) | ||
destination.on('error', (err) => { | ||
// exit the connection filter domain | ||
connectionFilterDomain.exit() | ||
clearConnectionTimeout() | ||
// notify of connection error | ||
err.addr = args.dst.addr | ||
err.atyp = args.atyp | ||
err.port = args.dst.port | ||
self.server.emit(EVENTS.REMOTE_SOCKET_ERROR, { | ||
err, | ||
destination, | ||
args, | ||
originInfo, | ||
destinationInfo, | ||
proxyServer, | ||
}) | ||
if (err.code && err.code === 'EADDRNOTAVAIL') { | ||
return end(RFC_1928_REPLIES.HOST_UNREACHABLE, args) | ||
} | ||
if (err.code && err.code === 'ECONNREFUSED') { | ||
return end(RFC_1928_REPLIES.CONNECTION_REFUSED, args) | ||
} | ||
return end(RFC_1928_REPLIES.NETWORK_UNREACHABLE, args) | ||
}) | ||
createExecuterAndRegisterToEvents() | ||
}), | ||
@@ -349,0 +362,0 @@ ) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22170
554