Skip to content

Commit 1338282

Browse files
committed
prevent negative complete/incomplete numbers
Fixes webtorrent#65 Fixes webtorrent#72
1 parent 71c5cf5 commit 1338282

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/swarm.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Swarm.prototype.announce = function (params, cb) {
1919
if (self[fn]) {
2020
self[fn](params, peer) // process event
2121

22-
if (params.left === 0 && peer) peer.complete = true
23-
2422
cb(null, {
2523
complete: self.complete,
2624
incomplete: self.incomplete,
@@ -86,6 +84,12 @@ Swarm.prototype._onAnnounce_update = function (params, peer) {
8684
debug('unexpected `update` event from peer that is not in swarm')
8785
return this._onAnnounce_started(params, peer) // treat as a start
8886
}
87+
88+
if (!peer.complete && params.left === 0) {
89+
this.complete += 1
90+
this.incomplete -= 1
91+
peer.complete = true
92+
}
8993
}
9094

9195
// TODO: randomize the peers that are given out

0 commit comments

Comments
 (0)