Skip to content

Commit dfd5149

Browse files
committed
fix webtorrent#11 - support torrents with 64-bit file sizes
1 parent a924e62 commit dfd5149

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
exports.Client = Client
22
exports.Server = Server
33

4+
var bignum = require('bignum')
45
var bncode = require('bncode')
56
var compact2string = require('compact2string')
67
var dgram = require('dgram')
@@ -225,9 +226,9 @@ Client.prototype._requestUdp = function (announceUrl, opts) {
225226
transactionId,
226227
self._infoHash,
227228
self._peerId,
228-
toUInt32(0), toUInt32(opts.downloaded || 0), // 64bit
229-
toUInt32(0), toUInt32(opts.left || 0), // 64bit
230-
toUInt32(0), toUInt32(opts.uploaded || 0), // 64bit
229+
toUInt64(opts.downloaded || 0),
230+
toUInt64(opts.left || 0),
231+
toUInt64(opts.uploaded || 0),
231232
toUInt32(EVENTS[opts.event] || 0),
232233
toUInt32(0), // ip address (optional)
233234
toUInt32(0), // key (optional)
@@ -520,6 +521,10 @@ function toUInt32 (n) {
520521
return buf
521522
}
522523

524+
function toUInt64 (n) {
525+
return bignum(n).toBuffer({ size: 8 })
526+
}
527+
523528
function bytewiseEncodeURIComponent (buf) {
524529
return encodeURIComponent(buf.toString('binary'))
525530
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"url": "https://github.com/feross/bittorrent-tracker/issues"
1212
},
1313
"dependencies": {
14+
"bignum": "^0.6.2",
1415
"bncode": "^0.5.2",
1516
"compact2string": "^1.2.0",
1617
"extend.js": "0.0.1",

test/client-large-torrent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ var parsedTorrent = parseTorrent(torrent)
88
var peerId = new Buffer('01234567890123456789')
99
var port = 6881
1010

11+
// remove all tracker servers except a single UDP one, for now
12+
parsedTorrent.announce = [ 'udp://tracker.publicbt.com:80/announce' ]
13+
1114
test('client.start()', function (t) {
1215
t.plan(4)
1316

@@ -18,7 +21,7 @@ test('client.start()', function (t) {
1821
})
1922

2023
client.once('update', function (data) {
21-
t.equal(data.announce, 'http://t.bitlove.org/announce')
24+
t.equal(data.announce, 'udp://tracker.publicbt.com:80/announce')
2225
t.equal(typeof data.complete, 'number')
2326
t.equal(typeof data.incomplete, 'number')
2427
})

test/server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ var portfinder = require('portfinder')
33
var Server = require('../').Server
44
var test = require('tape')
55

6+
// TODO: add tests to verify that the correct downloaded/left/uploaded numbers are
7+
// being sent
8+
69
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
710
var peerId = '12345678901234567890'
811
var torrentLength = 50000

0 commit comments

Comments
 (0)