Skip to content

Commit 96f6fce

Browse files
committed
only return correct peer type from swarm
1 parent ad0cd4e commit 96f6fce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/swarm.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ Swarm.prototype.announce = function (params, cb) {
2020
if (self[fn]) {
2121
self[fn](params, peer) // process event
2222

23+
var peerType = params.compact === undefined ? 'webrtc' : 'addr'
2324
cb(null, {
2425
complete: self.complete,
2526
incomplete: self.incomplete,
26-
peers: self._getPeers(params.numwant)
27+
peers: self._getPeers(params.numwant, peerType)
2728
})
2829
} else {
2930
cb(new Error('invalid event'))
@@ -93,13 +94,16 @@ Swarm.prototype._onAnnounce_update = function (params, peer) {
9394
}
9495
}
9596

96-
Swarm.prototype._getPeers = function (numWant) {
97+
Swarm.prototype._getPeers = function (numWant, peerType) {
9798
var peers = []
9899
var ite = randomIterate(Object.keys(this.peers))
99100
while (true) {
100101
var peerId = ite()
101102
if (peers.length >= numWant || peerId == null) return peers
102103
var peer = this.peers[peerId]
103-
if (peer) peers.push(peer)
104+
if (peer &&
105+
((peerType === 'webrtc' && peer.socket) || (peerType === 'addr' && peer.ip))) {
106+
peers.push(peer)
107+
}
104108
}
105109
}

0 commit comments

Comments
 (0)