получения информации с трекеров
This commit is contained in:
@ -31,6 +31,13 @@ let connectTracker = function(connection) {
|
||||
buffer.writeUInt32BE(ACTION_CONNECT, 8);
|
||||
buffer.writeUInt32BE(transactionId, 12);
|
||||
|
||||
// очистка старых соединений
|
||||
for(transaction in requests) {
|
||||
if((new Date).getTime() - requests[transaction].date.getTime() > 60 * 1000) {
|
||||
delete requests[transaction];
|
||||
}
|
||||
}
|
||||
|
||||
requests[transactionId] = connection;
|
||||
message(buffer, connection.host, connection.port);
|
||||
};
|
||||
@ -58,12 +65,9 @@ let scrapeTorrent = function (connectionIdHigh, connectionIdLow, transactionId)
|
||||
server.on("message", function (msg, rinfo) {
|
||||
let buffer = new Buffer(msg)
|
||||
|
||||
console.log('response from ' + rinfo);
|
||||
|
||||
const action = buffer.readUInt32BE(0, 4);
|
||||
const transactionId = buffer.readUInt32BE(4, 4);
|
||||
|
||||
console.log(Object.keys(requests));
|
||||
if(!(transactionId in requests))
|
||||
return;
|
||||
|
||||
@ -103,7 +107,7 @@ server.on("message", function (msg, rinfo) {
|
||||
|
||||
let getPeersStatistic = (host, port, hash, callback) => {
|
||||
let connection = {
|
||||
host, port, hash, callback
|
||||
host, port, hash, callback, date: new Date()
|
||||
}
|
||||
connectTracker(connection);
|
||||
}
|
||||
@ -113,15 +117,11 @@ server.on("listening", function () {
|
||||
console.log("listening udp tracker respose on " + address.address + ":" + address.port);
|
||||
});
|
||||
|
||||
server.bind(4444);
|
||||
server.bind(4446);
|
||||
|
||||
getPeersStatistic('tracker.coppersurfer.tk', 6969, "d096ff66557a5ea7030680967610e38b37434ea9", (data) => {
|
||||
console.log(data)
|
||||
});
|
||||
module.exports = getPeersStatistic;
|
||||
|
||||
//getPeersStatistic('tracker.glotorrents.com', 6969, "d096ff66557a5ea7030680967610e38b37434ea8", (data) => {
|
||||
// console.log(data)
|
||||
//});
|
||||
|
||||
getPeersStatistic('tracker.coppersurfer.tk', 6969, "d096ff66557a5ea7030680967610e38b37434ea8", (data) => {
|
||||
console.log(data)
|
||||
});
|
||||
getPeersStatistic('tracker.coppersurfer.tk', 6969, "d096ff66557a5ea7030680967610e38b37434ea8", (data) => {
|
||||
console.log(data)
|
||||
});
|
||||
|
Reference in New Issue
Block a user