From 2f1491ade7b57fc86eeacf1ef7d48098c9ec5266 Mon Sep 17 00:00:00 2001 From: bradleyjkemp Date: Sat, 25 Feb 2017 20:40:39 +0000 Subject: Start peers as uninterested and only move to interested if/once they have a piece that we need --- lib/torrent.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/torrent.js b/lib/torrent.js index ae3e256..d85efae 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1095,7 +1095,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) { @@ -1174,8 +1174,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() }) -- cgit v1.2.3 From c17c8b1572cedc6c6658a5439f30879e172dc142 Mon Sep 17 00:00:00 2001 From: bradleyjkemp Date: Sat, 25 Feb 2017 21:11:25 +0000 Subject: whitespace fix --- lib/torrent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/torrent.js b/lib/torrent.js index d85efae..bd78bc6 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1181,7 +1181,7 @@ Torrent.prototype._updateInterest = function () { break } } - + if (interested) wire.interested() else wire.uninterested() }) -- cgit v1.2.3