балансировка нагрузки на базу

This commit is contained in:
Alexey Kasyanchuk
2017-01-02 12:54:50 +03:00
parent 85836c5ff6
commit c766b2e5e8
2 changed files with 37 additions and 12 deletions

View File

@ -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);
}
}