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) + } } }