better error handling

This commit is contained in:
cubedro 2015-04-28 02:50:28 +03:00
parent 068133b021
commit 2fd2145d54
3 changed files with 49 additions and 37 deletions

13
app.js
View File

@ -82,13 +82,16 @@ api.on('connection', function(spark) {
data.stats.latency = spark.latency;
var stats = Nodes.update(data.id, data.stats);
client.write({action: 'update', data: stats});
if(stats !== false)
{
client.write({action: 'update', data: stats});
var blockPropagationChart = Nodes.blockPropagationChart();
client.write({action: 'blockPropagationChart', data: blockPropagationChart});
var blockPropagationChart = Nodes.blockPropagationChart();
client.write({action: 'blockPropagationChart', data: blockPropagationChart});
var uncleCount = Nodes.getUncleCount();
client.write({action: 'uncleCount', data: uncleCount});
var uncleCount = Nodes.getUncleCount();
client.write({action: 'uncleCount', data: uncleCount});
}
}
});

View File

@ -27,6 +27,10 @@ Collection.prototype.update = function(id, stats)
return false;
var block = this._history.add(stats.block, id);
if(! block)
return false;
var propagationHistory = this._history.getNodePropagation(id);
stats.block.arrived = block.arrived;

View File

@ -33,47 +33,52 @@ var History = function History(data)
History.prototype.add = function(block, id)
{
var historyBlock = this.search(block.number);
var now = (new Date()).getTime();
block.arrived = now;
block.received = now;
block.propagation = 0;
if(historyBlock)
if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined')
{
var propIndex = _.findIndex(historyBlock.propagTimes, {node: id});
var historyBlock = this.search(block.number);
if(propIndex === -1)
var now = (new Date()).getTime();
block.arrived = now;
block.received = now;
block.propagation = 0;
if(historyBlock)
{
block.arrived = historyBlock.block.arrived;
block.received = now;
block.propagation = now - historyBlock.block.received;
var propIndex = _.findIndex(historyBlock.propagTimes, {node: id});
historyBlock.propagTimes.push({node: id, received: now, propagation: block.propagation});
if(propIndex === -1)
{
block.arrived = historyBlock.block.arrived;
block.received = now;
block.propagation = now - historyBlock.block.received;
historyBlock.propagTimes.push({node: id, received: now, propagation: block.propagation});
}
else
{
block.arrived = historyBlock.block.arrived;
block.received = historyBlock.propagTimes[propIndex].received;
block.propagation = historyBlock.propagTimes[propIndex].propagation;
}
}
else
{
block.arrived = historyBlock.block.arrived;
block.received = historyBlock.propagTimes[propIndex].received;
block.propagation = historyBlock.propagTimes[propIndex].propagation;
}
}
else
{
var item = {
height: block.number,
block: block,
propagTimes: []
}
var item = {
height: block.number,
block: block,
propagTimes: []
}
item.propagTimes.push({node: id, received: now, propagation: block.propagation});
console.log('item: ', item);
this._save(item);
}
this.getNodePropagation(id);
item.propagTimes.push({node: id, received: now, propagation: block.propagation});
console.log('item: ', item);
this._save(item);
}
this.getNodePropagation(id);
return block;
return block;
}
return false;
}
History.prototype._save = function(block)