more code cleanup.
This commit is contained in:
parent
9c64b62078
commit
f24d4aa938
@ -64,8 +64,6 @@ function Pool(node, options) {
|
|||||||
|
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
this.synced = false;
|
this.synced = false;
|
||||||
this.busy = false;
|
|
||||||
this.jobs = [];
|
|
||||||
this._scheduled = false;
|
this._scheduled = false;
|
||||||
|
|
||||||
this.load = {
|
this.load = {
|
||||||
@ -233,57 +231,18 @@ Pool.prototype._init = function _init() {
|
|||||||
this.startServer();
|
this.startServer();
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._lock = function _lock(func, args, force) {
|
|
||||||
var self = this;
|
|
||||||
var called;
|
|
||||||
|
|
||||||
if (force) {
|
|
||||||
assert(this.busy);
|
|
||||||
return function unlock() {
|
|
||||||
assert(!called);
|
|
||||||
called = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.busy) {
|
|
||||||
this.jobs.push([func, args]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.busy = true;
|
|
||||||
|
|
||||||
return function unlock() {
|
|
||||||
var item;
|
|
||||||
|
|
||||||
assert(!called);
|
|
||||||
called = true;
|
|
||||||
|
|
||||||
self.busy = false;
|
|
||||||
|
|
||||||
if (self.jobs.length === 0) {
|
|
||||||
self.emit('flush');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item = self.jobs.shift();
|
|
||||||
item[0].apply(self, item[1]);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
self.chain.getLocator(top, function(err, locator) {
|
if (err)
|
||||||
if (err)
|
return callback(err);
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
peer.getBlocks(locator, stop);
|
peer.getBlocks(locator, stop);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -294,35 +253,33 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan, callbac
|
|||||||
|
|
||||||
assert(orphan);
|
assert(orphan);
|
||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
self.chain.getLocator(top, function(err, locator) {
|
if (err)
|
||||||
if (err)
|
return callback(err);
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
orphan = self.chain.getOrphanRoot(orphan);
|
orphan = self.chain.getOrphanRoot(orphan);
|
||||||
|
|
||||||
// Was probably resolved.
|
// Was probably resolved.
|
||||||
if (!orphan) {
|
if (!orphan) {
|
||||||
utils.debug('Orphan root was already resolved.');
|
utils.debug('Orphan root was already resolved.');
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're already processing the block
|
// If we're already processing the block
|
||||||
// that would resolve this, ignore.
|
// that would resolve this, ignore.
|
||||||
// if (self.request.map[orphan.soil]) {
|
// if (self.request.map[orphan.soil]) {
|
||||||
// utils.debug('Already requested orphan "soil".');
|
// utils.debug('Already requested orphan "soil".');
|
||||||
// return callback();
|
// return callback();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (self.chain.hasPending(orphan.soil)) {
|
// if (self.chain.hasPending(orphan.soil)) {
|
||||||
// utils.debug('Already processing orphan "soil".');
|
// utils.debug('Already processing orphan "soil".');
|
||||||
// return callback();
|
// return callback();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
peer.getBlocks(locator, orphan.root);
|
peer.getBlocks(locator, orphan.root);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -331,15 +288,13 @@ Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
|||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
self.chain.getLocator(top, function(err, locator) {
|
if (err)
|
||||||
if (err)
|
return callback(err);
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
peer.getHeaders(locator, stop);
|
peer.getHeaders(locator, stop);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user