mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
handle case where parsedTorrent.length is undefined
- Expose `torrentLength` so the user can set it when they know the torrent length. (With a magnet uri, they won’t know the length at the time the Client is instantiated) - UDP Client: Send FFFFFFFFFFFFFFFF for ‘left’ param when we don’t know the size. (This is what Transmission does) Fixes #15.
This commit is contained in:
parent
2983811a71
commit
cc80088038
11
index.js
11
index.js
@ -71,7 +71,7 @@ Tracker.prototype.complete = function (opts) {
|
||||
var self = this
|
||||
opts = opts || {}
|
||||
opts.event = 'completed'
|
||||
opts.downloaded = self._torrentLength
|
||||
opts.downloaded = opts.downloaded || self.torrentLength || 0
|
||||
self._request(opts)
|
||||
}
|
||||
|
||||
@ -126,13 +126,16 @@ Tracker.prototype._request = function (opts) {
|
||||
info_hash: bytewiseEncodeURIComponent(self.client._infoHash),
|
||||
peer_id: bytewiseEncodeURIComponent(self.client._peerId),
|
||||
port: self.client._port,
|
||||
left: self.client._torrentLength - (opts.downloaded || 0),
|
||||
compact: 1,
|
||||
numwant: self.client._numWant,
|
||||
uploaded: 0, // default, user should provide real value
|
||||
downloaded: 0 // default, user should provide real value
|
||||
}, opts)
|
||||
|
||||
if (self.client.torrentLength !== undefined) {
|
||||
opts.left = self.client.torrentLength - (opts.downloaded || 0)
|
||||
}
|
||||
|
||||
if (self._trackerId) {
|
||||
opts.trackerid = self._trackerId
|
||||
}
|
||||
@ -269,7 +272,7 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
|
||||
self.client._infoHash,
|
||||
self.client._peerId,
|
||||
toUInt64(opts.downloaded || 0),
|
||||
toUInt64(opts.left || 0),
|
||||
opts.left ? toUInt64(opts.left) : new Buffer('FFFFFFFFFFFFFFFF', 'hex'),
|
||||
toUInt64(opts.uploaded || 0),
|
||||
toUInt32(EVENTS[opts.event] || 0),
|
||||
toUInt32(0), // ip address (optional)
|
||||
@ -392,7 +395,7 @@ function Client (peerId, port, torrent, opts) {
|
||||
self._infoHash = Buffer.isBuffer(torrent.infoHash)
|
||||
? torrent.infoHash
|
||||
: new Buffer(torrent.infoHash, 'hex')
|
||||
self._torrentLength = torrent.length
|
||||
self.torrentLength = torrent.length
|
||||
self._announce = torrent.announce
|
||||
|
||||
// optional
|
||||
|
Loading…
Reference in New Issue
Block a user