возможность игнорировать dht трафик (опция), больше информации о балансировке
This commit is contained in:
17
bt/spider.js
17
bt/spider.js
@ -109,6 +109,10 @@ class Spider extends Emiter {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config.trafficIgnoreDHT && config.trafficMax > 0 && this.trafficSpeed > 0 && this.trafficSpeed > config.trafficMax) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const {t: tid, a: {id: nid, target: infohash}} = message
|
const {t: tid, a: {id: nid, target: infohash}} = message
|
||||||
|
|
||||||
if (tid === undefined || target.length != 20 || nid.length != 20) {
|
if (tid === undefined || target.length != 20 || nid.length != 20) {
|
||||||
@ -130,6 +134,10 @@ class Spider extends Emiter {
|
|||||||
return
|
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
|
const {t: tid, a: {id: nid, info_hash: infohash}} = message
|
||||||
|
|
||||||
if (tid === undefined || infohash.length != 20 || nid.length != 20) {
|
if (tid === undefined || infohash.length != 20 || nid.length != 20) {
|
||||||
@ -174,6 +182,14 @@ class Spider extends Emiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPingRequest(message, address) {
|
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)
|
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)
|
if(config.trafficMax > 0)
|
||||||
{
|
{
|
||||||
|
trafficDebug('inore dht traffic', config.trafficIgnoreDHT)
|
||||||
const path = `/sys/class/net/${config.trafficInterface}/statistics/rx_bytes`
|
const path = `/sys/class/net/${config.trafficInterface}/statistics/rx_bytes`
|
||||||
if(fs.existsSync(path))
|
if(fs.existsSync(path))
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ let config = {
|
|||||||
trafficInterface: 'enp2s0',
|
trafficInterface: 'enp2s0',
|
||||||
trafficMax: 0,
|
trafficMax: 0,
|
||||||
trafficUpdateTime: 3, //secs
|
trafficUpdateTime: 3, //secs
|
||||||
|
trafficIgnoreDHT: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
5
index.js
5
index.js
@ -490,15 +490,16 @@ let pushDatabaseBalance = () => {
|
|||||||
undoneQueries++;
|
undoneQueries++;
|
||||||
if(undoneQueries >= 5000)
|
if(undoneQueries >= 5000)
|
||||||
{
|
{
|
||||||
balanceDebug('too much freeze mysql connection. doing balance, queries:', undoneQueries);
|
balanceDebug('start balance mysql, queries:', undoneQueries);
|
||||||
spider.ignore = true;
|
spider.ignore = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let popDatabaseBalance = () => {
|
let popDatabaseBalance = () => {
|
||||||
undoneQueries--;
|
undoneQueries--;
|
||||||
|
balanceDebug('balanced, queries left:', undoneQueries);
|
||||||
if(undoneQueries == 0)
|
if(undoneQueries == 0)
|
||||||
{
|
{
|
||||||
balanceDebug('balance done, queries:', undoneQueries);
|
balanceDebug('balance done');
|
||||||
spider.ignore = !config.indexer;
|
spider.ignore = !config.indexer;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user