peer/pool: emit addr event on pool. refactor addr handler.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
Christopher Jeffrey 2014-05-15 01:14:06 -05:00 committed by Fedor Indutny
parent b2ee0891a1
commit 24779fb398
2 changed files with 10 additions and 5 deletions

View File

@ -327,6 +327,10 @@ Peer.prototype._handleAddr = function handleAddr(addr) {
// ipv4 - BE
ipv4 = utils.readU32BE(addr, 24);
ipv4 = ((ipv4 >> 24) & 0xff) + '.' +
((ipv4 >> 16) & 0xff) + '.' +
((ipv4 >> 8) & 0xff) + '.' +
((ipv4 >> 0) & 0xff);
// ipv6 - BE
ipv6 = utils.toHex(addr.slice(12, 24));
@ -338,14 +342,11 @@ Peer.prototype._handleAddr = function handleAddr(addr) {
this.emit('addr', {
date: new Date(date * 1000),
network: network,
address: ipv4,
ipv4: ipv4,
ipv6: ipv6,
port: port,
host: ((ipv4 >> 24) & 0xff) + '.' +
((ipv4 >> 16) & 0xff) + '.' +
((ipv4 >> 8) & 0xff) + '.' +
((ipv4 >> 0) & 0xff) + ':' +
port,
host: ipv4 + ':' + port,
host6: '[' + ipv6 + ']:' + port
});

View File

@ -310,6 +310,10 @@ Pool.prototype._addPeer = function _addPeer(backoff) {
self._response(tx);
self.emit('tx', tx);
});
peer.on('addr', function(addr) {
self.emit('addr', addr);
});
};
Pool.prototype._removePeer = function _removePeer(peer) {