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