Skip to content

Commit 8747f7e

Browse files
committed
Generate socks http agents on the fly (reuse is not working)
1 parent c1e9640 commit 8747f7e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/client/http-tracker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var debug = require('debug')('bittorrent-tracker:http-tracker')
66
var extend = require('xtend')
77
var get = require('simple-get')
88
var inherits = require('inherits')
9+
var Socks = require('socks')
910
var url = require('url')
1011

1112
var common = require('../common')
@@ -93,6 +94,9 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
9394
if (self.client._proxyOpts) {
9495
agent = parsedUrl.protocol === 'https:'
9596
? self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
97+
if (!agent && self.client._proxyOpts.socksProxy) {
98+
agent = new Socks.Agent(extend(self.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'https:'))
99+
}
96100
}
97101
var u = {
98102
url: parsedUrl,

lib/client/udp-tracker.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ UDPTracker.prototype._request = function (opts) {
7979

8080
var proxyOpts = self.client._proxyOpts && extend(self.client._proxyOpts.socksProxy)
8181
if (proxyOpts) {
82-
proxyOpts.proxy = extend(proxyOpts.proxy)
8382
if (!proxyOpts.proxy) {
8483
proxyOpts.proxy = {}
8584
}

lib/client/websocket-tracker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var inherits = require('inherits')
66
var Peer = require('simple-peer')
77
var randombytes = require('randombytes')
88
var Socket = require('simple-websocket')
9+
var Socks = require('socks')
910
var url = require('url')
1011

1112
var common = require('../common')
@@ -173,6 +174,9 @@ WebSocketTracker.prototype._openSocket = function () {
173174
if (self.client._proxyOpts) {
174175
agent = parsedUrl.protocol === 'wss:'
175176
? self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
177+
if (!agent && self.client._proxyOpts.socksProxy) {
178+
agent = new Socks.Agent(extend(self.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'wss:'))
179+
}
176180
}
177181
self.socket = socketPool[self.announceUrl] = new Socket(self.announceUrl, { agent: agent })
178182
self.socket.consumers = 1

0 commit comments

Comments
 (0)