Split out peer cmds into new functions
-Add new setting for getpeerinfo cmd -getpeerinfo api call moved to explorer.js -Peer geo location api call moved to explorer.js
This commit is contained in:
@@ -29,6 +29,7 @@ This project is a fork of [Ciquidus Explorer](https://github.com/suprnurd/ciquid
|
||||
- **getblock:** Returns an object with information about the block
|
||||
- **getrawtransaction:** Returns raw transaction data
|
||||
- **getinfo:** Returns an object containing various state info
|
||||
- **getpeerinfo:** Returns data about each connected network node as a json array of objects
|
||||
- **gettxoutsetinfo:** Returns an object with statistics about the unspent transaction output set
|
||||
- **getsupply:** Returns the current money supply
|
||||
- **getmaxmoney:** Returns the number of coins that will be produced in total
|
||||
|
||||
@@ -733,6 +733,40 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get_peerinfo: function(cb) {
|
||||
var cmd = prepareRpcCommand(settings.api_cmds.getpeerinfo);
|
||||
|
||||
if (!(cmd.method == '' && cmd.parameters.length == 0)) {
|
||||
if (settings.use_rpc) {
|
||||
rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) {
|
||||
// check if an error msg was received from the rpc server
|
||||
if (response == 'There was an error. Check your console.')
|
||||
return cb(null);
|
||||
else
|
||||
return cb(response);
|
||||
});
|
||||
} else {
|
||||
var uri = base_url + 'getpeerinfo';
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
// check if an error msg was received from the web api server
|
||||
if (body == 'There was an error. Check your console.')
|
||||
return cb(null);
|
||||
else
|
||||
return cb(body);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// cmd not in use. return null.
|
||||
return cb(null);
|
||||
}
|
||||
},
|
||||
|
||||
get_geo_location: function(address, cb) {
|
||||
request({uri: 'https://freegeoip.app/json/' + address, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, geo) {
|
||||
return cb(error, geo);
|
||||
});
|
||||
},
|
||||
|
||||
is_unique: function(array, object, cb) {
|
||||
var unique = true;
|
||||
|
||||
@@ -40,6 +40,7 @@ module.exports = function(){
|
||||
case 'getrawtransaction':
|
||||
case 'getsupply':
|
||||
case 'getinfo':
|
||||
case 'getpeerinfo':
|
||||
case 'gettxoutsetinfo':
|
||||
case 'getmaxmoney':
|
||||
case 'getmaxvote':
|
||||
@@ -126,6 +127,7 @@ module.exports = function(){
|
||||
case 'getblockcount':
|
||||
case 'getsupply':
|
||||
case 'getinfo':
|
||||
case 'getpeerinfo':
|
||||
case 'gettxoutsetinfo':
|
||||
case 'getmaxmoney':
|
||||
case 'getmaxvote':
|
||||
|
||||
@@ -194,6 +194,7 @@ exports.api_cmds = {
|
||||
"getblock": "getblock",
|
||||
"getrawtransaction": "getrawtransaction",
|
||||
"getinfo": "getinfo",
|
||||
"getpeerinfo": "getpeerinfo",
|
||||
"gettxoutsetinfo": "gettxoutsetinfo",
|
||||
"getsupply": "getsupply",
|
||||
"getmaxmoney": "getmaxmoney",
|
||||
|
||||
+46
-35
@@ -6,8 +6,7 @@ var mongoose = require('mongoose')
|
||||
, AddressTx = require('../models/addresstx')
|
||||
, Richlist = require('../models/richlist')
|
||||
, Stats = require('../models/stats')
|
||||
, settings = require('../lib/settings')
|
||||
, request = require('postman-request');
|
||||
, settings = require('../lib/settings');
|
||||
|
||||
var mode = 'update';
|
||||
var database = 'index';
|
||||
@@ -185,43 +184,55 @@ if (database == 'peers') {
|
||||
console.log('Aborting');
|
||||
exit();
|
||||
} else {
|
||||
request({uri: 'http://127.0.0.1:' + settings.port + '/api/getpeerinfo', json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
lib.syncLoop(body.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
var address = body[i].addr.substring(0, body[i].addr.lastIndexOf(":")).replace("[","").replace("]","");
|
||||
var port = body[i].addr.substring(body[i].addr.lastIndexOf(":") + 1);
|
||||
var rateLimit = new RateLimit(1, 2000, false);
|
||||
db.find_peer(address, function(peer) {
|
||||
if (peer) {
|
||||
if (isNaN(peer['port']) || peer['port'].length < 2 || peer['country'].length < 1 || peer['country_code'].length < 1) {
|
||||
db.drop_peers(function() {
|
||||
console.log('Saved peers missing ports or country, dropping peers. Re-run this script afterwards.');
|
||||
exit();
|
||||
});
|
||||
}
|
||||
// peer already exists
|
||||
loop.next();
|
||||
} else {
|
||||
rateLimit.schedule(function() {
|
||||
request({uri: 'https://freegeoip.app/json/' + address, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, geo) {
|
||||
db.create_peer({
|
||||
address: address,
|
||||
port: port,
|
||||
protocol: body[i].version,
|
||||
version: body[i].subver.replace('/', '').replace('/', ''),
|
||||
country: geo.country_name,
|
||||
country_code: geo.country_code
|
||||
}, function(){
|
||||
loop.next();
|
||||
lib.get_peerinfo(function (body) {
|
||||
if (body != null) {
|
||||
lib.syncLoop(body.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
var address = body[i].addr.substring(0, body[i].addr.lastIndexOf(":")).replace("[","").replace("]","");
|
||||
var port = body[i].addr.substring(body[i].addr.lastIndexOf(":") + 1);
|
||||
var rateLimit = new RateLimit(1, 2000, false);
|
||||
db.find_peer(address, function(peer) {
|
||||
if (peer) {
|
||||
if (isNaN(peer['port']) || peer['port'].length < 2 || peer['country'].length < 1 || peer['country_code'].length < 1) {
|
||||
db.drop_peers(function() {
|
||||
console.log('Saved peers missing ports or country, dropping peers. Re-run this script afterwards.');
|
||||
exit();
|
||||
});
|
||||
}
|
||||
// peer already exists
|
||||
loop.next();
|
||||
} else {
|
||||
rateLimit.schedule(function() {
|
||||
lib.get_geo_location(address, function (error, geo) {
|
||||
// check if an error was returned
|
||||
if (error) {
|
||||
console.log(error);
|
||||
exit();
|
||||
} else {
|
||||
// add peer to collection
|
||||
db.create_peer({
|
||||
address: address,
|
||||
port: port,
|
||||
protocol: body[i].version,
|
||||
version: body[i].subver.replace('/', '').replace('/', ''),
|
||||
country: geo.country_name,
|
||||
country_code: geo.country_code
|
||||
}, function() {
|
||||
loop.next();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
console.log('peer sync complete');
|
||||
exit();
|
||||
});
|
||||
}, function() {
|
||||
console.log('peer sync complete');
|
||||
} else {
|
||||
console.log('no peers found');
|
||||
exit();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -269,6 +269,7 @@
|
||||
// getblock: Returns an object with information about the block.
|
||||
// getrawtransaction: Returns raw transaction data. Can return a hex-encoded string that is serialized or an object with txid information depending on the decrypt value (0(false) or 1(true))
|
||||
// getinfo: Returns an object containing various state info.
|
||||
// getpeerinfo: Returns data about each connected network node as a json array of objects.
|
||||
// gettxoutsetinfo: Returns an object with statistics about the unspent transaction output set.
|
||||
// getsupply: Returns the current money supply. This should be a positive whole or decimal number.
|
||||
// getmaxmoney: Returns the number of coins that will be produced in total. This should be a positive whole or decimal number.
|
||||
@@ -291,6 +292,7 @@
|
||||
"getblock": "getblock",
|
||||
"getrawtransaction": "getrawtransaction",
|
||||
"getinfo": "getinfo",
|
||||
"getpeerinfo": "getpeerinfo",
|
||||
"gettxoutsetinfo": "gettxoutsetinfo",
|
||||
"getsupply": "getsupply",
|
||||
"getmaxmoney": "getmaxmoney",
|
||||
|
||||
Reference in New Issue
Block a user