From e6382c9af6e71a75357f60baf98fa9baa631fbc9 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 5 Dec 2015 00:41:56 -0800 Subject: [PATCH] don't send peer to itself --- lib/server/swarm.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/server/swarm.js b/lib/server/swarm.js index 84c2705..62e406f 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -30,7 +30,7 @@ Swarm.prototype.announce = function (params, cb) { cb(null, { complete: self.complete, incomplete: self.incomplete, - peers: self._getPeers(params.numwant, !!params.socket) + peers: self._getPeers(params.numwant, params.peer_id, !!params.socket) }) } @@ -97,14 +97,16 @@ Swarm.prototype._onAnnounceUpdate = function (params, peer) { } } -Swarm.prototype._getPeers = function (numwant, isWebRTC) { +Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) { var peers = [] var ite = randomIterate(Object.keys(this.peers)) var peerId while ((peerId = ite()) && peers.length < numwant) { var peer = this.peers[peerId] if (!peer) continue - if ((isWebRTC && peer.socket) || (!isWebRTC && peer.ip)) peers.push(peer) + if (isWebRTC && peer.peerId === ownPeerId) continue // don't send peer to itself + if ((isWebRTC && peer.ip) || (!isWebRTC && peer.socket)) continue // send proper peer type + peers.push(peer) } return peers }