diff --git a/src/background/bt/spider.js b/src/background/bt/spider.js index 4f0bcdd..5eee04f 100644 --- a/src/background/bt/spider.js +++ b/src/background/bt/spider.js @@ -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) { diff --git a/src/background/bt/table.js b/src/background/bt/table.js index c3ac200..4cdebaa 100644 --- a/src/background/bt/table.js +++ b/src/background/bt/table.js @@ -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))) }