mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
don't send peer to itself
This commit is contained in:
parent
f56ca3031b
commit
e6382c9af6
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user