reject packets.
This commit is contained in:
parent
81be92b1ba
commit
b4b4e8b6cc
@ -57,6 +57,7 @@ function Pool(node, options) {
|
|||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
this.size = options.size || 8;
|
this.size = options.size || 8;
|
||||||
|
this.connected = false;
|
||||||
|
|
||||||
this.chain = node.chain;
|
this.chain = node.chain;
|
||||||
this.mempool = node.mempool;
|
this.mempool = node.mempool;
|
||||||
@ -171,6 +172,8 @@ Pool.prototype._init = function _init() {
|
|||||||
|
|
||||||
for (i = 0; i < this.size; i++)
|
for (i = 0; i < this.size; i++)
|
||||||
this._addPeer();
|
this._addPeer();
|
||||||
|
|
||||||
|
this.connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chain.on('block', function(block, entry, peer) {
|
this.chain.on('block', function(block, entry, peer) {
|
||||||
@ -1737,6 +1740,9 @@ Pool.prototype.getSeed = function getSeed(priority) {
|
|||||||
var addr;
|
var addr;
|
||||||
|
|
||||||
if (priority) {
|
if (priority) {
|
||||||
|
if (!this.connected)
|
||||||
|
return this.originalSeeds[0];
|
||||||
|
|
||||||
addr = this._getRandom(this.originalSeeds);
|
addr = this._getRandom(this.originalSeeds);
|
||||||
if (addr)
|
if (addr)
|
||||||
return addr;
|
return addr;
|
||||||
@ -1745,11 +1751,11 @@ Pool.prototype.getSeed = function getSeed(priority) {
|
|||||||
if (addr)
|
if (addr)
|
||||||
return addr;
|
return addr;
|
||||||
|
|
||||||
addr = this.seeds[Math.random() * (this.seeds.length - 1) | 0];
|
addr = this.seeds[Math.random() * this.seeds.length | 0];
|
||||||
if (addr)
|
if (addr)
|
||||||
return addr;
|
return addr;
|
||||||
|
|
||||||
return this.originalSeeds[Math.random() * (this.originalSeeds.length - 1) | 0];
|
return this.originalSeeds[Math.random() * this.originalSeeds.length | 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hang back if we don't have a loader peer yet.
|
// Hang back if we don't have a loader peer yet.
|
||||||
@ -1780,7 +1786,7 @@ Pool.prototype._getRandom = function _getRandom(seeds, uniq) {
|
|||||||
if (tries === seeds.length)
|
if (tries === seeds.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
index = Math.round(Math.random() * (seeds.length - 1));
|
index = Math.random() * seeds.length | 0;
|
||||||
addr = seeds[index];
|
addr = seeds[index];
|
||||||
|
|
||||||
if (!tried[index]) {
|
if (!tried[index]) {
|
||||||
@ -1884,13 +1890,10 @@ Pool.prototype.reject = function reject(peer, obj, reason, dos) {
|
|||||||
utils.debug('Rejecting %s %s: reason=%s',
|
utils.debug('Rejecting %s %s: reason=%s',
|
||||||
obj.type, obj.hash('hex'), reason);
|
obj.type, obj.hash('hex'), reason);
|
||||||
|
|
||||||
if (!peer)
|
peer.reject({
|
||||||
return false;
|
reason: reason,
|
||||||
|
data: obj.hash()
|
||||||
// peer.reject({
|
});
|
||||||
// reason: reason,
|
|
||||||
// data: obj.hash()
|
|
||||||
// });
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user