diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index de859a2..f7cc21b 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -455,17 +455,19 @@ Torrent.prototype.addPeer = function (peer) { self.emit('peer', peer) } - // TODO: extract IP address from peer object and check blocklist - if (typeof peer === 'string' && self.client.blocked && - self.client.blocked.contains(addrToIPPort(peer)[0])) { - self.numBlockedPeers += 1 - self.emit('blockedPeer', peer) - return false - } else { - if (self.swarm) addPeer() - else self.once('listening', addPeer) - return true + if (self.client.blocked) { + var addr = typeof peer === 'string' ? peer : peer.remoteAddress + + if (addr && self.client.blocked.contains(addrToIPPort(addr)[0])) { + self.numBlockedPeers += 1 + self.emit('blockedPeer', peer) + return false + } } + + if (self.swarm) addPeer() + else self.once('listening', addPeer) + return true } /** |