балансировка нагрузки на базу
This commit is contained in:
@ -37,6 +37,7 @@ class Spider extends Emiter {
|
||||
this.bootstraps = options.bootstraps || bootstraps
|
||||
this.token = new Token()
|
||||
this.client = client
|
||||
this.ignore = false; // ignore all requests
|
||||
|
||||
this.walkInterval = 5;
|
||||
}
|
||||
@ -67,10 +68,13 @@ class Spider extends Emiter {
|
||||
|
||||
walk() {
|
||||
if(!this.client || this.client.isIdle()) {
|
||||
const node = this.table.shift()
|
||||
if (node) {
|
||||
this.findNode(Node.neighbor(node.id, this.table.id), {address: node.address, port: node.port})
|
||||
}
|
||||
if(!this.ignore)
|
||||
{
|
||||
const node = this.table.shift()
|
||||
if (node) {
|
||||
this.findNode(Node.neighbor(node.id, this.table.id), {address: node.address, port: node.port})
|
||||
}
|
||||
}
|
||||
}
|
||||
setTimeout(()=>this.walk(), this.walkInterval)
|
||||
}
|
||||
@ -138,7 +142,7 @@ class Spider extends Emiter {
|
||||
port: port
|
||||
};
|
||||
this.emit('ensureHash', infohash.toString('hex').toUpperCase(), addressPair)
|
||||
if(this.client) {
|
||||
if(this.client && !this.ignore) {
|
||||
this.client.add(addressPair, infohash);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user