moved popagation to backend fixes #38

This commit is contained in:
cubedro
2015-04-05 00:59:24 +03:00
parent 19646a71a7
commit ff5d8bd31a
5 changed files with 44 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ var Node = require('./node');
var Collection = function Collection()
{
this._list = [];
this._bestBlock = null;
return this;
}
@@ -23,6 +24,35 @@ Collection.prototype.update = function(id, stats)
if(!node)
return false;
if(this._bestBlock === null)
{
stats.block.received = (new Date()).getTime();
stats.block.propagation = 0;
this._bestBlock = stats.block;
}
else
{
var oldStats = node.getStats();
if(stats.block.number !== oldStats.stats.block.number)
{
stats.block.received = (new Date()).getTime();
if(this._bestBlock.number < oldStats.stats.block.number)
{
stats.block.propagation = 0;
this._bestBlock = stats.block;
}
else
{
stats.block.propagation = stats.block.received - this._bestBlock.received;
}
} else {
stats.block.received = oldStats.stats.block.received;
stats.block.propagation = oldStats.stats.block.propagation;
}
}
return node.setStats(stats);
}

View File

@@ -90,11 +90,12 @@ Node.prototype.setStats = function(stats)
{
if(typeof stats !== 'undefined' && typeof stats.block !== 'undefined' && typeof stats.block.number !== 'undefined')
{
if(stats.block.number !== this.stats.block.number) {
stats.block.received = (new Date()).getTime();
} else {
stats.block.received = this.stats.block.received;
}
// if(stats.block.number !== this.stats.block.number) {
// stats.block.received = (new Date()).getTime();
// } else {
// stats.block.received = this.stats.block.received;
// }
stats.block.hash = stats.block.hash.replace('0x', '');
this.stats = stats;