diff options
author | KayleePop <34007889+KayleePop@users.noreply.github.com> | 2020-05-26 01:52:12 +0300 |
---|---|---|
committer | KayleePop <34007889+KayleePop@users.noreply.github.com> | 2020-05-26 01:52:12 +0300 |
commit | a07188f87a4acb7f8b2338c3d41da1b57cb9878c (patch) | |
tree | 2fad9ca9857ff9d1f2516d0a69e273eab191c62f /lib | |
parent | f4742f7f31d70ec793d209388c0ef7d09a357e6b (diff) |
fix: not setting initial wire interest
https://github.com/webtorrent/webtorrent/issues/1864
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 1a765a1..4ac71a0 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1084,7 +1084,7 @@ class Torrent extends EventEmitter { }) wire.bitfield(this.bitfield) // always send bitfield (required) - wire.uninterested() // always start out uninterested (as per protocol) + this._updateWireInterest(wire) // set inital interest // Send PORT message to peers that support DHT if (wire.peerExtensions.dht && this.client.dht && this.client.dht.listening) { @@ -1147,24 +1147,26 @@ class Torrent extends EventEmitter { const prev = this._amInterested this._amInterested = !!this._selections.length - this.wires.forEach(wire => { - let interested = false - for (let index = 0; index < this.pieces.length; ++index) { - if (this.pieces[index] && wire.peerPieces.get(index)) { - interested = true - break - } - } - - if (interested) wire.interested() - else wire.uninterested() - }) + this.wires.forEach(wire => this._updateWireInterest(wire)) if (prev === this._amInterested) return if (this._amInterested) this.emit('interested') else this.emit('uninterested') } + _updateWireInterest (wire) { + let interested = false + for (let index = 0; index < this.pieces.length; ++index) { + if (this.pieces[index] && wire.peerPieces.get(index)) { + interested = true + break + } + } + + if (interested) wire.interested() + else wire.uninterested() + } + /** * Heartbeat to update all peers and their requests. */ |