Skip to content
Merged
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
43 changes: 24 additions & 19 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
if (peer.complete) {
allPeers[peerId].seeder = true
} else {
allPeers[peerId].leecher = true

// The peer could be evicted at this point
if (typeof peer !== 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually better to invert if-statements like this one to prevent another level of indentation.

This is better, IMO:

if (peer == null) return

Also, it's better to be defensive and treat null like no peer as well, hence the ==.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f2786cd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll keep it in mind for future PRs

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)
}
allPeers[peerId].peerId = peer.peerId
allPeers[peerId].client = peerid(peer.peerId)
})
})

Expand Down