получения информации с трекеров
This commit is contained in:
68
index.js
68
index.js
@ -1,6 +1,7 @@
|
||||
const client = new (require('./lib/client'))
|
||||
const spider = new (require('./lib/spider'))(client)
|
||||
const mysql = require('mysql');
|
||||
const getPeersStatisticUDP = require('./lib/udp-tracker-request')
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
@ -27,6 +28,25 @@ let socketMysql = mysql.createPool({
|
||||
database : mysqlSettings.database
|
||||
});
|
||||
|
||||
const udpTrackers = [
|
||||
{
|
||||
host: 'tracker.coppersurfer.tk',
|
||||
port: 6969
|
||||
},
|
||||
{
|
||||
host: 'tracker.leechers-paradise.org',
|
||||
port: 6969
|
||||
},
|
||||
{
|
||||
host: 'tracker.opentrackr.org',
|
||||
port: 1337
|
||||
},
|
||||
{
|
||||
host: '9.rarbg.me',
|
||||
port: 2710
|
||||
}
|
||||
]
|
||||
|
||||
let listenerMysql;
|
||||
function handleListenerDisconnect() {
|
||||
listenerMysql = mysql.createConnection(mysqlSettings);
|
||||
@ -79,6 +99,9 @@ io.on('connection', function(socket)
|
||||
added: row.added.getTime(),
|
||||
contentType: row.contentType,
|
||||
contentCategory: row.contentCategory,
|
||||
seeders: row.seeders,
|
||||
completed: row.completed,
|
||||
leechers: row.leechers,
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,6 +353,51 @@ client.on('complete', function (metadata, infohash, rinfo) {
|
||||
contentType: torrentQ.contentType,
|
||||
contentCategory: torrentQ.contentCategory,
|
||||
});
|
||||
let maxSeeders = 0, maxLeechers = 0, maxCompleted = 0;
|
||||
udpTrackers.forEach((tracker) => {
|
||||
getPeersStatisticUDP(tracker.host, tracker.port, hash, ({seeders, completed, leechers}) => {
|
||||
if(seeders == 0 && completed == 0 && leechers == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
pushDatabaseBalance();
|
||||
listenerMysql.query('INSERT INTO trackers SET ?', statistic, function(err, result) {
|
||||
popDatabaseBalance();
|
||||
});
|
||||
*/
|
||||
|
||||
if(seeders < maxSeeders)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(seeders == maxSeeders && leechers < maxLeechers)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(seeders == maxSeeders && leechers == maxLeechers && completed <= maxCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
maxSeeders = seeders;
|
||||
maxLeechers = leechers;
|
||||
maxCompleted = completed;
|
||||
|
||||
pushDatabaseBalance();
|
||||
listenerMysql.query('UPDATE torrents SET seeders = ?, completed = ?, leechers = ? WHERE hash = ?', [seeders, completed, leechers, hash], function(err, result) {
|
||||
popDatabaseBalance();
|
||||
if(!result) {
|
||||
return
|
||||
}
|
||||
|
||||
io.sockets.emit('trackerTorrentUpdate', {
|
||||
hash,
|
||||
seeders,
|
||||
completed,
|
||||
leechers
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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)
|
||||
});
|
||||
|
@ -30,6 +30,17 @@ return (
|
||||
:
|
||||
null
|
||||
}
|
||||
{
|
||||
torrent.seeders || torrent.leechers || torrent.completed
|
||||
?
|
||||
<div className='break-word fs0-85' style={{paddingTop: '0.3em'}}>
|
||||
<span style={{color: (torrent.seeders > 0 ? '#00C853' : 'grey')}}>{torrent.seeders} seeders</span>
|
||||
<span style={{color: (torrent.leechers > 0 ? '#AA00FF' : 'grey'), marginLeft: '12px'}}>{torrent.leechers} leechers</span>
|
||||
<span style={{color: (torrent.completed > 0 ? '#FF6D00' : 'grey'), marginLeft: '12px'}}>{torrent.completed} completed downloads</span>
|
||||
</div>
|
||||
:
|
||||
null
|
||||
}
|
||||
</div>
|
||||
}
|
||||
leftIcon={
|
||||
@ -156,6 +167,7 @@ export default class RecentTorrents extends Component {
|
||||
super()
|
||||
this.torrents = [];
|
||||
this.displayQueue = [];
|
||||
this.displayQueueAssoc = {};
|
||||
this.state = { pause: false }
|
||||
}
|
||||
componentDidMount() {
|
||||
@ -174,17 +186,29 @@ export default class RecentTorrents extends Component {
|
||||
|
||||
let torrent = this.displayQueue.shift();
|
||||
this.torrents.unshift(torrent);
|
||||
if(this.torrents.length > 10)
|
||||
this.torrents.pop()
|
||||
if(this.torrents.length > 10) {
|
||||
let toDelete = this.torrents.pop()
|
||||
delete this.displayQueueAssoc[toDelete.hash];
|
||||
}
|
||||
|
||||
this.forceUpdate();
|
||||
}, 850);
|
||||
});
|
||||
this.newTorrentFunc = (torrent) => {
|
||||
this.displayQueue.push(torrent);
|
||||
this.displayQueueAssoc[torrent.hash] = torrent;
|
||||
this.forceUpdate();
|
||||
};
|
||||
window.torrentSocket.on('newTorrent', this.newTorrentFunc);
|
||||
|
||||
this.tracketUpdate = (statistic) => {
|
||||
if(statistic.hash in this.displayQueueAssoc)
|
||||
{
|
||||
Object.assign(this.displayQueueAssoc[statistic.hash], statistic);
|
||||
this.forceUpdate();
|
||||
}
|
||||
}
|
||||
window.torrentSocket.on('trackerTorrentUpdate', this.tracketUpdate);
|
||||
}
|
||||
pauseAndContinue() {
|
||||
this.setState({
|
||||
@ -194,6 +218,8 @@ export default class RecentTorrents extends Component {
|
||||
componentWillUnmount() {
|
||||
if(this.newTorrentFunc)
|
||||
window.torrentSocket.off('newTorrent', this.newTorrentFunc);
|
||||
if(this.tracketUpdate)
|
||||
window.torrentSocket.off('trackerTorrentUpdate', this.tracketUpdate);
|
||||
if(this.displayNewTorrent)
|
||||
clearInterval(this.displayNewTorrent);
|
||||
}
|
||||
|
Reference in New Issue
Block a user