fix pool peers.
This commit is contained in:
parent
ee97c7ed12
commit
6df8319871
@ -346,6 +346,7 @@ Pool.prototype._addLoader = function _addLoader() {
|
||||
};
|
||||
|
||||
Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
|
||||
var reqs = 0;
|
||||
var i, header, last, block;
|
||||
|
||||
assert(this.options.headers);
|
||||
@ -374,8 +375,10 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
|
||||
if (!block.verify())
|
||||
break;
|
||||
|
||||
if (!this.chain.has(block))
|
||||
if (!this.chain.has(block)) {
|
||||
this._request(this.block.type, block.hash('hex'));
|
||||
reqs++;
|
||||
}
|
||||
|
||||
last = block;
|
||||
}
|
||||
@ -401,12 +404,12 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer) {
|
||||
|
||||
this.emit('debug',
|
||||
'Requesting %s block packets from %s with getdata',
|
||||
this.request.queue.length,
|
||||
peer.host
|
||||
reqs, peer.host
|
||||
);
|
||||
};
|
||||
|
||||
Pool.prototype._handleBlocks = function _handleBlocks(hashes, peer) {
|
||||
var reqs = 0;
|
||||
var i, hash;
|
||||
|
||||
assert(!this.options.headers);
|
||||
@ -432,6 +435,7 @@ Pool.prototype._handleBlocks = function _handleBlocks(hashes, peer) {
|
||||
// Request block if we don't have it
|
||||
if (!this.chain.has(hash)) {
|
||||
this._request(this.block.type, hash);
|
||||
reqs++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -456,8 +460,7 @@ Pool.prototype._handleBlocks = function _handleBlocks(hashes, peer) {
|
||||
|
||||
this.emit('debug',
|
||||
'Requesting %s block packets from %s with getdata',
|
||||
this.request.queue.length,
|
||||
peer.host
|
||||
reqs, peer.host
|
||||
);
|
||||
};
|
||||
|
||||
@ -1426,19 +1429,19 @@ Pool.prototype.usableSeed = function usableSeed(addrs, force) {
|
||||
return Math.random() > 0.50 ? 1 : -1;
|
||||
});
|
||||
|
||||
if (this.peers.loader) {
|
||||
if (this.peers.load) {
|
||||
for (i = 0; i < addrs.length; i++) {
|
||||
if (!this.getPeer(addrs[i]))
|
||||
return addrs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!force)
|
||||
return;
|
||||
|
||||
if (addrs.length === 1)
|
||||
return addrs[0];
|
||||
|
||||
if (!force)
|
||||
return;
|
||||
|
||||
do {
|
||||
addr = addrs[Math.random() * (addrs.length - 1) | 0];
|
||||
} while (this.peers.load && this.getPeer(addr) === this.peers.load);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user