diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index c7bb10b1..0f57401a 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -101,10 +101,12 @@ function Pool(options) { if (options.headers == null) options.headers = options.spv; - seeds = (options.seeds || this.network.seeds).slice(); + seeds = options.seeds || this.network.seeds; - if (process.env.BCOIN_SEED) + if (process.env.BCOIN_SEED) { + seeds = seeds.slice(); seeds.unshift(process.env.BCOIN_SEED); + } this.seeds = seeds.map(function(hostname) { return NetworkAddress.fromHostname(hostname, self.network); @@ -1959,9 +1961,6 @@ Pool.prototype.getRandom = function getRandom(hosts, unique) { var tries = 0; var index, host; - if (!unique) - return hosts[Math.random() * hosts.length | 0]; - for (;;) { if (tries === hosts.length) return; @@ -1974,7 +1973,10 @@ Pool.prototype.getRandom = function getRandom(hosts, unique) { tries++; } - if (this.getPeer(host.host)) + if (this.isMisbehaving(host.host)) + continue; + + if (unique && this.getPeer(host.host)) continue; return host;