fetch-dht/lib/peerListFormatters/bencoded.js

24 lines
524 B
JavaScript
Raw Permalink Normal View History

2020-04-12 21:33:32 +00:00
const addrToIPPort = require('addr-to-ip-port');
const bencode = require('bencode');
const fakePeerId = require('../fakePeerId');
module.exports = (peers, res) => {
const response = bencode.encode({
interval: 30 * 60, // 30 minutes between requests
peers: peers.map((peer) => {
const [ip, port] = addrToIPPort(peer);
return {
ip,
'peer id': fakePeerId(peer),
port,
};
}),
});
res
.set({
'Content-Length': response.length,
})
.end(response);
};