added more socket functionality

This commit is contained in:
cubedro
2015-02-17 11:30:41 +02:00
parent ae7dc4579c
commit b0fdf6928c
9 changed files with 178 additions and 55 deletions

View File

@@ -11,6 +11,7 @@ var Collection = function Collection()
Collection.prototype.add = function(data)
{
var node = this.getNodeOrNew({ id : data.id }, data);
node.setInfo(data);
return node.getInfo();
}
@@ -24,8 +25,6 @@ Collection.prototype.update = function(id, stats)
node.stats = stats;
console.log(this.all());
return node.getStats();
}

View File

@@ -12,7 +12,13 @@ var Node = function Node(data)
peers: 0,
pending: 0,
gasPrice: 0,
block: {},
block: {
difficulty: 0,
number: 0,
gasLimit: 0,
timestamp: 0,
blocktime: 0
},
blocktimeAvg: 0,
difficulty: [],
uptime: 0,
@@ -25,8 +31,10 @@ var Node = function Node(data)
if(typeof data.info !== 'undefined')
this.info = data.info;
if(typeof data.ip !== 'undefined')
if(typeof data.ip !== 'undefined'){
this.info.ip = data.ip;
this.setGeo(data.ip);
}
return this;
}
@@ -36,9 +44,20 @@ Node.prototype.setGeo = function(ip)
this.geo = geoip.lookup(ip);
}
Node.prototype.setInfo = function(data)
{
if(typeof data.info !== 'undefined')
this.info = data.info;
if(typeof data.ip !== 'undefined'){
this.info.ip = data.ip;
this.setGeo(data.ip);
}
}
Node.prototype.getInfo = function()
{
return {id: this.id, info: this.info, geo: this.geo};
return {id: this.id, info: this.info, geo: this.geo, stats: this.stats};
}
Node.prototype.getStats = function()