From 7f98203d5ec63f395e2794700a10046c54dcf8f1 Mon Sep 17 00:00:00 2001 From: Yoann Ciabaud Date: Thu, 9 Jun 2016 16:28:31 +0200 Subject: [PATCH] Manually clean peers on announce --- lib/server/swarm.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/server/swarm.js b/lib/server/swarm.js index d07f061..21940f8 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -118,6 +118,11 @@ Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) { var ite = randomIterate(Object.keys(this.peers.cache)) var peerId while ((peerId = ite()) && peers.length < numwant) { + // Check manually if the peer is active + if (peers.maxAge && (Date.now() - peers.cache[peerId].modified) > peers.maxAge) { + peers.remove(peerId) + continue + } // Don't mark the peer as most recently used on announce var peer = this.peers.peek(peerId) if (isWebRTC && peer.peerId === ownPeerId) continue // don't send peer to itself