Skip to content

Commit 5588419

Browse files
committed
Merge pull request webtorrent#124 from yciabaud/fix-peertype
Bugfix: Do not use params.ip to filter Websocket peers
2 parents 60320e3 + eb3cefe commit 5588419

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/server/swarm.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ Swarm.prototype._onAnnounceStarted = function (params, peer) {
5252
else this.incomplete += 1
5353
var id = params.type === 'ws' ? params.peer_id : params.addr
5454
peer = this.peers[id] = {
55+
type: params.type,
5556
complete: params.left === 0,
5657
peerId: params.peer_id, // as hex
57-
ip: params.ip, // only http, udp
58-
port: params.port, // only http, udp
58+
ip: params.ip,
59+
port: params.port,
5960
socket: params.socket // only websocket
6061
}
6162
}
@@ -107,7 +108,7 @@ Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) {
107108
while ((peerId = ite()) && peers.length < numwant) {
108109
var peer = this.peers[peerId]
109110
if (isWebRTC && peer.peerId === ownPeerId) continue // don't send peer to itself
110-
if ((isWebRTC && peer.ip) || (!isWebRTC && peer.socket)) continue // send proper peer type
111+
if ((isWebRTC && peer.type !== 'ws') || (!isWebRTC && peer.type === 'ws')) continue // send proper peer type
111112
peers.push(peer)
112113
}
113114
return peers

test/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function serverTest (t, serverType, serverFamily) {
4646
t.equal(swarm.incomplete, 1)
4747
t.equal(Object.keys(swarm.peers).length, 1)
4848
t.deepEqual(swarm.peers[hostname + ':6881'], {
49+
type: serverType,
4950
ip: clientIp,
5051
port: 6881,
5152
peerId: peerId.toString('hex'),

0 commit comments

Comments
 (0)