From ca7afa614ad7e37ac8818d91270603aef6dfdac6 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sat, 17 Feb 2018 21:03:42 +0300 Subject: [PATCH] feat(config): p2p enable/disable --- src/app/app.js | 8 +++++--- src/background/bt/spider.js | 13 ++++--------- src/background/spider.js | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/app.js b/src/app/app.js index bf213e1..43b25f8 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -101,9 +101,11 @@ class App extends Component { render() { return ( - -
0 ? 'green' : 'grey'}}> - rats peers: {window.peers} {window.peers > 0 ? ' (p2p rats search enabled)' : ' (p2p rats search not available at this moment)'} +
+ +
0 ? 'green' : 'grey'}}> + rats peers: {window.peers} {window.peers > 0 ? ' (p2p rats search enabled)' : ' (p2p rats search not available at this moment)'} +
); diff --git a/src/background/bt/spider.js b/src/background/bt/spider.js index 63dc0e7..72d1be6 100644 --- a/src/background/bt/spider.js +++ b/src/background/bt/spider.js @@ -8,7 +8,6 @@ const Token = require('./token') const cpuUsage = require('./cpu-usage') const config = require('../config') const fs = require('fs') -const crypto = require('crypto') const _debug = require('debug') const cpuDebug = _debug('spider:cpu') @@ -52,7 +51,7 @@ class Spider extends Emiter { this.cpuLimit = config.spider.cpuLimit; this.cpuInterval = config.spider.cpuInterval; - this.announceHashes = [crypto.createHash('sha1').update('degrats-v1').digest()] + this.announceHashes = [] } send(message, address) { @@ -333,16 +332,12 @@ class Spider extends Emiter { } } - this.announceSearchInterval = setInterval(() => this.getPeersRequest(this.announceHashes[0]), 2000) - - /* - setInterval(() => { - for(const address of this.table.nodes) + this.announceSearchInterval = setInterval(() => { + for(const hash of this.announceHashes) { - this.announcePeer(this.announcePeer[0], null, address) + this.getPeersRequest(hash) } }, 3000) - */ } close(callback) diff --git a/src/background/spider.js b/src/background/spider.js index 6b8510d..d207ca4 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -5,6 +5,7 @@ const mysql = require('mysql'); const getPeersStatisticUDP = require('./bt/udp-tracker-request') const net = require('net') const JsonSocket = require('json-socket') +const crypto = require('crypto') //var express = require('express'); //var app = express(); @@ -630,6 +631,15 @@ tcpServer.on('connection', (socket) => { if(option in config) config[option] = options[option] } + + if(config.p2p) + { + spider.announceHashes = [crypto.createHash('sha1').update('degrats-v1').digest()] + } + else + { + spider.announceHashes = [] + } if(typeof callback === 'function') callback(true) @@ -1157,6 +1167,10 @@ function hideFakeTorrents() if(config.indexer) { spider.listen(config.spiderPort) + if(config.p2p) + { + spider.announceHashes = [crypto.createHash('sha1').update('degrats-v1').digest()] + } } else { // showFakeTorrents(); }