Skip to content

Commit 4b01040

Browse files
committed
Standard fix and test update
1 parent dd96c0f commit 4b01040

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

client-socks.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var Client = require('../')
2+
var Buffer = require('safe-buffer').Buffer
3+
4+
var peerId1 = Buffer.from('01234567890123456789')
5+
var port = 6881
6+
7+
var client = new Client({
8+
infoHash: '4d753474429d817b80ff9e0c441ca660ec5d2450',
9+
announce: [
10+
// 'udp://tracker.leechers-paradise.org:6969'
11+
// 'http://mgtracker.org:2710/announce'
12+
'wss://tracker.webtorrent.io'
13+
],
14+
peerId: peerId1,
15+
port: port,
16+
wrtc: {},
17+
proxyOpts: {
18+
socksProxy: {
19+
proxy: {
20+
ipAddress: 'localhost',
21+
port: 1080,
22+
type: 5
23+
}
24+
}
25+
}
26+
})
27+
28+
client.on('error', function (err) {
29+
// fatal client error!
30+
console.log(err.message)
31+
})
32+
33+
client.on('warning', function (err) {
34+
// a tracker was unavailable or sent bad data to the client. you can probably ignore it
35+
console.log(err.message)
36+
})
37+
38+
// scrape
39+
client.scrape()
40+
41+
client.on('scrape', function (data) {
42+
console.log('got a scrape response from tracker: ' + data.announce)
43+
console.log('number of seeders in the swarm: ' + data.complete)
44+
console.log('number of leechers in the swarm: ' + data.incomplete)
45+
console.log('number of total downloads of this torrent: ' + data.downloaded)
46+
47+
// start getting peers from the tracker
48+
client.start()
49+
50+
client.once('update', function (data) {
51+
console.log('got an announce response from tracker: ' + data.announce)
52+
console.log('number of seeders in the swarm: ' + data.complete)
53+
console.log('number of leechers in the swarm: ' + data.incomplete)
54+
55+
client.once('update', function (data) {
56+
client.destroy()
57+
})
58+
})
59+
60+
client.once('peer', function (addr) {
61+
console.log('found a peer: ' + addr) // 85.10.239.191:48623
62+
})
63+
})

lib/client/http-tracker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
9191
var parsedUrl = url.parse(requestUrl + (requestUrl.indexOf('?') === -1 ? '?' : '&') + common.querystringStringify(params))
9292
var agent
9393
if (self.client._proxyOpts) {
94-
agent = parsedUrl.protocol === 'https:' ?
95-
self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
94+
agent = parsedUrl.protocol === 'https:'
95+
? self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
9696
}
9797
var u = {
9898
url: parsedUrl,

lib/client/websocket-tracker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ WebSocketTracker.prototype._openSocket = function () {
169169
socketPool[self.announceUrl].consumers += 1
170170
} else {
171171
var parsedUrl = url.parse(self.announceUrl)
172-
var agent = self.client._proxyOpts && parsedUrl.protocol === 'wss:' ?
173-
self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
172+
var agent
173+
if (self.client._proxyOpts) {
174+
agent = parsedUrl.protocol === 'wss:'
175+
? self.client._proxyOpts.httpsAgent : self.client._proxyOpts.httpAgent
176+
}
174177
self.socket = socketPool[self.announceUrl] = new Socket(self.announceUrl, { agent: agent })
175178
self.socket.consumers = 1
176179
self.socket.on('connect', self._onSocketConnectBound)

test/client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ function testClientStartHttpAgent (t, serverType) {
399399
peerId: peerId1,
400400
port: port,
401401
wrtc: {},
402-
httpAgent: agent
402+
proxyOpts: {
403+
httpAgent: agent
404+
}
403405
})
404406

405407
if (serverType === 'ws') common.mockWebsocketTracker(client)

0 commit comments

Comments
 (0)