Skip to content
Snippets Groups Projects
Commit ae252b1a authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Now properly reuses peers.cache contents

parent 4553ab79
No related branches found
No related tags found
No related merge requests found
...@@ -156,25 +156,24 @@ function gotAdminPeers( err, nodelist ) ...@@ -156,25 +156,24 @@ function gotAdminPeers( err, nodelist )
// Try to connect to a random node if we have very few peers // Try to connect to a random node if we have very few peers
if ( nowpeers.length < 5 ) if ( nowpeers.length < 5 )
{ {
var candidatenew = []; var candidate = [];
// find candidate nodes which we can connect to // find candidate nodes which we can connect to
// (it comes from peers.cache) // (it comes from peers.cache)
peerscache.forEach( peerscache.forEach(
function(acachedpeer) { function(acachedpeer) {
if ( // Add "a cached peer" to "candidate" peers
// Add "a cached peer" to "candidate new" peers // if the cached peer is not in the list of currently
// if the cached peer is not in the list of current node. // connected nodes.
currentnodes.find( function(element) { element.info != acachedpeer } ) 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 i = Math.floor( Math.random() * candidate.length );
var enode = candidatenew[i]; var enode = candidate[i];
console.log( console.log(
"We have " "We have "
+ nowpeers.length + nowpeers.length
...@@ -311,6 +310,10 @@ function unlock() ...@@ -311,6 +310,10 @@ function unlock()
function timer() function timer()
{ {
if ( bfa.sockettype == 'ipc' && ! bfa.fs.existsSync( bfa.socketurl ) )
{
return;
}
if ( netid == 0 ) if ( netid == 0 )
{ {
web3.eth.net.getId() web3.eth.net.getId()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment