client: Do not include WebRTC offers with 'stopped' announce event (fix #132)

This commit is contained in:
Feross Aboukhadijeh 2016-03-16 18:04:56 -07:00
parent 2c23ae7f00
commit c181020937

View File

@ -45,22 +45,27 @@ WebSocketTracker.prototype.announce = function (opts) {
return self.socket.once('connect', self.announce.bind(self, opts)) return self.socket.once('connect', self.announce.bind(self, opts))
} }
var params = extend(opts, {
action: 'announce',
info_hash: self.client._infoHashBinary,
peer_id: self.client._peerIdBinary
})
if (self._trackerId) params.trackerid = self._trackerId
if (opts.event === 'stopped') {
// Don't include offers with 'stopped' event
self._send(params)
} else {
// Limit the number of offers that are generated, since it can be slow // Limit the number of offers that are generated, since it can be slow
var numwant = Math.min(opts.numwant, 10) var numwant = Math.min(opts.numwant, 10)
self._generateOffers(numwant, function (offers) { self._generateOffers(numwant, function (offers) {
var params = extend(opts, { params.numwant = numwant
action: 'announce', params.offers = offers
numwant: numwant,
info_hash: self.client._infoHashBinary,
peer_id: self.client._peerIdBinary,
offers: offers
})
if (self._trackerId) params.trackerid = self._trackerId
self._send(params) self._send(params)
}) })
} }
}
WebSocketTracker.prototype.scrape = function (opts) { WebSocketTracker.prototype.scrape = function (opts) {
var self = this var self = this
@ -337,6 +342,7 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) {
for (var i = 0; i < numwant; ++i) { for (var i = 0; i < numwant; ++i) {
generateOffer() generateOffer()
} }
checkDone()
function generateOffer () { function generateOffer () {
var offerId = hat(160) var offerId = hat(160)