updated node.info
This commit is contained in:
parent
82e659834f
commit
b87f19dc58
@ -1,8 +1,6 @@
|
||||
var config = {
|
||||
name: 'Node',
|
||||
type: 'C++',
|
||||
rpcHost: 'localhost',
|
||||
rpcPort: '8080',
|
||||
serverHost: 'localhost',
|
||||
serverPort: '3000'
|
||||
};
|
||||
|
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++;
|
||||
|
@ -9,6 +9,8 @@
|
||||
"debug": "~2.0.0",
|
||||
"ethereum.js": "*",
|
||||
"express.io": "^1.1.13",
|
||||
"xmlhttprequest": "*",
|
||||
"slugs": "^0.1.3",
|
||||
"underscore": "^1.7.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user