Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@applitools/eg-socks5-proxy-server

Package Overview
Dependencies
Maintainers
30
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/eg-socks5-proxy-server - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

src/end-socket-connection.js

2

package.json
{
"name": "@applitools/eg-socks5-proxy-server",
"version": "0.2.3",
"version": "0.2.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "src/index.js",

const net = require('net')
const {RFC_1928_REPLIES} = require('./constants')
const {convertSocketErrorToRpcReply} = require('./utils/convert-socket-error-to-rpc-reply')

@@ -27,3 +28,3 @@ module.exports = {executeRequestThroughRemoteProxy}

const onHandShakeCompleted = (_data) => {
const onHandshakeCompleted = (_data) => {
;[stopTimeout] = _writeAndWaitForResponse({

@@ -47,3 +48,3 @@ socket: destination,

proxyServer.onHandShakeCompleted()
proxyServer.onHandshakeCompleted()
}

@@ -59,3 +60,3 @@

},
onComplete: onHandShakeCompleted,
onComplete: onHandshakeCompleted,
})

@@ -82,11 +83,4 @@ })

if (err.code && err.code === 'EADDRNOTAVAIL') {
return end(originalSocket, RFC_1928_REPLIES.HOST_UNREACHABLE, args)
}
if (err.code && err.code === 'ECONNREFUSED') {
return end(originalSocket, RFC_1928_REPLIES.CONNECTION_REFUSED, args)
}
return end(originalSocket, RFC_1928_REPLIES.NETWORK_UNREACHABLE, args)
const rpcReply = convertSocketErrorToRpcReply(err)
return end(rpcReply, args)
})

@@ -93,0 +87,0 @@

const net = require('net')
const {RFC_1928_REPLIES} = require('./constants')
const {convertSocketErrorToRpcReply} = require('./utils/convert-socket-error-to-rpc-reply')

@@ -41,11 +42,4 @@ module.exports = {executeRequest}

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)
const rpcReply = convertSocketErrorToRpcReply(err)
return end(rpcReply, args)
})

@@ -52,0 +46,0 @@

@@ -20,3 +20,3 @@ const binary = require('binary')

* @param {Function} end
* @param {Function} onHandShakeCompleted
* @param {Function} onHandshakeCompleted
*

@@ -23,0 +23,0 @@ * @returns {undefined}

@@ -12,2 +12,3 @@ const {

const EVENTS = require('./events')
const {endConnection} = require('./end-socket-connection')
const {handshake} = require('./handshake')

@@ -205,37 +206,73 @@ const {authenticate} = require('./authenticate')

? {
...self.options.proxyServer,
shouldUseProxy: self.options.proxyServer.shouldUseProxy || _alwaysTrue
}
...self.options.proxyServer,
shouldUseProxy: self.options.proxyServer.shouldUseProxy || _alwaysTrue,
}
: undefined
const shouldUseProxy = proxyServer && proxyServer.shouldUseProxy({socket, destinationInfo, originInfo})
const proxyInfo = shouldUseProxy? {
address: proxyServer.address,
port: proxyServer.port,
}: undefined
const shouldUseProxy =
proxyServer && proxyServer.shouldUseProxy({socket, destinationInfo, originInfo})
self.server.emit(EVENTS.ACCEPT_NEW_REQUEST, {
const proxyInfo = shouldUseProxy
? {
address: proxyServer.address,
port: proxyServer.port,
}
: undefined
const basicEventData = {
originInfo,
destinationInfo,
proxyInfo,
})
}
const retries = {handshake: 0, rpcReply: 0}
self.server.emit(EVENTS.ACCEPT_NEW_REQUEST, basicEventData)
if (shouldUseProxy) {
const retries = {handshake: 0, rpcReply: 0}
proxyServer.onHandshakeCompleted = () => {
self.server.emit(EVENTS.REMOTE_PROXY_HANDSHAKE_COMPLETED, basicEventData)
}
proxyServer.onHandshakeTimeout = () => {
self.server.emit(EVENTS.REMOTE_PROXY_HANDSHAKE_TIMEOUT, {
...basicEventData,
timeout: proxyServer.handshakeTimeout,
})
retries.handshake++
if (retries.handshake <= 3) createExecuterAndRegisterToEvents()
else end(RFC_1928_REPLIES.NETWORK_UNREACHABLE, args)
}
proxyServer.onRpc1928ReplyTimeout = () => {
self.server.emit(EVENTS.REMOTE_PROXY_RFC_1928_REPLY_TIMEOUT, {
...basicEventData,
timeout: proxyServer.rpcReplyTimeout,
})
retries.rpcReply++
if (retries.rpcReply <= 3) createExecuterAndRegisterToEvents()
else end(RFC_1928_REPLIES.NETWORK_UNREACHABLE, args)
}
proxyServer.onRpc1928Reply = (reply) => {
self.server.emit(EVENTS.REMOTE_PROXY_RFC_1928_REPLY, {
...basicEventData,
reply,
})
}
}
createExecuterAndRegisterToEvents = () => {
let connectionTimeout = setTimeout(
const connectionTimeout = 120000
let connectionTimeoutId = setTimeout(
() =>
self.server.emit(EVENTS.REMOTE_CONNECTION_TIMEOUT_ERROR, {
originInfo,
destinationInfo,
proxyInfo,
}),
120000,
self.server.emit(EVENTS.REMOTE_CONNECTION_TIMEOUT_ERROR, {...basicEventData, timeout: connectionTimeout}),
connectionTimeout,
)
const clearConnectionTimeout = () => {
connectionTimeout && clearTimeout(connectionTimeout)
connectionTimeout = null
connectionTimeoutId && clearTimeout(connectionTimeoutId)
connectionTimeoutId = null
}

@@ -250,6 +287,8 @@

destinationSocket.destroy()
self.destinationSockets.splice(self.destinationSockets.indexOf(destinationSocket), 1)
self.destinationSockets.splice(
self.destinationSockets.indexOf(destinationSocket),
1,
)
})
const event = shouldUseProxy

