peer/pool: emit addr event on pool. refactor addr handler.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
b2ee0891a1
commit
24779fb398
@ -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
|
||||
});
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user