fix(p2p): compact convert ip's

This commit is contained in:
Alexey Kasyanchuk 2018-02-17 01:23:53 +03:00
parent b1d2c4a334
commit a57ff6e430
2 changed files with 11 additions and 3 deletions

View File

@ -163,9 +163,8 @@ class Spider extends Emiter {
if(!peers || peers.length == 0)
return;
const nodes = Node.decodeNodes(peers)
console.log('peers', peers, nodes)
this.emit('peer', nodes)
const ips = Node.decodeCompactIP(peers)
this.emit('peer', ips)
}
onFindNodeRequest(message, address) {

View File

@ -31,6 +31,15 @@ class Node {
return nodes
}
static decodeCompactIP(data) {
return data.map((compact) => {
return {
address: `${compact[0]}.${compact[1]}.${compact[2]}.${compact[3]}`,
port: compact.readUInt16BE(4)
}
})
}
static encodeIP(ip) {
return Buffer.from(ip.split('.').map((i)=>parseInt(i)))
}