Skip to content

Commit e6382c9

Browse files
committed
don't send peer to itself
1 parent f56ca30 commit e6382c9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/server/swarm.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Swarm.prototype.announce = function (params, cb) {
3030
cb(null, {
3131
complete: self.complete,
3232
incomplete: self.incomplete,
33-
peers: self._getPeers(params.numwant, !!params.socket)
33+
peers: self._getPeers(params.numwant, params.peer_id, !!params.socket)
3434
})
3535
}
3636

@@ -97,14 +97,16 @@ Swarm.prototype._onAnnounceUpdate = function (params, peer) {
9797
}
9898
}
9999

100-
Swarm.prototype._getPeers = function (numwant, isWebRTC) {
100+
Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) {
101101
var peers = []
102102
var ite = randomIterate(Object.keys(this.peers))
103103
var peerId
104104
while ((peerId = ite()) && peers.length < numwant) {
105105
var peer = this.peers[peerId]
106106
if (!peer) continue
107-
if ((isWebRTC && peer.socket) || (!isWebRTC && peer.ip)) peers.push(peer)
107+
if (isWebRTC && peer.peerId === ownPeerId) continue // don't send peer to itself
108+
if ((isWebRTC && peer.ip) || (!isWebRTC && peer.socket)) continue // send proper peer type
109+
peers.push(peer)
108110
}
109111
return peers
110112
}

0 commit comments

Comments
 (0)