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

3
app.js
View File

@ -82,6 +82,8 @@ api.on('connection', function(spark) {
data.stats.latency = spark.latency;
var stats = Nodes.update(data.id, data.stats);
if(stats !== false)
{
client.write({action: 'update', data: stats});
var blockPropagationChart = Nodes.blockPropagationChart();
@ -90,6 +92,7 @@ api.on('connection', function(spark) {
var uncleCount = Nodes.getUncleCount();
client.write({action: 'uncleCount', data: uncleCount});
}
}
});
spark.on('node-ping', function(data){

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

@ -32,6 +32,8 @@ var History = function History(data)
}
History.prototype.add = function(block, id)
{
if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined')
{
var historyBlock = this.search(block.number);
@ -76,6 +78,9 @@ History.prototype.add = function(block, id)
return block;
}
return false;
}
History.prototype._save = function(block)
{
this._items.push(block);