Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Client (peerId, port, torrent, opts) {

self._rtcConfig = opts.rtcConfig
self._wrtc = opts.wrtc
self._getAnnounceOpts = opts.getAnnounceOpts

debug('new client %s', self.infoHash)

Expand Down Expand Up @@ -268,5 +269,10 @@ Client.prototype._defaultAnnounceOpts = function (opts) {
if (opts.left == null && self.torrentLength != null) {
opts.left = self.torrentLength - opts.downloaded
}

if (opts.getAnnounceOpts == null) {
opts.getAnnounceOpts = self._getAnnounceOpts
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary. All tracker types already have a reference to the Client instance. So they should check for self.client._getAnnounceOpts directly.


return opts
}
13 changes: 12 additions & 1 deletion lib/client/http-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,26 @@ HTTPTracker.prototype.announce = function (opts) {
var self = this
if (self.destroyed) return

// Refresh opts if the callback is provided
var cbopts
if (opts.getAnnounceOpts) {
cbopts = opts.getAnnounceOpts()
if (cbopts.uploaded) opts.uploaded = cbopts.uploaded
if (cbopts.downloaded) opts.downloaded = cbopts.downloaded
if (cbopts.left) opts.left = cbopts.left
}

var params = {
numwant: opts.numwant,
uploaded: opts.uploaded,
downloaded: opts.downloaded,
left: opts.left,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Didn't realize that we weren't sending this.

event: opts.event,
compact: (opts.compact == null) ? 1 : opts.compact,
info_hash: self.client._infoHashBinary,
peer_id: self.client._peerIdBinary,
port: self.client._port
port: self.client._port,
extras: cbopts && cbopts.extraAnnounceOpts
}
if (self._trackerId) params.trackerid = self._trackerId

Expand Down
9 changes: 9 additions & 0 deletions lib/client/udp-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ UDPTracker.prototype._request = function (opts) {
function announce (connectionId, opts) {
transactionId = genTransactionId()

// Refresh opts if the callback is provided
var cbopts
if (opts.getAnnounceOpts) {
cbopts = opts.getAnnounceOpts()
if (cbopts.uploaded) opts.uploaded = cbopts.uploaded
if (cbopts.downloaded) opts.downloaded = cbopts.downloaded
if (cbopts.left) opts.left = cbopts.left
}

send(Buffer.concat([
connectionId,
common.toUInt32(common.ACTIONS.ANNOUNCE),
Expand Down
13 changes: 12 additions & 1 deletion lib/client/websocket-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,26 @@ WebSocketTracker.prototype.announce = function (opts) {
// Limit the number of offers that are generated, since it can be slow
var numwant = Math.min(opts.numwant, 10)

// Refresh opts if the callback is provided
var cbopts
if (opts.getAnnounceOpts) {
cbopts = opts.getAnnounceOpts()
if (cbopts.uploaded) opts.uploaded = cbopts.uploaded
if (cbopts.downloaded) opts.downloaded = cbopts.downloaded
if (cbopts.left) opts.left = cbopts.left
}

self._generateOffers(numwant, function (offers) {
var params = {
numwant: numwant,
uploaded: opts.uploaded || 0,
downloaded: opts.downloaded,
left: opts.left,
event: opts.event,
info_hash: self.client._infoHashBinary,
peer_id: self.client._peerIdBinary,
offers: offers
offers: offers,
extras: cbopts && cbopts.extraAnnounceOpts
}
if (self._trackerId) params.trackerid = self._trackerId

Expand Down