Skip to content
Permalink
Browse files

Merge pull request #126 from rixombea/master

config for remote node list format
  • Loading branch information...
rixombea committed Apr 5, 2019
2 parents 8fd5bb0 + 151743c commit d8561dce2a0c2c39a0e0378e663a1163427b5d53
Showing with 57 additions and 9 deletions.
  1. +7 −5 main.js
  2. +7 −0 src/js/ws_config.js
  3. +43 −4 src/js/wsui_main.js
12 main.js
@@ -248,15 +248,16 @@ function createWindow() {
}

function storeNodeList(pnodes) {
pnodes = pnodes || settings.get('pubnodes_data');
if(!pnodes) return;

if(!pnodes.length) return;

let validNodes = [];
pnodes.forEach(node => {
let item = `${node.url}:${node.port}`;
validNodes.push(item);
});

if (validNodes.length) settings.set('pubnodes_data', validNodes);
settings.set('pubnodes_data', validNodes);
}

function doNodeListUpdate() {
@@ -272,10 +273,11 @@ function doNodeListUpdate() {
res.on('end', () => {
try {
var pnodes = JSON.parse(result);
if(pnodes.hasOwnProperty('node')) {
pnodes = pnodes.node;
if(pnodes.hasOwnProperty('nodes')) {
pnodes = pnodes.nodes;
}
storeNodeList(pnodes);
if(result.length) settings.set('pubnodes_raw', Buffer.from(result).toString('base64'));
settings.set('pubnodes_last_updated', new Date().getTime());
settings.delete('pubnodes_tested');
log.debug('Public node list has been updated');
@@ -33,9 +33,16 @@ config.blockExplorerUrl = 'https://explorer.turtlecoin.lol/transaction.html?hash
// default remote node to connect to, set this to a known reliable node for 'just works' user experience
config.remoteNodeDefaultHost = 'turtlenode.co';


// remote node list update url, set to null if you don't have one
// for TRTL:
// raw list: https://raw.githubusercontent.com/turtlecoin/turtlecoin-nodes-json/master/turtlecoin-nodes.json
// filtered: https://trtl.nodes.pub/api/getNodes
config.remoteNodeListUpdateUrl = 'https://trtl.nodes.pub/api/getNodes';

// set to false if using raw/unfiltered node list
config.remoteNodeListFiltered = true;

// fallback remote node list, in case fetching update failed, fill this with known to works remote nodes
config.remoteNodeListFallback = [
'turtlenode.co:11898',
@@ -120,7 +120,6 @@ let thtml;
let dmswitch;
let kswitch;
let iswitch;
let pubnodes_fallbacks = [];

function populateElementVars() {
// misc
@@ -497,9 +496,19 @@ function initNodeSelection(nodeAddr) {
offlines = testedNodes.filter((v) => v.label.indexOf(timeoutStr) >= 0);
}

let pubnodes_fallbacks = config.remoteNodeListFallback;
// shuffle nodes
if (onlines.length) {
let rndMethod = wsutil.arrShuffle([0, 1]);
if (pubnodes_fallbacks.length && config.remoteNodeListFiltered) {
let fallbackMerge = [];
pubnodes_fallbacks.forEach(n => {
if(!onlines.find(x => x.host === n)) {
fallbackMerge.push({ host: n, label: `${n}|FREE` });
}
});
onlines = onlines.concat(fallbackMerge);
}
onlines = wsutil.arrShuffle(onlines, rndMethod);
} else {
if (pubnodes_fallbacks.length) {
@@ -2846,6 +2855,32 @@ function initKeyBindings() {
});
}

function fetchFromRaw() {
if(!settings.has('pubnodes_raw')){
setTimeout(() => initNodeSelection, 100);
return;
}

let nodeStr = atob(settings.get('pubnodes_raw', ""));
if(!nodeStr.length) return;
console.debug(nodeStr);

let tested_nodes = [];
let nodes = JSON.parse(nodeStr);

for(const n of nodes) {
let feeLabel = parseInt(n.fee, 10) > 0 ? `Fee: ${wsutil.amountForMortal(n.fee)} ${config.assetTicker}` : "FREE";
tested_nodes.push({
host: `${n.url}:${n.port}`,
label: `${n.url}|${feeLabel}`
});
}

settings.set('pubnodes_tested', tested_nodes);
initNodeSelection();

}

function fetchNodeInfo(force) {
force = force || false;

@@ -2947,10 +2982,14 @@ function fetchNodeInfo(force) {
document.addEventListener('DOMContentLoaded', () => {
initHandlers();
showInitialPage();
if (navigator.onLine) {
fetchNodeInfo();
if (!config.remoteNodeListFiltered) {
if (navigator.onLine) {
fetchNodeInfo();
} else {
setTimeout(() => initNodeSelection, 500);
}
} else {
setTimeout(() => initNodeSelection, 500);
fetchFromRaw();
}
}, false);

0 comments on commit d8561dc

Please sign in to comment.
You can’t perform that action at this time.