mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-13 19:06:27 +00:00
Use type from server to filter peers to offer
This commit is contained in:
parent
60320e3ed5
commit
eb3cefec35
@ -52,10 +52,11 @@ Swarm.prototype._onAnnounceStarted = function (params, peer) {
|
|||||||
else this.incomplete += 1
|
else this.incomplete += 1
|
||||||
var id = params.type === 'ws' ? params.peer_id : params.addr
|
var id = params.type === 'ws' ? params.peer_id : params.addr
|
||||||
peer = this.peers[id] = {
|
peer = this.peers[id] = {
|
||||||
|
type: params.type,
|
||||||
complete: params.left === 0,
|
complete: params.left === 0,
|
||||||
peerId: params.peer_id, // as hex
|
peerId: params.peer_id, // as hex
|
||||||
ip: params.ip, // only http, udp
|
ip: params.ip,
|
||||||
port: params.port, // only http, udp
|
port: params.port,
|
||||||
socket: params.socket // only websocket
|
socket: params.socket // only websocket
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,7 +108,7 @@ Swarm.prototype._getPeers = function (numwant, ownPeerId, isWebRTC) {
|
|||||||
while ((peerId = ite()) && peers.length < numwant) {
|
while ((peerId = ite()) && peers.length < numwant) {
|
||||||
var peer = this.peers[peerId]
|
var peer = this.peers[peerId]
|
||||||
if (isWebRTC && peer.peerId === ownPeerId) continue // don't send peer to itself
|
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)
|
peers.push(peer)
|
||||||
}
|
}
|
||||||
return peers
|
return peers
|
||||||
|
@ -46,6 +46,7 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
t.equal(swarm.incomplete, 1)
|
t.equal(swarm.incomplete, 1)
|
||||||
t.equal(Object.keys(swarm.peers).length, 1)
|
t.equal(Object.keys(swarm.peers).length, 1)
|
||||||
t.deepEqual(swarm.peers[hostname + ':6881'], {
|
t.deepEqual(swarm.peers[hostname + ':6881'], {
|
||||||
|
type: serverType,
|
||||||
ip: clientIp,
|
ip: clientIp,
|
||||||
port: 6881,
|
port: 6881,
|
||||||
peerId: peerId.toString('hex'),
|
peerId: peerId.toString('hex'),
|
||||||
|
Loading…
Reference in New Issue
Block a user