mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-13 19:06:27 +00:00
only return correct peer type from swarm
This commit is contained in:
parent
ad0cd4edab
commit
96f6fce1ab
10
lib/swarm.js
10
lib/swarm.js
@ -20,10 +20,11 @@ Swarm.prototype.announce = function (params, cb) {
|
|||||||
if (self[fn]) {
|
if (self[fn]) {
|
||||||
self[fn](params, peer) // process event
|
self[fn](params, peer) // process event
|
||||||
|
|
||||||
|
var peerType = params.compact === undefined ? 'webrtc' : 'addr'
|
||||||
cb(null, {
|
cb(null, {
|
||||||
complete: self.complete,
|
complete: self.complete,
|
||||||
incomplete: self.incomplete,
|
incomplete: self.incomplete,
|
||||||
peers: self._getPeers(params.numwant)
|
peers: self._getPeers(params.numwant, peerType)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
cb(new Error('invalid event'))
|
cb(new Error('invalid event'))
|
||||||
@ -93,13 +94,16 @@ Swarm.prototype._onAnnounce_update = function (params, peer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Swarm.prototype._getPeers = function (numWant) {
|
Swarm.prototype._getPeers = function (numWant, peerType) {
|
||||||
var peers = []
|
var peers = []
|
||||||
var ite = randomIterate(Object.keys(this.peers))
|
var ite = randomIterate(Object.keys(this.peers))
|
||||||
while (true) {
|
while (true) {
|
||||||
var peerId = ite()
|
var peerId = ite()
|
||||||
if (peers.length >= numWant || peerId == null) return peers
|
if (peers.length >= numWant || peerId == null) return peers
|
||||||
var peer = this.peers[peerId]
|
var peer = this.peers[peerId]
|
||||||
if (peer) peers.push(peer)
|
if (peer &&
|
||||||
|
((peerType === 'webrtc' && peer.socket) || (peerType === 'addr' && peer.ip))) {
|
||||||
|
peers.push(peer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user