我正在使用Node.js构建一个Bittorrent客户端,并且无法通过PWP元数据扩展(BEP 0009)从对等方获得答案
我从DHT(BEP 0005)(我宣布的地方)获得同行,然后使用网络套接字在PWP上发送握手和扩展握手.
buildHandshake = (torrent, ext) => { // torrent contains mainly infoHash
const buf = Buffer.alloc(68)
buf.writeUInt8(19, 0)
buf.write('BitTorrent protocol', 1)
if (ext) {
const big = new Uint64BE(1048576)
big.toBuffer().copy(buf, 20)
} else {
buf.writeUInt32BE(0, 20)
buf.writeUInt32BE(0, 24)
}
torrent.infoHashBuffer.copy(buf, 28)
anon.nodeId().copy(buf, 48) // tool that generates a nodeId once.
return buf
}
buildExtRequest = (id, msg) => {
const size = msg.length + 1
const buf = Buffer.alloc(size + 5)
buf.writeUInt32BE(size, 0) …Run Code Online (Sandbox Code Playgroud)