diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-03-29 06:55:33 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-03-29 06:55:33 +0300 |
commit | 62a38621db2d088dcc7412e812063f3464d45cb8 (patch) | |
tree | adf62c2e5313922e5b4822539ea36acf83010c63 /lib | |
parent | ca4576f377ce26b6c41b41d5caa9c6bc426e0142 (diff) |
Don't create new outgoing TCP connections when torrent is done
Diffstat (limited to 'lib')
-rw-r--r-- | lib/swarm.js | 2 | ||||
-rw-r--r-- | lib/torrent.js | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/swarm.js b/lib/swarm.js index 6f169cb..7edee82 100644 --- a/lib/swarm.js +++ b/lib/swarm.js @@ -364,6 +364,8 @@ Swarm.prototype._drain = function () { conn.on('close', function () { if (self.destroyed) return + // TODO: If torrent is done, do not try to reconnect after a timeout + if (peer.retries >= RECONNECT_WAIT.length) { debug( 'conn %s closed: will not re-add (max %s attempts)', diff --git a/lib/torrent.js b/lib/torrent.js index eaa5396..aad46b5 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -299,7 +299,11 @@ Torrent.prototype._onSwarmListening = function () { port: self.client.torrentPort }) self.discovery.on('error', self._onError.bind(self)) - self.discovery.on('peer', self.addPeer.bind(self)) + self.discovery.on('peer', function (peer) { + // Don't create new outgoing TCP connections when torrent is done + if (typeof peer === 'string' && self.done) return + self.addPeer(peer) + }) // expose discovery events reemit(self.discovery, self, ['trackerAnnounce', 'dhtAnnounce', 'warning']) |