From fef7d8fc2fbe28b7a70840f96c5e4e4443ab0765 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Fri, 25 Aug 2017 12:12:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D0=B3=D0=BD=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20dht=20=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=20(=D0=BE=D0=BF=D1=86=D0=B8=D1=8F),=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BE=20=D0=B1=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D1=81=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bt/spider.js | 17 +++++++++++++++++ config.js | 1 + index.js | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bt/spider.js b/bt/spider.js index aab7048..316b4ea 100644 --- a/bt/spider.js +++ b/bt/spider.js @@ -109,6 +109,10 @@ class Spider extends Emiter { return } + if(config.trafficIgnoreDHT && config.trafficMax > 0 && this.trafficSpeed > 0 && this.trafficSpeed > config.trafficMax) { + return + } + const {t: tid, a: {id: nid, target: infohash}} = message if (tid === undefined || target.length != 20 || nid.length != 20) { @@ -130,6 +134,10 @@ class Spider extends Emiter { return } + if(config.trafficIgnoreDHT && config.trafficMax > 0 && this.trafficSpeed > 0 && this.trafficSpeed > config.trafficMax) { + return + } + const {t: tid, a: {id: nid, info_hash: infohash}} = message if (tid === undefined || infohash.length != 20 || nid.length != 20) { @@ -174,6 +182,14 @@ class Spider extends Emiter { } onPingRequest(message, address) { + if(this.cpuLimit > 0 && cpuUsage() > this.cpuLimit) { + return + } + + if(config.trafficIgnoreDHT && config.trafficMax > 0 && this.trafficSpeed > 0 && this.trafficSpeed > config.trafficMax) { + return + } + this.send({ t: message.t, y: 'r', r: { id: Node.neighbor(message.a.id, this.table.id) } }, address) } @@ -224,6 +240,7 @@ class Spider extends Emiter { if(config.trafficMax > 0) { + trafficDebug('inore dht traffic', config.trafficIgnoreDHT) const path = `/sys/class/net/${config.trafficInterface}/statistics/rx_bytes` if(fs.existsSync(path)) { diff --git a/config.js b/config.js index c6c8a5f..b867f45 100644 --- a/config.js +++ b/config.js @@ -42,6 +42,7 @@ let config = { trafficInterface: 'enp2s0', trafficMax: 0, trafficUpdateTime: 3, //secs + trafficIgnoreDHT: false } const fs = require('fs'); diff --git a/index.js b/index.js index 3c7e0a2..e4a9fa9 100644 --- a/index.js +++ b/index.js @@ -490,15 +490,16 @@ let pushDatabaseBalance = () => { undoneQueries++; if(undoneQueries >= 5000) { - balanceDebug('too much freeze mysql connection. doing balance, queries:', undoneQueries); + balanceDebug('start balance mysql, queries:', undoneQueries); spider.ignore = true; } }; let popDatabaseBalance = () => { undoneQueries--; + balanceDebug('balanced, queries left:', undoneQueries); if(undoneQueries == 0) { - balanceDebug('balance done, queries:', undoneQueries); + balanceDebug('balance done'); spider.ignore = !config.indexer; } };