From 96f6fce1ab6b68fef68d035700cfd3bb3294960c Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 6 Jun 2015 13:10:49 -0700 Subject: [PATCH] only return correct peer type from swarm --- lib/swarm.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/swarm.js b/lib/swarm.js index d12d053..67fdef7 100644 --- a/lib/swarm.js +++ b/lib/swarm.js @@ -20,10 +20,11 @@ Swarm.prototype.announce = function (params, cb) { if (self[fn]) { self[fn](params, peer) // process event + var peerType = params.compact === undefined ? 'webrtc' : 'addr' cb(null, { complete: self.complete, incomplete: self.incomplete, - peers: self._getPeers(params.numwant) + peers: self._getPeers(params.numwant, peerType) }) } else { 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 ite = randomIterate(Object.keys(this.peers)) while (true) { var peerId = ite() if (peers.length >= numWant || peerId == null) return peers var peer = this.peers[peerId] - if (peer) peers.push(peer) + if (peer && + ((peerType === 'webrtc' && peer.socket) || (peerType === 'addr' && peer.ip))) { + peers.push(peer) + } } }