mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-31 10:31: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, {
|
cb(null, {
|
||||||
complete: self.complete,
|
complete: self.complete,
|
||||||
incomplete: self.incomplete,
|
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 peers = []
|
||||||
var ite = randomIterate(Object.keys(this.peers))
|
var ite = randomIterate(Object.keys(this.peers))
|
||||||
var peerId
|
var peerId
|
||||||
while ((peerId = ite()) && peers.length < numwant) {
|
while ((peerId = ite()) && peers.length < numwant) {
|
||||||
var peer = this.peers[peerId]
|
var peer = this.peers[peerId]
|
||||||
if (!peer) continue
|
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
|
return peers
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user