Skip to content

Commit 7f738ae

Browse files
committed
Add documentation for proxy
1 parent 35d3d2a commit 7f738ae

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ var optionalOpts = {
7272
left: 0,
7373
customParam: 'blah' // custom parameters supported
7474
}
75+
},
76+
// NodeJS HTTP agent implementation (used to proxy HTTP and Websocket requests in node)
77+
httpAgent: {},
78+
// Socks proxy options (used to proxy UDP requests in node)
79+
socksProxyOpts: {
80+
// Configuration from socks module (https://github.com/JoshGlazebrook/socks)
81+
proxy: {
82+
// IP Address of Proxy (Required)
83+
ipaddress: "1.2.3.4",
84+
// TCP Port of Proxy (Required)
85+
port: 1080,
86+
// Proxy Type 5 (Required)
87+
// Type 4 does not support UDP association relay
88+
type: 5,
89+
90+
// Authentication used for SOCKS 5 (when it's required) (Optional)
91+
authentication: {
92+
username: "Josh",
93+
password: "somepassword"
94+
}
95+
}
7596
}
7697
}
7798

lib/client/udp-tracker.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ UDPTracker.prototype._request = function (opts) {
6868
parsedUrl.port = 80
6969
}
7070
var timeout
71+
// Socket used to connect to the socks server to create a relay, null if socks is disabled
7172
var proxySocket
73+
// Socket used to connect to the tracker or to the socks relay if socks is enabled
7274
var socket
75+
// Contains the host/port of the socks relay
7376
var relay
7477
var transactionId = genTransactionId()
7578
if (self.client._socksProxyOpts) {
@@ -218,10 +221,10 @@ UDPTracker.prototype._request = function (opts) {
218221
self.client.emit('warning', err)
219222
}
220223

221-
function send (message, info) {
222-
if (info) {
224+
function send (message, proxyInfo) {
225+
if (proxyInfo) {
223226
var pack = Socks.createUDPFrame({ host: parsedUrl.hostname, port: parsedUrl.port }, message)
224-
socket.send(pack, 0, pack.length, info.port, info.host)
227+
socket.send(pack, 0, pack.length, proxyInfo.port, proxyInfo.host)
225228
} else {
226229
socket.send(message, 0, message.length, parsedUrl.port, parsedUrl.hostname)
227230
}

0 commit comments

Comments
 (0)