updated node.info

This commit is contained in:
cubedro 2015-02-12 15:38:09 +02:00
parent 82e659834f
commit b87f19dc58
3 changed files with 25 additions and 5 deletions

View File

@ -1,8 +1,6 @@
var config = { var config = {
name: 'Node', name: 'Node',
type: 'C++', type: 'C++',
rpcHost: 'localhost',
rpcPort: '8080',
serverHost: 'localhost', serverHost: 'localhost',
serverPort: '3000' serverPort: '3000'
}; };

View File

@ -1,6 +1,8 @@
var web3 = require('ethereum.js'); var web3 = require('ethereum.js');
var _ = require('underscore'); var _ = require('underscore');
var os = require('os'); var os = require('os');
var slugs = require('slugs');
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
var MAX_BLOCKS_HISTORY = 12, var MAX_BLOCKS_HISTORY = 12,
LOWEST_TIMESTAMP = 0; LOWEST_TIMESTAMP = 0;
@ -9,14 +11,15 @@ function Node(options)
{ {
this.options = options; this.options = options;
this.info = { this.info = {
ip: this.getExternalIp(),
name: options.name, name: options.name,
ip: options.rpcHost,
type: options.type, type: options.type,
os: os.platform(), os: os.platform(),
os_v: os.release() os_v: os.release()
}; };
this.info.id = this.info.ip; this.info.id = this.makeId();
console.log(this.info);
this.stats = { this.stats = {
active: false, active: false,
listening: false, listening: false,
@ -39,7 +42,7 @@ function Node(options)
this.chainWatch = false; this.chainWatch = false;
this.updateInterval = false; this.updateInterval = false;
var sock = new web3.providers.HttpSyncProvider('http://' + this.options.rpcHost + ':' + this.options.rpcPort); var sock = new web3.providers.HttpSyncProvider('http://' + (process.env.RPC_HOST || 'localhost') + ':' + (process.env.RPC_PORT || '8080'));
web3.setProvider(sock); web3.setProvider(sock);
this.init(); this.init();
@ -47,6 +50,23 @@ function Node(options)
return this; return this;
} }
Node.prototype.getExternalIp = function()
{
var request = new XMLHttpRequest();
request.open('GET', 'http://curlmyip.com/', false);
request.send();
if(request.status !== 200)
return 'unknown';
return request.responseText.trim();
}
Node.prototype.makeId = function()
{
return slugs(this.info.name + ' ' + this.info.type + ' ' + this.info.os + ' ' + this.info.os_v + ' ' + this.info.ip);
}
Node.prototype.isActive = function() Node.prototype.isActive = function()
{ {
this.stats.uptime.inc++; this.stats.uptime.inc++;

View File

@ -9,6 +9,8 @@
"debug": "~2.0.0", "debug": "~2.0.0",
"ethereum.js": "*", "ethereum.js": "*",
"express.io": "^1.1.13", "express.io": "^1.1.13",
"xmlhttprequest": "*",
"slugs": "^0.1.3",
"underscore": "^1.7.0" "underscore": "^1.7.0"
} }
} }