@@ -286,45 +325,2 @@ ? EVENTS.CONNECTED_TO_REMOTE_PROXY

} else {
proxyServer.onHandShakeCompleted = () => {
self.server.emit(EVENTS.REMOTE_PROXY_HANDSHAKE_COMPLETED, {
originInfo,
destinationInfo,
proxyInfo,
})
}
proxyServer.onHandshakeTimeout = () => {
self.server.emit(EVENTS.REMOTE_PROXY_HANDSHAKE_TIMEOUT, {
originInfo,
destinationInfo,
proxyInfo,
timeout: proxyServer.handshakeTimeout
})
retries.handshake++
if (retries.handshake <= 3) createExecuterAndRegisterToEvents()
else end(RFC_1928_REPLIES.NETWORK_UNREACHABLE, args)
}
proxyServer.onRpc1928ReplyTimeout = () => {
self.server.emit(EVENTS.REMOTE_PROXY_RFC_1928_REPLY_TIMEOUT, {
originInfo,
destinationInfo,
proxyInfo,
timeout: proxyServer.rpcReplyTimeout
})
retries.rpcReply++
if (retries.rpcReply <= 3) createExecuterAndRegisterToEvents()
else end(RFC_1928_REPLIES.NETWORK_UNREACHABLE, args)
}
proxyServer.onRpc1928Reply = (reply) => {
self.server.emit(EVENTS.REMOTE_PROXY_RFC_1928_REPLY, {
originInfo,
destinationInfo,
proxyInfo,
reply
})
}
destination = executeRequestThroughRemoteProxy({

@@ -362,18 +358,3 @@ originalSocket: socket,

function end(response, args) {
// either use the raw buffer (if available) or create a new one
let responseBuffer = args.requestBuffer || Buffer.allocUnsafe(2)
if (!args.requestBuffer) {
responseBuffer[0] = RFC_1928_VERSION
}
responseBuffer[1] = response
// respond then end the connection
try {
socket.end(responseBuffer)
} catch (ex) {
socket.destroy()
}
endConnection({socket, response, args})
// indicate end of connection

@@ -426,3 +407,3 @@ self.server.emit(EVENTS.PROXY_END, response, args)

getConnections = (...args) => this.server.getConnections(...args)
setProxyServer = (proxyServer) => {

@@ -429,0 +410,0 @@ this.options.proxyServer = proxyServer

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc