fix(p2p): compact convert ip's
This commit is contained in:
parent
b1d2c4a334
commit
a57ff6e430
@ -163,9 +163,8 @@ class Spider extends Emiter {
|
|||||||
if(!peers || peers.length == 0)
|
if(!peers || peers.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const nodes = Node.decodeNodes(peers)
|
const ips = Node.decodeCompactIP(peers)
|
||||||
console.log('peers', peers, nodes)
|
this.emit('peer', ips)
|
||||||
this.emit('peer', nodes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onFindNodeRequest(message, address) {
|
onFindNodeRequest(message, address) {
|
||||||
|
@ -31,6 +31,15 @@ class Node {
|
|||||||
return nodes
|
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) {
|
static encodeIP(ip) {
|
||||||
return Buffer.from(ip.split('.').map((i)=>parseInt(i)))
|
return Buffer.from(ip.split('.').map((i)=>parseInt(i)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user