diff options
author | Diego RodrÃguez Baquero <diegorbaquero@gmail.com> | 2018-07-25 03:07:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-25 03:07:15 +0300 |
commit | d37d6a772c86e60c296506b675dd4167855e76b6 (patch) | |
tree | 7d7ef0f237b0456c98733abc1ee46c9c6d4aa6f1 /lib | |
parent | 2e422208de7e4679be0913a842082291d36dd7d1 (diff) | |
parent | c17c8b1572cedc6c6658a5439f30879e172dc142 (diff) |
Merge pull request #1061 from bradleyjkemp/correct-availability
Implement correct interested behaviour
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index a7253f6..f959a1c 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1116,7 +1116,7 @@ Torrent.prototype._onWireWithMetadata = function (wire) { }) wire.bitfield(self.bitfield) // always send bitfield (required) - wire.interested() // always start out interested + wire.uninterested() // always start out uninterested (as per protocol) // Send PORT message to peers that support DHT if (wire.peerExtensions.dht && self.client.dht && self.client.dht.listening) { @@ -1185,8 +1185,15 @@ Torrent.prototype._updateInterest = function () { self._amInterested = !!self._selections.length self.wires.forEach(function (wire) { - // TODO: only call wire.interested if the wire has at least one piece we need - if (self._amInterested) wire.interested() + var interested = false + for (var index = 0; index < self.pieces.length; ++index) { + if (self.pieces[index] && wire.peerPieces.get(index)) { + interested = true + break + } + } + + if (interested) wire.interested() else wire.uninterested() }) |