From eb3cefec358e168d9b31dd28f6cf7146a9317e2e Mon Sep 17 00:00:00 2001 From: Yoann Ciabaud Date: Sun, 13 Mar 2016 15:51:08 +0100 Subject: [PATCH] Use type from server to filter peers to offer --- lib/server/swarm.js | 7 ++++--- test/server.js | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/server/swarm.js b/lib/server/swarm.js index 4f2a927..1dad058 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -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 } } @@ -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 diff --git a/test/server.js b/test/server.js index e1451c2..1934f75 100644 --- a/test/server.js +++ b/test/server.js @@ -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'),