From 2252fcaac48230190d66b7d418ff90d7ec7dd948 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sat, 21 Jan 2017 01:16:40 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B5=D0=B9=D0=BA=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D0=BE=D1=80=D1=80=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.js | 5 ++-- index.js | 57 +++++++++++++++++++++++++------------- lib/udp-tracker-request.js | 2 +- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/config.js b/config.js index 8bf9be1..1312eda 100644 --- a/config.js +++ b/config.js @@ -1,10 +1,11 @@ module.exports = { - indexer: true, + indexer: false, domain: 'ratsontheboat.org', httpPort: 8095, spiderPort: 4445, - udpTrackersPort: 4446, + udpTrackersPort: 4446, + udpTrackersTimeout: 3 * 60 * 1000, sitemapMaxSize: 25000, diff --git a/index.js b/index.js index dcb4d1b..7746a9b 100644 --- a/index.js +++ b/index.js @@ -147,27 +147,27 @@ app.get('*', function(req, res) // start +function baseRowData(row) +{ + return { + hash: row.hash, + name: row.name, + size: row.size, + files: row.files, + filesList: row.filesList, + piecelength: row.piecelength, + added: row.added ? row.added.getTime() : (new Date()).getTime(), + contentType: row.contentType || row.contenttype, + contentCategory: row.contentCategory || row.contentcategory, + seeders: row.seeders, + completed: row.completed, + leechers: row.leechers, + trackersChecked: row.trackersChecked ? row.trackersChecked.getTime() : undefined, + } +} + io.on('connection', function(socket) { - function baseRowData(row) - { - return { - hash: row.hash, - name: row.name, - size: row.size, - files: row.files, - filesList: row.filesList, - piecelength: row.piecelength, - added: row.added ? row.added.getTime() : (new Date()).getTime(), - contentType: row.contentType || row.contenttype, - contentCategory: row.contentCategory || row.contentcategory, - seeders: row.seeders, - completed: row.completed, - leechers: row.leechers, - trackersChecked: row.trackersChecked ? row.trackersChecked.getTime() : undefined, - } - } - socket.on('recentTorrents', function(callback) { if(typeof callback != 'function') @@ -506,4 +506,23 @@ client.on('complete', function (metadata, infohash, rinfo) { if(config.indexer) { spider.listen(config.spiderPort) +} else { + function showFakeTorrents(page) + { + listenerMysql.query('SELECT * FROM torrents LIMIT ?, 100', [page], function(err, torrents) { + console.log(page) + if(!torrents) + return; + + torrents.forEach((torrent, index) => { + setTimeout(() => { + io.sockets.emit('newTorrent', baseRowData(torrent)); + updateTorrentTrackers(torrent.hash); + }, 700 * index) + }) + + setTimeout(()=>showFakeTorrents(torrents.length > 0 ? page + torrents.length : 0), 700 * torrents.length); + }); + } + showFakeTorrents(0); } \ No newline at end of file diff --git a/lib/udp-tracker-request.js b/lib/udp-tracker-request.js index 947fc5f..eee94d9 100644 --- a/lib/udp-tracker-request.js +++ b/lib/udp-tracker-request.js @@ -34,7 +34,7 @@ let connectTracker = function(connection) { // очистка старых соединений for(transaction in requests) { - if((new Date).getTime() - requests[transaction].date.getTime() > 3 * 60 * 1000) { + if((new Date).getTime() - requests[transaction].date.getTime() > config.udpTrackersTimeout) { delete requests[transaction]; } }