diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 0e6db599..c5f5cfb5 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -49,6 +49,8 @@ function Pool(node, options) { seeds.unshift(process.env.BCOIN_SEED); this.originalSeeds = seeds.map(utils.parseHost); + this.seeds = []; + this.hosts = {}; this.setSeeds([]); this.server = null; @@ -1731,89 +1733,6 @@ Pool.prototype.getPeer = function getPeer(addr) { } }; -Pool.prototype.getSeed = function getSeed(priority) { - var i, addr; - var original = this.originalSeeds; - var seeds = this.seeds; - var all = original.concat(seeds); - - // Hang back if we don't have a loader peer yet. - if (!priority && !this.peers.load) - return; - - // Randomize the non-original peers. - seeds = seeds.slice().sort(function() { - return Math.random() > 0.50 ? 1 : -1; - }); - - // Try to avoid connecting to a peer twice. - // Try the original peers first. - for (i = 0; i < original.length; i++) { - addr = original[i]; - assert(addr.host); - if (this.getPeer(addr)) - continue; - if (this.isMisbehaving(addr.host)) - continue; - return addr; - } - - // If we are a priority socket, try to find a - // peer this time with looser requirements. - if (priority) { - for (i = 0; i < original.length; i++) { - addr = original[i]; - assert(addr.host); - if (this.peers.load && this.getPeer(addr) === this.peers.load) - continue; - if (this.isMisbehaving(addr.host)) - continue; - return addr; - } - } - - // Try the rest of the peers second. - for (i = 0; i < seeds.length; i++) { - addr = seeds[i]; - assert(addr.host); - if (this.getPeer(addr)) - continue; - if (this.isMisbehaving(addr.host)) - continue; - return addr; - } - - // If we are a priority socket, try to find a - // peer this time with looser requirements. - if (priority) { - for (i = 0; i < seeds.length; i++) { - addr = seeds[i]; - assert(addr.host); - if (this.peers.load && this.getPeer(addr) === this.peers.load) - continue; - if (this.isMisbehaving(addr.host)) - continue; - return addr; - } - } - - // If we have no block peers, always return - // an address. - if (!priority) { - if (all.length === 1) - return all[Math.random() * (all.length - 1) | 0]; - } - - // This should never happen: priority sockets - // should _always_ get an address. - if (priority) { - utils.debug( - 'We had to connect to a random peer. Something is not right.'); - - return all[Math.random() * (all.length - 1) | 0]; - } -}; - Pool.prototype.getSeed = function getSeed(priority) { var addr;