updated node.info
This commit is contained in:
26
lib/node.js
26
lib/node.js
@@ -1,6 +1,8 @@
|
||||
var web3 = require('ethereum.js');
|
||||
var _ = require('underscore');
|
||||
var os = require('os');
|
||||
var slugs = require('slugs');
|
||||
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
|
||||
|
||||
var MAX_BLOCKS_HISTORY = 12,
|
||||
LOWEST_TIMESTAMP = 0;
|
||||
@@ -9,14 +11,15 @@ function Node(options)
|
||||
{
|
||||
this.options = options;
|
||||
this.info = {
|
||||
ip: this.getExternalIp(),
|
||||
name: options.name,
|
||||
ip: options.rpcHost,
|
||||
type: options.type,
|
||||
os: os.platform(),
|
||||
os_v: os.release()
|
||||
};
|
||||
|
||||
this.info.id = this.info.ip;
|
||||
this.info.id = this.makeId();
|
||||
console.log(this.info);
|
||||
this.stats = {
|
||||
active: false,
|
||||
listening: false,
|
||||
@@ -39,7 +42,7 @@ function Node(options)
|
||||
this.chainWatch = 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);
|
||||
|
||||
this.init();
|
||||
@@ -47,6 +50,23 @@ function Node(options)
|
||||
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()
|
||||
{
|
||||
this.stats.uptime.inc++;
|
||||
|
||||
Reference in New Issue
Block a user