Skip to content

Commit 8ea50ea

Browse files
committed
Use clone to deepcopy socks opts
1 parent 8747f7e commit 8ea50ea

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

lib/client/http-tracker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = HTTPTracker
22

33
var bencode = require('bencode')
44
var compact2string = require('compact2string')
5+
var clone = require('clone')
56
var debug = require('debug')('bittorrent-tracker:http-tracker')
67
var extend = require('xtend')
78
var get = require('simple-get')
@@ -95,7 +96,7 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
9596
agent = parsedUrl.protocol === 'https:'
9697
? self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
9798
if (!agent && self.client._proxyOpts.socksProxy) {
98-
agent = new Socks.Agent(extend(self.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'https:'))
99+
agent = new Socks.Agent(clone(self.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'https:'))
99100
}
100101
}
101102
var u = {

lib/client/udp-tracker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module.exports = UDPTracker
22

33
var BN = require('bn.js')
44
var Buffer = require('safe-buffer').Buffer
5+
var clone = require('clone')
56
var compact2string = require('compact2string')
67
var debug = require('debug')('bittorrent-tracker:udp-tracker')
78
var dgram = require('dgram')
8-
var extend = require('xtend')
99
var inherits = require('inherits')
1010
var randombytes = require('randombytes')
1111
var Socks = require('socks')
@@ -77,7 +77,7 @@ UDPTracker.prototype._request = function (opts) {
7777
var relay
7878
var transactionId = genTransactionId()
7979

80-
var proxyOpts = self.client._proxyOpts && extend(self.client._proxyOpts.socksProxy)
80+
var proxyOpts = self.client._proxyOpts && clone(self.client._proxyOpts.socksProxy)
8181
if (proxyOpts) {
8282
if (!proxyOpts.proxy) {
8383
proxyOpts.proxy = {}

lib/client/websocket-tracker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = WebSocketTracker
22

3+
var clone = require('clone')
34
var debug = require('debug')('bittorrent-tracker:websocket-tracker')
45
var extend = require('xtend')
56
var inherits = require('inherits')
@@ -175,7 +176,7 @@ WebSocketTracker.prototype._openSocket = function () {
175176
agent = parsedUrl.protocol === 'wss:'
176177
? self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
177178
if (!agent && self.client._proxyOpts.socksProxy) {
178-
agent = new Socks.Agent(extend(self.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'wss:'))
179+
agent = new Socks.Agent(clone(self.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'wss:'))
179180
}
180181
}
181182
self.socket = socketPool[self.announceUrl] = new Socket(self.announceUrl, { agent: agent })

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"bencode": "^0.10.0",
2525
"bittorrent-peerid": "^1.0.2",
2626
"bn.js": "^4.4.0",
27+
"clone": "^1.0.2",
2728
"compact2string": "^1.2.0",
2829
"debug": "^2.0.0",
2930
"inherits": "^2.0.1",

0 commit comments

Comments
 (0)