pool: fix potential infinite loop with addrman.
This commit is contained in:
parent
bb1bf9f138
commit
cc4dd23c83
@ -2337,24 +2337,27 @@ HostList.prototype.isBanned = function isBanned(host) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a new loader host.
|
* Allocate a new host.
|
||||||
* @returns {HostEntry}
|
* @returns {HostEntry}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.getHost = function getHost() {
|
HostList.prototype.getHost = function getHost() {
|
||||||
var now = this.network.now();
|
var now = this.network.now();
|
||||||
var buckets = this.fresh;
|
var buckets = null;
|
||||||
var factor = 1;
|
var factor = 1;
|
||||||
var index, key, bucket, entry, num;
|
var index, key, bucket, entry, num;
|
||||||
|
|
||||||
if (this.size() === 0)
|
if (this.totalFresh > 0)
|
||||||
return;
|
buckets = this.fresh;
|
||||||
|
|
||||||
if (this.totalUsed > 0) {
|
if (this.totalUsed > 0) {
|
||||||
if (this.totalFresh === 0 || util.random(0, 2) === 0)
|
if (this.totalFresh === 0 || util.random(0, 2) === 0)
|
||||||
buckets = this.used;
|
buckets = this.used;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!buckets)
|
||||||
|
return;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
index = util.random(0, buckets.length);
|
index = util.random(0, buckets.length);
|
||||||
bucket = buckets[index];
|
bucket = buckets[index];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user