pool: load interval

This commit is contained in:
Fedor Indutny 2014-05-06 20:46:20 +04:00
parent 2401fa2d4f
commit b98be4b388
3 changed files with 11 additions and 3 deletions

View File

@ -18,6 +18,7 @@ function Pool(options) {
this.redundancy = 2;
this.load = {
timeout: options.loadTimeout || 5000,
interval: options.loadInterval || 5000,
window: options.loadWindow || 250,
timer: null,
lwm: options.lwm || this.parallel * 2,
@ -101,10 +102,15 @@ Pool.prototype._addLoader = function _addLoader() {
peer.once('close', onclose);
function onclose() {
clearTimeout(timer);
clearInterval(interval);
self._removePeer(peer);
self._addLoader();
};
var interval = setInterval(function() {
self._load();
}, this.load.interval);
peer.once('ack', function() {
peer.updateWatch();
if (!self._load())
@ -115,7 +121,6 @@ Pool.prototype._addLoader = function _addLoader() {
// Chain is full and up-to-date
if (self.block.lastHash === null && self.chain.isFull()) {
clearTimeout(timer);
peer.removeListener('close', onclose);
self._removePeer(peer);
}

View File

@ -10,9 +10,12 @@ function TXPool() {
}
module.exports = TXPool;
TXPool.prototype.add = function add(tx) {
TXPool.prototype.add = function add(tx, wallet) {
var hash = tx.hash('hex');
if (!wallet.own(tx))
return;
// Do not add TX two times
if (this._all[hash])
return false;

View File

@ -149,7 +149,7 @@ Wallet.prototype.sign = function sign(tx, type) {
};
Wallet.prototype.addTX = function addTX(tx) {
return this.tx.add(tx);
return this.tx.add(tx, this);
};
Wallet.prototype.unspent = function unspent() {