File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ Swarm.prototype.announce = function (params, cb) {
3030 cb ( null , {
3131 complete : self . complete ,
3232 incomplete : self . incomplete ,
33- peers : self . _getPeers ( params . numwant , ! ! params . socket )
33+ peers : self . _getPeers ( params . numwant , params . peer_id , ! ! params . socket )
3434 } )
3535}
3636
@@ -97,14 +97,16 @@ Swarm.prototype._onAnnounceUpdate = function (params, peer) {
9797 }
9898}
9999
100- Swarm . prototype . _getPeers = function ( numwant , isWebRTC ) {
100+ Swarm . prototype . _getPeers = function ( numwant , ownPeerId , isWebRTC ) {
101101 var peers = [ ]
102102 var ite = randomIterate ( Object . keys ( this . peers ) )
103103 var peerId
104104 while ( ( peerId = ite ( ) ) && peers . length < numwant ) {
105105 var peer = this . peers [ peerId ]
106106 if ( ! peer ) continue
107- if ( ( isWebRTC && peer . socket ) || ( ! isWebRTC && peer . ip ) ) peers . push ( peer )
107+ if ( isWebRTC && peer . peerId === ownPeerId ) continue // don't send peer to itself
108+ if ( ( isWebRTC && peer . ip ) || ( ! isWebRTC && peer . socket ) ) continue // send proper peer type
109+ peers . push ( peer )
108110 }
109111 return peers
110112}
You can’t perform that action at this time.
0 commit comments