From 946815988595ba4547bdc41c0029c2a94aa5647f Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sat, 8 Jul 2017 21:38:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B5=D0=B1=D0=B0=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bt/client.js | 4 +++- bt/spider.js | 5 ++++- bt/udp-tracker-request.js | 15 ++++++++------- config.js | 2 +- index.js | 2 +- package.json | 1 + 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/bt/client.js b/bt/client.js index d766da8..f2904b6 100644 --- a/bt/client.js +++ b/bt/client.js @@ -6,6 +6,7 @@ var net = require('net'); var PeerQueue = require('./peer-queue'); var Wire = require('./wire'); +const debug = require('debug')('downloader'); class Client extends Emiter @@ -41,7 +42,7 @@ class Client extends Emiter _download(rinfo, infohash) { - console.log('start download ' + infohash.toString('hex')); + debug('start download ' + infohash.toString('hex')); this.activeConnections++; var successful = false; @@ -54,6 +55,7 @@ class Client extends Emiter wire.on('metadata', (metadata, infoHash) => { successful = true; + debug('successfuly downloader', infoHash, rinfo); this.emit('complete', metadata, infoHash, rinfo); socket.destroy(); }); diff --git a/bt/spider.js b/bt/spider.js index bcaec0c..f02b4ad 100644 --- a/bt/spider.js +++ b/bt/spider.js @@ -8,6 +8,9 @@ const Token = require('./token') const cpuUsage = require('./cpu-usage') const config = require('../config') +const _debug = require('debug') +const cpuDebug = _debug('cpu') + const bootstraps = [{ address: 'router.bittorrent.com', port: 6881 @@ -155,7 +158,7 @@ class Spider extends Emiter { }; this.emit('ensureHash', infohash.toString('hex').toUpperCase(), addressPair) if(this.client && !this.ignore) { - console.log('cpu usage:' + cpuUsage()) + cpuDebug('cpu usage:' + cpuUsage()) if(this.cpuLimit <= 0 || cpuUsage() <= this.cpuLimit + this.cpuInterval) { this.client.add(addressPair, infohash); } diff --git a/bt/udp-tracker-request.js b/bt/udp-tracker-request.js index eee94d9..e4e61a6 100644 --- a/bt/udp-tracker-request.js +++ b/bt/udp-tracker-request.js @@ -1,6 +1,7 @@ const dgram = require('dgram'); const server = dgram.createSocket("udp4") const config = require('../config'); +const debug = require('debug')('peers-scrape'); const ACTION_CONNECT = 0 const ACTION_ANNOUNCE = 1 @@ -20,7 +21,7 @@ let message = function (buf, host, port) { }; let connectTracker = function(connection) { - console.log('start connection'); + debug('start screape connection'); let buffer = new Buffer(16); const transactionId = Math.floor((Math.random()*100000)+1); @@ -48,7 +49,7 @@ let scrapeTorrent = function (connectionIdHigh, connectionIdLow, transactionId) if(!connection) return; - console.log('start scrape'); + debug('start scrape'); let buffer = new Buffer(56) buffer.fill(0); @@ -72,11 +73,11 @@ server.on("message", function (msg, rinfo) { if(!(transactionId in requests)) return; - console.log("returned action: " + action); - console.log("returned transactionId: " + transactionId); + debug("returned action: " + action); + debug("returned transactionId: " + transactionId); if (action === ACTION_CONNECT) { - console.log("connect response"); + debug("connect response"); let connectionIdHigh = buffer.readUInt32BE(8, 4); let connectionIdLow = buffer.readUInt32BE(12, 4); @@ -84,7 +85,7 @@ server.on("message", function (msg, rinfo) { scrapeTorrent(connectionIdHigh, connectionIdLow, transactionId); } else if (action === ACTION_SCRAPE) { - console.log("scrape response"); + debug("scrape response"); let seeders = buffer.readUInt32BE(8, 4); let completed = buffer.readUInt32BE(12, 4); @@ -102,7 +103,7 @@ server.on("message", function (msg, rinfo) { delete requests[transactionId]; } else if (action === ACTION_ERROR) { delete requests[transactionId]; - console.log("error response"); + console.log("error in scrape response"); } }); diff --git a/config.js b/config.js index 1312eda..881b7ac 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,5 @@ module.exports = { - indexer: false, + indexer: true, domain: 'ratsontheboat.org', httpPort: 8095, diff --git a/index.js b/index.js index e66bd10..c3804aa 100644 --- a/index.js +++ b/index.js @@ -506,7 +506,7 @@ const updateTorrentTrackers = (hash) => { } client.on('complete', function (metadata, infohash, rinfo) { - console.log('writing torrent to db'); + console.log('writing torrent', metadata.info.name, 'to database'); const hash = infohash.toString('hex'); let size = metadata.info.length ? metadata.info.length : 0; let filesCount = 1; diff --git a/package.json b/package.json index 87edb42..ef8bb6c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "connect-history-api-fallback": "1.3.0", "cross-spawn": "4.0.2", "css-loader": "0.26.0", + "debug": "^2.6.8", "detect-port": "1.0.1", "dotenv": "2.0.0", "eslint": "3.8.1",