Merge pull request #170 from alxhotel/master

Check if peek(peerId) is undefined
This commit is contained in:
Feross Aboukhadijeh 2016-08-10 06:33:25 +02:00 committed by GitHub
commit 03fe83339c

View File

@ -198,28 +198,33 @@ function Server (opts) {
if (keys.length > 0) activeTorrents++
keys.forEach(function (peerId) {
if (!allPeers.hasOwnProperty(peerId)) {
allPeers[peerId] = {
ipv4: false,
ipv6: false,
seeder: false,
leecher: false
}
}
// Don't mark the peer as most recently used for stats
var peer = peers.peek(peerId)
if (peer.ip.indexOf(':') >= 0) {
allPeers[peerId].ipv6 = true
} else {
allPeers[peerId].ipv4 = true
// The peer could be evicted at this point
if (typeof peer !== 'undefined') {
if (!allPeers.hasOwnProperty(peerId)) {
allPeers[peerId] = {
ipv4: false,
ipv6: false,
seeder: false,
leecher: false
}
}
if (peer.ip.indexOf(':') >= 0) {
allPeers[peerId].ipv6 = true
} else {
allPeers[peerId].ipv4 = true
}
if (peer.complete) {
allPeers[peerId].seeder = true
} else {
allPeers[peerId].leecher = true
}
allPeers[peerId].peerId = peer.peerId
allPeers[peerId].client = peerid(peer.peerId)
}
if (peer.complete) {
allPeers[peerId].seeder = true
} else {
allPeers[peerId].leecher = true
}
allPeers[peerId].peerId = peer.peerId
allPeers[peerId].client = peerid(peer.peerId)
})
})