дебаг
This commit is contained in:
parent
bb89191b8e
commit
9468159885
@ -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();
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
indexer: false,
|
||||
indexer: true,
|
||||
|
||||
domain: 'ratsontheboat.org',
|
||||
httpPort: 8095,
|
||||
|
2
index.js
2
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;
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user