24 lines
524 B
JavaScript
24 lines
524 B
JavaScript
|
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);
|
||
|
};
|