diff --git a/index.js b/index.js index 36da98c..feae75d 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ exports.Client = Client exports.Server = Server +var bignum = require('bignum') var bncode = require('bncode') var compact2string = require('compact2string') var dgram = require('dgram') @@ -225,9 +226,9 @@ Client.prototype._requestUdp = function (announceUrl, opts) { transactionId, self._infoHash, self._peerId, - toUInt32(0), toUInt32(opts.downloaded || 0), // 64bit - toUInt32(0), toUInt32(opts.left || 0), // 64bit - toUInt32(0), toUInt32(opts.uploaded || 0), // 64bit + toUInt64(opts.downloaded || 0), + toUInt64(opts.left || 0), + toUInt64(opts.uploaded || 0), toUInt32(EVENTS[opts.event] || 0), toUInt32(0), // ip address (optional) toUInt32(0), // key (optional) @@ -520,6 +521,10 @@ function toUInt32 (n) { return buf } +function toUInt64 (n) { + return bignum(n).toBuffer({ size: 8 }) +} + function bytewiseEncodeURIComponent (buf) { return encodeURIComponent(buf.toString('binary')) } diff --git a/package.json b/package.json index e2c9c86..ccaee16 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "url": "https://github.com/feross/bittorrent-tracker/issues" }, "dependencies": { + "bignum": "^0.6.2", "bncode": "^0.5.2", "compact2string": "^1.2.0", "extend.js": "0.0.1", diff --git a/test/client-large-torrent.js b/test/client-large-torrent.js index 1bf1e05..62c5f03 100644 --- a/test/client-large-torrent.js +++ b/test/client-large-torrent.js @@ -8,6 +8,9 @@ var parsedTorrent = parseTorrent(torrent) var peerId = new Buffer('01234567890123456789') var port = 6881 +// remove all tracker servers except a single UDP one, for now +parsedTorrent.announce = [ 'udp://tracker.publicbt.com:80/announce' ] + test('client.start()', function (t) { t.plan(4) @@ -18,7 +21,7 @@ test('client.start()', function (t) { }) client.once('update', function (data) { - t.equal(data.announce, 'http://t.bitlove.org/announce') + t.equal(data.announce, 'udp://tracker.publicbt.com:80/announce') t.equal(typeof data.complete, 'number') t.equal(typeof data.incomplete, 'number') }) diff --git a/test/server.js b/test/server.js index 48f7579..b207b92 100644 --- a/test/server.js +++ b/test/server.js @@ -3,6 +3,9 @@ var portfinder = require('portfinder') var Server = require('../').Server var test = require('tape') +// TODO: add tests to verify that the correct downloaded/left/uploaded numbers are +// being sent + var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705' var peerId = '12345678901234567890' var torrentLength = 50000