From ae252b1ad259f99c9402b757e852859d2829bd20 Mon Sep 17 00:00:00 2001 From: Robert Martin-Legene <robert@nic.ar> Date: Wed, 5 Aug 2020 09:09:14 +0000 Subject: [PATCH] Now properly reuses peers.cache contents --- bin/monitor.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bin/monitor.js b/bin/monitor.js index 95f28aa..303af88 100755 --- a/bin/monitor.js +++ b/bin/monitor.js @@ -156,25 +156,24 @@ function gotAdminPeers( err, nodelist ) // Try to connect to a random node if we have very few peers if ( nowpeers.length < 5 ) { - var candidatenew = []; + var candidate = []; // find candidate nodes which we can connect to // (it comes from peers.cache) peerscache.forEach( function(acachedpeer) { - if ( - // Add "a cached peer" to "candidate new" peers - // if the cached peer is not in the list of current node. - currentnodes.find( function(element) { element.info != acachedpeer } ) - ) + // Add "a cached peer" to "candidate" peers + // if the cached peer is not in the list of currently + // connected nodes. + if ( ! currentnodes.includes( acachedpeer ) ) { - candidatenew.push( acachedpeer ); + candidate.push( acachedpeer ); } } ); - if ( candidatenew.length > 0 ) + if ( candidate.length > 0 ) { - var i = Math.floor( Math.random() * candidatenew.length ); - var enode = candidatenew[i]; + var i = Math.floor( Math.random() * candidate.length ); + var enode = candidate[i]; console.log( "We have " + nowpeers.length @@ -311,6 +310,10 @@ function unlock() function timer() { + if ( bfa.sockettype == 'ipc' && ! bfa.fs.existsSync( bfa.socketurl ) ) + { + return; + } if ( netid == 0 ) { web3.eth.net.getId() -- GitLab