Manually clean peers on announce

This commit is contained in:
Yoann Ciabaud 2016-06-09 16:28:31 +02:00
parent 5dcc932247
commit 7f98203d5e

View File

@ -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