|
|
@ -26,6 +26,13 @@ function PeerManager(config) { |
|
|
|
this.interval = 5000; |
|
|
|
this.minConnections = 8; |
|
|
|
this.minKnownPeers = 10; |
|
|
|
|
|
|
|
// keep track of tried seeds and results
|
|
|
|
this.seeds = { |
|
|
|
resolved: [], |
|
|
|
failed: [], |
|
|
|
results: {} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
PeerManager.parent = imports.parent || require('events').EventEmitter; |
|
|
@ -219,13 +226,6 @@ PeerManager.prototype.discoverPeers = function(callback) { |
|
|
|
var networks = imports.networks || require('../networks')[this.config.network]; |
|
|
|
var seeds = networks.dnsSeeds; |
|
|
|
|
|
|
|
// keep track of tried seeds and results
|
|
|
|
self.seeds = { |
|
|
|
resolved: [], |
|
|
|
failed: [], |
|
|
|
results: {} |
|
|
|
}; |
|
|
|
|
|
|
|
var dnsExecutor = seeds.map(function(seed) { |
|
|
|
return function(done) { |
|
|
|
// have we already resolved this seed?
|
|
|
@ -234,16 +234,19 @@ PeerManager.prototype.discoverPeers = function(callback) { |
|
|
|
return done(null, self.seeds.results[seed]); |
|
|
|
} |
|
|
|
// has this seed failed to resolve?
|
|
|
|
if (~self.seeds.resolved.indexOf(seed)) { |
|
|
|
if (~self.seeds.failed.indexOf(seed)) { |
|
|
|
// if so, pass back empty results
|
|
|
|
return done(null, []); |
|
|
|
} |
|
|
|
// otherwise resolve the dns seed to get some peers
|
|
|
|
log.info('resolving dns seed '+ seed); |
|
|
|
dns.resolve(seed, function(err, peers) { |
|
|
|
if (err) { |
|
|
|
log.err('failed to resolve dns seed '+ seed, err); |
|
|
|
self.seeds.failed.push(seed); |
|
|
|
return done(null, []); |
|
|
|
} |
|
|
|
log.info('found '+ peers.length + ' peers from ' + seed); |
|
|
|
self.seeds.resolved.push(seed); |
|
|
|
self.seeds.results[seed] = peers; |
|
|
|
return done(null, peers); |
|
|
|