Skip to content

Commit

Permalink
Merge pull request iquidus#321 from TheHolyRogerCoin/dev-addpeerinfotab
Browse files Browse the repository at this point in the history
Network: Add tab with information to easily get addnode information for Wallets
  • Loading branch information
uaktags committed Dec 24, 2019
2 parents 6c4b6f8 + cbdb5df commit e52e1b1
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 43 deletions.
22 changes: 22 additions & 0 deletions lib/database.js
Expand Up @@ -744,6 +744,28 @@ module.exports = {
})
},

drop_peer: function(address, cb) {
Peers.deleteOne({address: address}, function(err) {
if (err) {
console.log(err);
return cb();
} else {
return cb ()
}
})
},

drop_peers: function(cb) {
Peers.deleteMany({}, function(err) {
if (err) {
console.log(err);
return cb();
} else {
return cb ()
}
})
},

get_peers: function(cb) {
Peers.find({}, function(err, peers) {
if (err) {
Expand Down
1 change: 1 addition & 0 deletions lib/locale.js
Expand Up @@ -71,6 +71,7 @@ exports.rl_top75 = "Top 51-75",
exports.rl_top100 = "Top 76-100",
exports.rl_hundredplus = "101+",

exports.net_addnodes = "Add Nodes",
exports.net_connections = "Connections",
exports.net_address = "Address",
exports.net_protocol = "Protocol",
Expand Down
1 change: 1 addition & 0 deletions locale/en.json
Expand Up @@ -75,6 +75,7 @@
"rl_top100": "Top 76-100",
"rl_hundredplus": "101+",

"net_addnodes": "Add Nodes",
"net_connections": "Connections",
"net_address": "Address",
"net_protocol": "Protocol",
Expand Down
1 change: 1 addition & 0 deletions models/peers.js
Expand Up @@ -4,6 +4,7 @@ var mongoose = require('mongoose')
var PeersSchema = new Schema({
createdAt: { type: Date, expires: 86400, default: Date.now()},
address: { type: String, default: "" },
port: { type: String, default: "" },
protocol: { type: String, default: "" },
version: { type: String, default: "" },
country: { type: String, default: "" }
Expand Down
10 changes: 9 additions & 1 deletion scripts/peers.js
Expand Up @@ -27,14 +27,22 @@ mongoose.connect(dbString, function(err) {
lib.syncLoop(body.length, function (loop) {
var i = loop.iteration();
var address = body[i].addr.split(':')[0];
var port = body[i].addr.split(':')[1];
db.find_peer(address, function(peer) {
if (peer) {
if (isNaN(peer['port']) || peer['port'].length < 2 || peer['country'].length < 1) {
db.drop_peers(function() {
console.log('Saved peers missing ports or country, dropping peers. Re-reun this script afterwards.');
exit();
});
}
// peer already exists
loop.next();
} else {
request({uri: 'http://freegeoip.net/json/' + address, json: true}, function (error, response, geo) {
request({uri: 'https://freegeoip.app/json/' + address, json: true}, 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
Expand Down
71 changes: 71 additions & 0 deletions views/includes/net_addnodes.jade
@@ -0,0 +1,71 @@
script.
$(document).ready(function(){
var ctable = $('#addnodes-table').dataTable( {
autoWidth: true,
searching: false,
ordering: false,
responsive: true,
lengthChange: true,
processing: true,
ajax: {
url: '/ext/connections',
dataSrc: function ( json ) {
var rows = []
for ( var i=0;i<json.data.length; i++ ) {
rows.push({'nodes':'addnode='+json.data[i]['address']+':'+json.data[i]['port']});
}
return rows;
}
},
columns: [
{ data: 'nodes', width: '100%' }
],
columnDefs: [
{ targets: '_all', className: 'text-left'}
]
});
var ctable = $('#addnodes2-table').dataTable( {
autoWidth: true,
searching: false,
ordering: false,
responsive: true,
lengthChange: true,
processing: true,
ajax: {
url: '/ext/connections',
dataSrc: function ( json ) {
var rows = []
for ( var i=0;i<json.data.length; i++ ) {
rows.push({'nodes':'addnode '+json.data[i]['address']+':'+json.data[i]['port']+' onetry'});
}
return rows;
}
},
columns: [
{ data: 'nodes', width: '100%' }
],
columnDefs: [
{ targets: '_all', className: 'text-left'}
]
});
});
.panel.panel-default
.panel-body
:markdown
If you have trouble syncing your wallet, add these lines to your coin daemon .conf file and restart the wallet.

*Typically you can access the config file through QT-wallet menu, Tools > Open Wallet Configuration File*
table#addnodes-table.table.table-bordered.table-striped
thead
tr
th.text-center AddNode Config Lines
tbody.text-center

.panel-body
:markdown
Alternatively you can try one of these lines in the coin wallet debug window, or add them with *coindaemon*-cli
table#addnodes2-table.table.table-bordered.table-striped
thead
tr
th.text-center OneTry Node Lines
tbody.text-center
40 changes: 40 additions & 0 deletions views/includes/net_list.jade
@@ -0,0 +1,40 @@
script.
$(document).ready(function(){
var ctable = $('#connections-table').dataTable( {
autoWidth: true,
searching: false,
ordering: false,
responsive: true,
lengthChange: true,
processing: true,
ajax: {
url: '/ext/connections',
dataSrc: function ( json ) {
/*for ( var i=0;i<json.data.length; i++ ) {
json.data[i]['timestamp'] = new Date((json.data[i]['timestamp']) * 1000).toUTCString();
json.data[i]['txid'] = "<a href='/tx/" + json.data[i]['txid'] + "'>" + json.data[i]['txid'] + "</a>";
json.data[i]['blockindex'] = "<a href='/block/" + json.data[i]['blockhash'] + "'>" + json.data[i]['blockindex'] + "</a>";
var amount = json.data[i]['total'] / 100000000;
json.data[i]['total'] = amount.toFixed(8);
json.data[i]['recipients'] = json.data[i]['vout'].length;
}*/
return json.data;
}
},
columns: [
{ data: 'address', width: '25%' },
{ data: 'protocol', width: '25%' },
{ data: 'version', width:'25%' },
{ data: 'country', width: '25%'}
]
});
});
.panel.panel-default
table#connections-table.table.table-bordered.table-striped
thead
tr
th.text-center #{settings.locale.net_address}
th.text-center #{settings.locale.net_protocol}
th.text-center #{settings.locale.net_subversion}
th.text-center #{settings.locale.net_country}
tbody.text-center
53 changes: 11 additions & 42 deletions views/network.jade
@@ -1,48 +1,17 @@
extends layout

block content
script.
$(document).ready(function(){
var ctable = $('#connections-table').dataTable( {
autoWidth: true,
searching: false,
ordering: false,
responsive: true,
lengthChange: true,
processing: true,
ajax: {
url: '/ext/connections',
dataSrc: function ( json ) {
/*for ( var i=0;i<json.data.length; i++ ) {
json.data[i]['timestamp'] = new Date((json.data[i]['timestamp']) * 1000).toUTCString();
json.data[i]['txid'] = "<a href='/tx/" + json.data[i]['txid'] + "'>" + json.data[i]['txid'] + "</a>";
json.data[i]['blockindex'] = "<a href='/block/" + json.data[i]['blockhash'] + "'>" + json.data[i]['blockindex'] + "</a>";
var amount = json.data[i]['total'] / 100000000;
json.data[i]['total'] = amount.toFixed(8);
json.data[i]['recipients'] = json.data[i]['vout'].length;
}*/
return json.data;
}
},
columns: [
{ data: 'address', width: '25%' },
{ data: 'protocol', width: '25%' },
{ data: 'version', width:'25%' },
{ data: 'country', width: '25%'}
]
});
});
.col-md-12(style="margin-bottom: 4%")
.row.text-center(style='margin-bottom:15px;')
i #{settings.locale.net_warning}
.panel.panel-default
.panel-heading
strong #{settings.locale.net_connections}
table#connections-table.table.table-bordered.table-striped
thead
tr
th.text-center #{settings.locale.net_address}
th.text-center #{settings.locale.net_protocol}
th.text-center #{settings.locale.net_subversion}
th.text-center #{settings.locale.net_country}
tbody.text-center
.tabpanel
ul.nav.nav-tabs(role='tablist')
li.active(role='presentation')
a(href='#connections', aria-controls='connections', role='tab', data-toggle='tab') #{settings.locale.net_connections}
li(role='presentation')
a(href='#addnodes', aria-controls='addnodes', role='tab', data-toggle='tab') #{settings.locale.net_addnodes}
.tab-content
#connections.tabpanel.tab-pane.active
include ./includes/net_list.jade
#addnodes.tabpanel.tab-pane
include ./includes/net_addnodes.jade

0 comments on commit e52e1b1

Please sign in to comment.