catching the synced state better
simpler connect handling
This commit is contained in:
parent
6ad7d35963
commit
ccf51ec337
@ -10,7 +10,7 @@ var Bcoin = function(options) {
|
|||||||
this.emitter = new EE();
|
this.emitter = new EE();
|
||||||
};
|
};
|
||||||
|
|
||||||
Bcoin.prototype.start = function(callback) {
|
Bcoin.prototype.start = function(done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self._bcoin = bcoin.fullnode(self._config);
|
self._bcoin = bcoin.fullnode(self._config);
|
||||||
|
|
||||||
@ -18,11 +18,14 @@ Bcoin.prototype.start = function(callback) {
|
|||||||
|
|
||||||
self._bcoin.open().then(function() {
|
self._bcoin.open().then(function() {
|
||||||
self._bcoin.connect().then(function() {
|
self._bcoin.connect().then(function() {
|
||||||
self._bcoin.pool.once('full', function() {
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
self._bcoin.startSync();
|
|
||||||
log.info('Waiting for Bcoin to sync');
|
log.info('Waiting for Bcoin to sync');
|
||||||
|
self._bcoin.startSync();
|
||||||
|
if (self._bcoin.chain.synced){
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
self._bcoin.chain.once('full', function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -171,17 +171,14 @@ P2P.prototype._broadcast = function(subscribers, name, entity) {
|
|||||||
|
|
||||||
P2P.prototype._connect = function() {
|
P2P.prototype._connect = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
self._connectCalled = self._connectCalled > 0 ? 2 : 1;
|
log.info('Connecting to p2p network.');
|
||||||
if(self._connectCalled > 1 || !self._bcoin) {
|
self._pool.connect();
|
||||||
log.info('Connecting to p2p network.');
|
var retryInterval = setInterval(function() {
|
||||||
self._pool.connect();
|
self._pool.connect();
|
||||||
var retryInterval = setInterval(function() {
|
}, 5000);
|
||||||
self._pool.connect();
|
self._pool.once('peerready', function() {
|
||||||
}, 5000);
|
clearInterval(retryInterval);
|
||||||
self._pool.once('peerready', function() {
|
});
|
||||||
clearInterval(retryInterval);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
P2P.prototype._getBestHeight = function() {
|
P2P.prototype._getBestHeight = function() {
|
||||||
@ -315,9 +312,7 @@ P2P.prototype._setListeners = function() {
|
|||||||
self._pool.on('peertx', self._onPeerTx.bind(self));
|
self._pool.on('peertx', self._onPeerTx.bind(self));
|
||||||
self._pool.on('peerblock', self._onPeerBlock.bind(self));
|
self._pool.on('peerblock', self._onPeerBlock.bind(self));
|
||||||
self._pool.on('peerheaders', self._onPeerHeaders.bind(self));
|
self._pool.on('peerheaders', self._onPeerHeaders.bind(self));
|
||||||
if (!self._bcoin) {
|
self.node.on('ready', self._connect.bind(self));
|
||||||
self.node.on('ready', self._connect.bind(self));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
P2P.prototype._setResourceFilter = function(filter, resource) {
|
P2P.prototype._setResourceFilter = function(filter, resource) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user