Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
73c1ffb
Merge pull request #247 from cubedro/gasLimit
cubedro Aug 6, 2015
a234329
Merge pull request #248 from cubedro/gasLimit
cubedro Aug 6, 2015
9214e4b
Merge pull request #249 from cubedro/develop
cubedro Aug 6, 2015
e2cdec1
unbanned ip
cubedro Aug 7, 2015
f86ef9e
Merge branch 'develop' of https://github.com/cubedro/eth-netstats int…
cubedro Aug 7, 2015
c0b0cbb
Merge pull request #250 from cubedro/develop
cubedro Aug 7, 2015
91e54ec
add xss filter
frozeman Aug 11, 2015
99e7418
removed ip from display
cubedro Aug 12, 2015
7051070
Merge pull request #252 from cubedro/develop
cubedro Aug 12, 2015
10c7f93
Merge pull request #253 from cubedro/master
cubedro Aug 13, 2015
b9cd95b
Merge pull request #254 from cubedro/develop
cubedro Aug 13, 2015
f53e555
add meteor frontend app
frozeman Aug 14, 2015
3aa81fa
Merge pull request #255 from cubedro/master
cubedro Aug 17, 2015
472cc1f
Merge pull request #256 from cubedro/meteor
cubedro Aug 17, 2015
9401b91
Merge pull request #257 from cubedro/master
cubedro Aug 17, 2015
fef93f7
Merge pull request #258 from cubedro/develop
cubedro Aug 17, 2015
8573431
added multiple secrets
cubedro Aug 17, 2015
02a561a
Merge pull request #259 from cubedro/develop
cubedro Aug 17, 2015
c2a98f5
added secret split by | char
cubedro Aug 17, 2015
5f3dffc
Merge pull request #260 from cubedro/develop
cubedro Aug 17, 2015
a896730
Merge pull request #261 from cubedro/master
cubedro Aug 17, 2015
67e6e89
Merge pull request #262 from cubedro/meteor
cubedro Aug 17, 2015
a5ffebf
fixed WS_SECRET if no pipe line found
cubedro Aug 18, 2015
b50dda7
Merge pull request #263 from cubedro/develop
cubedro Aug 18, 2015
3237db0
fixed WS_SECRET bug
cubedro Aug 19, 2015
fa3e8d8
Merge pull request #264 from cubedro/develop
cubedro Aug 19, 2015
f4ac506
secret from js to json
cubedro Aug 19, 2015
2524a79
Merge pull request #265 from cubedro/develop
cubedro Aug 19, 2015
1f5a8ee
WS_SECRET json accepts object
cubedro Aug 19, 2015
10541dc
Merge pull request #266 from cubedro/develop
cubedro Aug 19, 2015
eccd9d5
added security alert blog post
cubedro Aug 20, 2015
84d88e7
Merge pull request #267 from cubedro/develop
cubedro Aug 20, 2015
0bd26a6
added back olympic block to lite version
cubedro Aug 20, 2015
731d6f7
Merge pull request #268 from cubedro/develop
cubedro Aug 20, 2015
4a2821a
changed olympic block announcement color to orange
cubedro Aug 20, 2015
b46a976
Merge pull request #269 from cubedro/develop
cubedro Aug 20, 2015
79a1632
updated dependency libraries
cubedro Aug 21, 2015
c3543af
Merge pull request #270 from cubedro/develop
cubedro Aug 21, 2015
84037d3
fixed secret bug
cubedro Aug 24, 2015
5e6e3d5
Merge pull request #271 from cubedro/develop
cubedro Aug 24, 2015
8d50891
updated block time colors
cubedro Aug 25, 2015
eb5a0ea
Merge pull request #272 from cubedro/develop
cubedro Aug 25, 2015
b2363d2
disabled node connection notifications
cubedro Aug 28, 2015
0808b8e
Merge pull request #273 from cubedro/develop
cubedro Aug 28, 2015
351c0e1
Changed security alert to latest
cubedro Sep 4, 2015
78cfbc2
Merge pull request #274 from cubedro/develop
cubedro Sep 4, 2015
75cfab7
added attention warning
cubedro Sep 9, 2015
a225a7d
Merge pull request #275 from cubedro/develop
cubedro Sep 9, 2015
b20269f
updated security alert
cubedro Sep 11, 2015
11a707b
updated security alert for lite version
cubedro Sep 11, 2015
b715024
Merge pull request #276 from cubedro/develop
cubedro Sep 11, 2015
55ac4ac
changed avg blocktime to be calculated from the entire history
cubedro Sep 14, 2015
8134928
Merge pull request #278 from cubedro/develop
cubedro Sep 14, 2015
019f64c
added another node to trusted ips
cubedro Sep 29, 2015
d6048da
Merge pull request #279 from cubedro/develop
cubedro Sep 29, 2015
a0c3bc2
removed trusted node check for history update
cubedro Oct 19, 2015
afafc71
Merge pull request #280 from cubedro/develop
cubedro Oct 19, 2015
b092bfd
made all nodes trusted
cubedro Oct 19, 2015
0291a3b
Merge pull request #281 from cubedro/develop
cubedro Oct 19, 2015
33f6cd1
fixed history sync bug
cubedro Oct 28, 2015
6b752f8
Merge pull request #282 from cubedro/develop
cubedro Oct 28, 2015
946408f
less logging
cubedro Oct 28, 2015
04f9f57
Merge pull request #283 from cubedro/develop
cubedro Oct 28, 2015
e017b27
switched source maps off
jesuscript Dec 4, 2015
6a1f289
bumped ws version
jesuscript Dec 4, 2015
0018342
fixed a possible typo
jesuscript Dec 4, 2015
41c3a06
fixed #284
cubedro Jan 8, 2016
f5f57ea
Merge pull request #285 from cubedro/develop
cubedro Jan 8, 2016
cbaca99
added support for isSyncing
cubedro Feb 1, 2016
2a7b1f1
bumped api version
cubedro Feb 1, 2016
fc5b355
Merge pull request #286 from cubedro/develop
cubedro Feb 1, 2016
f290106
updated analytics code
cubedro Feb 2, 2016
acf0165
Merge pull request #287 from cubedro/develop
cubedro Feb 2, 2016
1352dd8
Merge branch 'master' of https://github.com/cubedro/eth-netstats
jesuscript Mar 21, 2016
744b069
moved grunt into production dependencies
jesuscript Mar 21, 2016
e8afe1e
bumped ethstats client version
cubedro Apr 7, 2016
5e3375c
Merge pull request #292 from cubedro/develop
cubedro Apr 7, 2016
e82f1f4
changed ga tracking code
cubedro Jul 15, 2016
55a9721
Merge pull request #294 from cubedro/develop
cubedro Jul 15, 2016
d0b5adc
primus bump
jesuscript Oct 18, 2016
dbbdb5f
Merge branch 'master' of https://github.com/cubedro/eth-netstats into…
jesuscript Nov 8, 2016
1de39d2
bump primus
jesuscript Nov 8, 2016
b027754
comma fix in package.json
jesuscript Nov 8, 2016
e849a7f
fix for empty node info errors
jesuscript Nov 8, 2016
289008b
more fixing for incorrectly formatted node info
jesuscript Nov 8, 2016
e172a25
Merge pull request #298 from jesuscript/default-colors
cubedro Nov 9, 2016
86e6bf1
added another trusted ip
cubedro Dec 11, 2016
e391b87
Merge pull request #299 from cubedro/develop
cubedro Dec 11, 2016
a892077
fixed canUpdateHistory
cubedro Dec 11, 2016
caa057b
Merge pull request #300 from cubedro/develop
cubedro Dec 11, 2016
1c1cb25
better history handling
cubedro Dec 11, 2016
286378b
Merge pull request #301 from cubedro/develop
cubedro Dec 11, 2016
941c17a
fixed buggy if
cubedro Dec 11, 2016
5d3ed04
Merge pull request #302 from cubedro/develop
cubedro Dec 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ config/nodes.js
*.swp
*.pem
.node-xmlhttprequest-*
ws_secret.json
stats.json
16 changes: 8 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ module.exports = function(grunt) {
concat: {
vendor: {
options: {
sourceMap: true,
souceMap: false,
sourceMapIncludeSources: true,
sourceMapIn: ['dist/js/lib/*.map']
},
Expand All @@ -201,21 +201,21 @@ module.exports = function(grunt) {
},
netstats: {
options: {
sourceMap: true,
sourceMap: false,
sourceMapIncludeSources: true,
sourceMapIn: ['dist/js/vendor.min.js.map', 'dist/js/app.min.js.map']
},
src: ['<%= concat.vendor.dest %>', '<%= uglify.app.dest %>'],
dest: 'dist/js/netstats.min.js',
nonull: true,
nonull: true
},
css: {
src: ['dist/css/*.min.css', 'dist/css/*.css'],
dest: 'dist/css/netstats.min.css'
},
vendor_lite: {
options: {
sourceMap: true,
sourceMap: false,
sourceMapIncludeSources: true,
sourceMapIn: ['dist-lite/js/lib/*.map']
},
Expand All @@ -231,7 +231,7 @@ module.exports = function(grunt) {
},
netstats_lite: {
options: {
sourceMap: true,
sourceMap: false,
sourceMapIncludeSources: true,
sourceMapIn: ['dist-lite/js/vendor.min.js.map', 'dist-lite/js/app.min.js.map']
},
Expand All @@ -248,7 +248,7 @@ module.exports = function(grunt) {
app: {
options: {
mangle: false,
sourceMap: true,
sourceMap: false,
sourceMapIncludeSources: true
},
dest: 'dist/js/app.min.js',
Expand All @@ -257,7 +257,7 @@ module.exports = function(grunt) {
app_lite: {
options: {
mangle: false,
sourceMap: true,
sourceMap: false,
sourceMapIncludeSources: true
},
dest: 'dist-lite/js/app.min.js',
Expand All @@ -277,4 +277,4 @@ module.exports = function(grunt) {
grunt.registerTask('lite', ['clean:build_lite', 'clean:cleanup_js_lite', 'clean:cleanup_css_lite', 'jade:build_lite', 'copy:build_lite', 'cssmin:build_lite', 'concat:vendor_lite', 'concat:scripts_lite', 'uglify:app_lite', 'concat:netstats_lite', 'concat:css_lite', 'clean:cleanup_js_lite', 'clean:cleanup_css_lite']);
grunt.registerTask('build', 'default');
grunt.registerTask('all', ['default', 'lite']);
};
};
37 changes: 31 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@ var logger = require('./lib/utils/logger');
var chalk = require('chalk');
var http = require('http');

var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
// Init WS SECRET
var WS_SECRET;

if( !_.isUndefined(process.env.WS_SECRET) && !_.isNull(process.env.WS_SECRET) )
{
if( process.env.WS_SECRET.indexOf('|') > 0 )
{
WS_SECRET = process.env.WS_SECRET.split('|');
}
else
{
WS_SECRET = [process.env.WS_SECRET];
}
}
else
{
try {
var tmp_secret_json = require('./ws_secret.json');
WS_SECRET = _.values(tmp_secret_json);
}
catch (e)
{
console.error("WS_SECRET NOT SET!!!");
}
}

var banned = require('./lib/utils/config').banned;

// Init http server
Expand All @@ -29,8 +54,8 @@ api = new Primus(server, {
parser: 'JSON'
});

api.use('emit', require('primus-emit'));
api.use('spark-latency', require('primus-spark-latency'));
api.plugin('emit', require('primus-emit'));
api.plugin('spark-latency', require('primus-spark-latency'));


// Init Client Socket connection
Expand All @@ -40,7 +65,7 @@ client = new Primus(server, {
parser: 'JSON'
});

client.use('emit', require('primus-emit'));
client.plugin('emit', require('primus-emit'));


// Init external API
Expand All @@ -50,7 +75,7 @@ external = new Primus(server, {
parser: 'JSON'
});

external.use('emit', require('primus-emit'));
external.plugin('emit', require('primus-emit'));

// Init collections
var Collection = require('./lib/collection');
Expand Down Expand Up @@ -81,7 +106,7 @@ api.on('connection', function (spark)
{
console.info('API', 'CON', 'Hello', data['id']);

if( _.isUndefined(data.secret) || data.secret !== WS_SECRET || banned.indexOf(spark.address.ip) >= 0 )
if( _.isUndefined(data.secret) || WS_SECRET.indexOf(data.secret) === -1 || banned.indexOf(spark.address.ip) >= 0 )
{
spark.end(undefined, { reconnect: false });
console.error('API', 'CON', 'Closed - wrong auth', data);
Expand Down
13 changes: 7 additions & 6 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Collection.prototype.update = function(id, stats, callback)
}
else
{
this._blockchain.clean(this.getBestBlockFromItems());
// this._blockchain.clean(this.getBestBlockFromItems());

var block = this._blockchain.add(stats.block, id, node.trusted);

Expand Down Expand Up @@ -75,7 +75,7 @@ Collection.prototype.addBlock = function(id, stats, callback)
}
else
{
this._blockchain.clean(this.getBestBlockFromItems());
// this._blockchain.clean(this.getBestBlockFromItems());

var block = this._blockchain.add(stats, id, node.trusted);

Expand Down Expand Up @@ -142,7 +142,7 @@ Collection.prototype.addHistory = function(id, blocks, callback)
{
blocks = blocks.reverse();

this._blockchain.clean(this.getBestBlockFromItems());
// this._blockchain.clean(this.getBestBlockFromItems());

for (var i = 0; i <= blocks.length - 1; i++)
{
Expand Down Expand Up @@ -288,7 +288,8 @@ Collection.prototype.getHistory = function()
Collection.prototype.getBestBlockFromItems = function()
{
return Math.max(this._blockchain.bestBlockNumber(), _.result(_.max(this._items, function(item) {
return ( !item.trusted ? 0 : item.stats.block.number );
// return ( !item.trusted ? 0 : item.stats.block.number );
return ( item.stats.block.number );
}), 'stats.block.number', 0));
}

Expand All @@ -301,9 +302,9 @@ Collection.prototype.canNodeUpdate = function(id)

if(node.canUpdate())
{
var diff = this._blockchain.bestBlockNumber() - node.getBlockNumber();
var diff = node.getBlockNumber() - this._blockchain.bestBlockNumber();

return (diff <= 0);
return Boolean(diff >= 0);
}

return false;
Expand Down
31 changes: 26 additions & 5 deletions lib/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ History.prototype.add = function(block, id, trusted, addingHistory)
propagTimes: []
}

if( this._items.length === 0 || (this._items.length === MAX_HISTORY && block.number > this.worstBlockNumber() && !addingHistory) || (this._items.length < MAX_HISTORY && block.number < this.bestBlockNumber()) )
if( this._items.length === 0 || (this._items.length === MAX_HISTORY && block.number > this.worstBlockNumber()) || (this._items.length < MAX_HISTORY && block.number < this.bestBlockNumber() && addingHistory) )
{
item.propagTimes.push({
node: id,
Expand Down Expand Up @@ -429,13 +429,32 @@ History.prototype.getBlockTimes = function()
.reverse()
.map(function (item)
{
return item.block.time;
return item.block.time / 1000;
})
.value();

return blockTimes;
}

History.prototype.getAvgBlocktime = function()
{
var blockTimes = _( this._items )
.sortByOrder( 'height', false )
// .filter(function (item)
// {
// return item.block.trusted;
// })
// .slice(0, MAX_BINS)
.reverse()
.map(function (item)
{
return item.block.time / 1000;
})
.value();

return _.sum(blockTimes) / (blockTimes.length === 0 ? 1 : blockTimes.length);
}

History.prototype.getGasLimit = function()
{
var gasLimitHistory = _( this._items )
Expand Down Expand Up @@ -598,7 +617,8 @@ History.prototype.getCharts = function()
this._callback(null, {
height : _.pluck( chartHistory, 'height' ),
blocktime : _.pluck( chartHistory, 'blocktime' ),
avgBlocktime : _.sum(_.pluck( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length),
// avgBlocktime : _.sum(_.pluck( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length),
avgBlocktime : this.getAvgBlocktime(),
difficulty : _.pluck( chartHistory, 'difficulty' ),
uncles : _.pluck( chartHistory, 'uncles' ),
transactions : _.pluck( chartHistory, 'transactions' ),
Expand All @@ -614,12 +634,13 @@ History.prototype.getCharts = function()

History.prototype.requiresUpdate = function()
{
return ( this._items.length < MAX_HISTORY && !_.isEmpty(this._items) );
// return ( this._items.length < MAX_HISTORY && !_.isEmpty(this._items) );
return ( this._items.length < MAX_HISTORY );
}

History.prototype.getHistoryRequestRange = function()
{
if( _.isEmpty(this._items) )
if( this._items.length < 2 )
return false;

var blocks = _.pluck( this._items, 'height' );
Expand Down
11 changes: 10 additions & 1 deletion lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var Node = function(data)
transactions: [],
uncles: []
},
syncing: false,
propagationAvg: 0,
latency: 0,
uptime: 100
Expand Down Expand Up @@ -113,6 +114,7 @@ Node.prototype.getInfo = function(callback)
stats: {
active: this.stats.active,
mining: this.stats.mining,
syncing: this.stats.syncing,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
Expand Down Expand Up @@ -235,6 +237,7 @@ Node.prototype.setBasicStats = function(stats, callback)
{
this.stats.active = stats.active;
this.stats.mining = stats.mining;
this.stats.syncing = (!_.isUndefined(stats.syncing) ? stats.syncing : false);
this.stats.hashrate = stats.hashrate;
this.stats.peers = stats.peers;
this.stats.gasPrice = stats.gasPrice;
Expand Down Expand Up @@ -284,6 +287,7 @@ Node.prototype.getStats = function()
stats: {
active: this.stats.active,
mining: this.stats.mining,
syncing: this.stats.syncing,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
Expand Down Expand Up @@ -314,6 +318,7 @@ Node.prototype.getBasicStats = function()
stats: {
active: this.stats.active,
mining: this.stats.mining,
syncing: this.stats.syncing,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
Expand Down Expand Up @@ -369,7 +374,11 @@ Node.prototype.getBlockNumber = function()

Node.prototype.canUpdate = function()
{
return (this.info.canUpdateHistory && this.trusted) || false;
if (this.trusted) {
return true;
}
// return (this.info.canUpdateHistory && this.trusted) || false;
return (this.info.canUpdateHistory || (this.stats.syncing === false && this.stats.peers > 0)) || false;
}

Node.prototype.isInactiveAndOld = function()
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ var trusted = [
'178.19.221.38',
'185.37.145.18',
'172.31.39.87',
'86.120.171.69',
'86.123.155.6',
'188.24.81.133',
'::ffff:127.0.0.1',
];

var banned = [
'198.48.150.206'
// '198.48.150.206'
];

module.exports = {
Expand Down
14 changes: 13 additions & 1 deletion lib/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ var typeColors = {
'PIN': chalk.reset.bold.yellow,
};

var verbosity = [
[],
['error'],
['error', 'warn', 'success'],
['info', 'error', 'warn', 'success', 'time', 'timeEnd']
];

var ENV_VERBOSITY = process.env.VERBOSITY || 2;

[
{
name: "info",
Expand Down Expand Up @@ -102,6 +111,9 @@ var typeColors = {

console[item.name] = function ()
{
if(verbosity[ENV_VERBOSITY].indexOf(item.name) === -1)
return false;

var args = Array.prototype.slice.call(arguments);
var type = null,
sign,
Expand Down Expand Up @@ -150,4 +162,4 @@ var typeColors = {

return fn.apply( this, item.formatter(sign, message) );
}
});
});
Loading