@applitools/eg-socks5-proxy-server
Advanced tools
Comparing version 0.2.2 to 0.2.3
{ | ||
"name": "@applitools/eg-socks5-proxy-server", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -18,2 +18,3 @@ module.exports = { | ||
REMOTE_PROXY_RFC_1928_REPLY_TIMEOUT: 'remote-proxy-rpc-1928-reply-timeout', | ||
REMOTE_PROXY_RFC_1928_REPLY: 'remote-proxy-rpc-1928-reply', | ||
@@ -20,0 +21,0 @@ ORIGIN_SOCKET_ERROR: 'orgin-socket-error', |
@@ -19,3 +19,3 @@ const net = require('net') | ||
let timeoutId | ||
let stopTimeout | ||
@@ -28,19 +28,12 @@ const destination = net.createConnection(port, address, () => { | ||
destination.write(clientHandshakeBuffer, () => { | ||
let wasHandshakeTimeoutCalled = false | ||
timeoutId = setTimeout(() => { | ||
wasHandshakeTimeoutCalled = true | ||
destination.destroy() | ||
proxyServer.onHandshakeTimeout() | ||
}, 10000) | ||
destination.once('data', () => { | ||
clearTimeout(timeoutId) | ||
if (wasHandshakeTimeoutCalled) { | ||
const onHandShakeCompleted = (_data) => { | ||
;[stopTimeout] = _writeAndWaitForResponse({ | ||
socket: destination, | ||
data: args.requestBuffer, | ||
timeout: proxyServer.rpcReplyTimeout || 5000, | ||
onTimeout: () => { | ||
destination.destroy() | ||
return | ||
} | ||
const writeAcknowledgementToClient = (data) => | ||
proxyServer.onRpc1928ReplyTimeout() | ||
}, | ||
onComplete: (data) => { | ||
originalSocket.write(data, () => { | ||
@@ -51,22 +44,18 @@ destination.pipe(originalSocket) | ||
let wasRpcReplyTimeoutCalled = false | ||
proxyServer.onRpc1928Reply(data) | ||
}, | ||
}) | ||
timeoutId = setTimeout(() => { | ||
wasRpcReplyTimeoutCalled = true | ||
destination.destroy() | ||
proxyServer.onRpc1928ReplyTimeout() | ||
}, 5000) | ||
proxyServer.onHandShakeCompleted() | ||
} | ||
// first buffer after handshake | ||
destination.write(args.requestBuffer, () => { | ||
destination.once('data', (data) => { | ||
if (wasRpcReplyTimeoutCalled) return | ||
clearTimeout(timeoutId) | ||
writeAcknowledgementToClient(data) | ||
}) | ||
}) | ||
proxyServer.onHandShakeCompleted && proxyServer.onHandShakeCompleted() | ||
}) | ||
;[stopTimeout] = _writeAndWaitForResponse({ | ||
socket: destination, | ||
data: clientHandshakeBuffer, | ||
timeout: proxyServer.handshakeTimeout || 5000, | ||
onTimeout: () => { | ||
destination.destroy() | ||
proxyServer.onHandshakeTimeout() | ||
}, | ||
onComplete: onHandShakeCompleted, | ||
}) | ||
@@ -84,3 +73,3 @@ }) | ||
destination.on('error', (err) => { | ||
timeoutId && clearTimeout(timeoutId) | ||
stopTimeout && stopTimeout() | ||
@@ -107,1 +96,22 @@ // notify of connection error | ||
} | ||
function _writeAndWaitForResponse({socket, data, timeout, onTimeout, onComplete}) { | ||
let wasTimeoutCalled = false | ||
const timeoutId = setTimeout(() => { | ||
wasTimeoutCalled = true | ||
onTimeout() | ||
}, timeout) | ||
const stopTimeoutFn = () => clearTimeout(timeoutId) | ||
socket.write(data, () => { | ||
socket.once('data', (response) => { | ||
if (wasTimeoutCalled) return | ||
stopTimeoutFn() | ||
onComplete(response) | ||
}) | ||
}) | ||
return [stopTimeoutFn] | ||
} |
@@ -214,3 +214,3 @@ const { | ||
address: proxyServer.address, | ||
port: proxyServer.port | ||
port: proxyServer.port, | ||
}: undefined | ||
@@ -297,2 +297,3 @@ | ||
proxyInfo, | ||
timeout: proxyServer.handshakeTimeout | ||
}) | ||
@@ -310,2 +311,3 @@ | ||
proxyInfo, | ||
timeout: proxyServer.rpcReplyTimeout | ||
}) | ||
@@ -317,2 +319,11 @@ | ||
} | ||
proxyServer.onRpc1928Reply = (reply) => { | ||
self.server.emit(EVENTS.REMOTE_PROXY_RFC_1928_REPLY, { | ||
originInfo, | ||
destinationInfo, | ||
proxyInfo, | ||
reply | ||
}) | ||
} | ||
@@ -319,0 +330,0 @@ destination = executeRequestThroughRemoteProxy({ |
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
25909
686