Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/server/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ Swarm.prototype._onAnnounceStarted = function (params, peer) {
else this.incomplete += 1
var id = params.type === 'ws' ? params.peer_id : params.addr
peer = this.peers[id] = {
type: params.type,
complete: params.left === 0,
peerId: params.peer_id, // as hex
ip: params.ip, // only http, udp
port: params.port, // only http, udp
ip: params.ip,
port: params.port,
socket: params.socket // only websocket
}
}
Expand Down Expand Up @@ -107,7 +108,7 @@ Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) {
while ((peerId = ite()) && peers.length < numwant) {
var peer = this.peers[peerId]
if (isWebRTC && peer.peerId === ownPeerId) continue // don't send peer to itself
if ((isWebRTC && peer.ip) || (!isWebRTC && peer.socket)) continue // send proper peer type
if ((isWebRTC && peer.type !== 'ws') || (!isWebRTC && peer.type === 'ws')) continue // send proper peer type
peers.push(peer)
}
return peers
Expand Down
1 change: 1 addition & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function serverTest (t, serverType, serverFamily) {
t.equal(swarm.incomplete, 1)
t.equal(Object.keys(swarm.peers).length, 1)
t.deepEqual(swarm.peers[hostname + ':6881'], {
type: serverType,
ip: clientIp,
port: 6881,
peerId: peerId.toString('hex'),
Expand Down