From e6baedd6ed7818f3c527f0c7828dcb58ad0fd7ca Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 11 May 2015 21:41:37 +0300 Subject: [PATCH 1/3] added check for old inactive nodes --- models/collection.js | 25 +++++++++++++++++++++++++ models/node.js | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/models/collection.js b/models/collection.js index 180f73f..e667bff 100644 --- a/models/collection.js +++ b/models/collection.js @@ -115,9 +115,34 @@ Collection.prototype.getNodeOrNew = function(search, data) Collection.prototype.all = function() { + this.removeOldNodes(); + return this._items; } +Collection.prototype.removeOldNodes = function() +{ + var deleteList = [] + + for(var i = this._items.length - 1; i >= 0; i--) + { + var node = this._items[i]; + + if( node.isInactiveAndOld() ) + { + deleteList.push(i); + } + } + + if(deleteList.length > 0) + { + for(var i = 0; i < deleteList.length; i++) + { + this._items.splice(deleteList[i], 1); + } + } +} + Collection.prototype.blockPropagationChart = function() { return this._blockchain.getBlockPropagation(); diff --git a/models/node.js b/models/node.js index 1de6db9..a5dbc1a 100644 --- a/models/node.js +++ b/models/node.js @@ -2,6 +2,7 @@ var geoip = require('geoip-lite'); var _ = require('lodash'); var MAX_HISTORY = 40; +var MAX_INACTIVE_TIME = 1000; var Node = function Node(data) { @@ -180,4 +181,20 @@ Node.prototype.canUpdate = function() return this.info.canUpdateHistory || false; } +Node.prototype.isInactiveAndOld = function() +{ + if(this.stats.active) + return false; + + var lastState = this.uptime.history[this.uptime.history.length -1]; + + if( !_.isUndefined(lastState) && !_.isUndefined(lastState.status) && !_.isUndefined(lastState.time) ) + { + if( lastState.status === 'down' && (_.now() - lastState.time) > MAX_INACTIVE_TIME ) + return true; + } + + return false; +} + module.exports = Node; From be4654aee7773bbec4064348bcb8a77e8e8ad24a Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 11 May 2015 22:03:08 +0300 Subject: [PATCH 2/3] added node cleanup refresh timeout for 1h --- app.js | 15 +++++++++++++++ models/node.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 39230f7..9ba645b 100644 --- a/app.js +++ b/app.js @@ -185,6 +185,21 @@ var latencyTimeout = setInterval( function () client.write({ action: 'client-ping' }); }, 5000); + +// Cleanup old inactive nodes +var nodeCleanupTimeout = setInterval( function () +{ + client.write({ + action: 'init', + data: Nodes.all() + }); + + client.write({ + action: 'charts', + data: Nodes.getCharts() + }); +}, 1000*60); + // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); diff --git a/models/node.js b/models/node.js index a5dbc1a..b134db5 100644 --- a/models/node.js +++ b/models/node.js @@ -2,7 +2,7 @@ var geoip = require('geoip-lite'); var _ = require('lodash'); var MAX_HISTORY = 40; -var MAX_INACTIVE_TIME = 1000; +var MAX_INACTIVE_TIME = 1000*60*4; var Node = function Node(data) { From ea7079291ed2fa9a639a9a8fd4607f2582c2288f Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 11 May 2015 22:10:19 +0300 Subject: [PATCH 3/3] fixed cleanup timeouts --- app.js | 2 +- models/node.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 9ba645b..561796e 100644 --- a/app.js +++ b/app.js @@ -198,7 +198,7 @@ var nodeCleanupTimeout = setInterval( function () action: 'charts', data: Nodes.getCharts() }); -}, 1000*60); +}, 1000*60*60); // view engine setup app.set('views', path.join(__dirname, 'views')); diff --git a/models/node.js b/models/node.js index b134db5..96a9ae1 100644 --- a/models/node.js +++ b/models/node.js @@ -2,7 +2,7 @@ var geoip = require('geoip-lite'); var _ = require('lodash'); var MAX_HISTORY = 40; -var MAX_INACTIVE_TIME = 1000*60*4; +var MAX_INACTIVE_TIME = 1000*60*60*4; var Node = function Node(data) {