Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/torrent.js28
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.
*/