From cf98530ff6fd8d70a50586d4dd584ebe85b44682 Mon Sep 17 00:00:00 2001 From: who-biz <37732338+who-biz@users.noreply.github.com> Date: Wed, 31 Jul 2019 18:11:49 -0400 Subject: [PATCH] Switch anchorlist and whitelist in precendence, fix max out conn - Prior to this, anchor peers were being given precendence over whitelist peers. - Additionally, when max out connections were set to -1, it appears that they were being changed to P2P_DEFAULT_MAX_OUT_CONNECTIONS which is defined to have a value of 8. Since these values are already passed in via command line options, this would seem incorrect. - This should also hopefully fix a crash with SIGSEGV that was occurring in p2p scenarios (likely happening when local connections = 0 and then a modulo operation is performed --- src/p2p/net_node.inl | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index af407f4f..74d5d56a 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -987,13 +987,13 @@ namespace nodetool local_peers_count = m_peerlist.get_white_peers_count(); if (!local_peers_count) return false; - max_random_index = std::min(local_peers_count -1, 20); + max_random_index = std::min(local_peers_count, 20); random_index = get_random_index_with_fixed_probability(max_random_index); } else { local_peers_count = m_peerlist.get_gray_peers_count(); if (!local_peers_count) return false; - random_index = crypto::rand() % local_peers_count; + random_index = crypto::rand() % (local_peers_count+1); } CHECK_AND_ASSERT_MES(random_index < local_peers_count, false, "random_starter_index < peers_local.size() failed!!"); @@ -1105,23 +1105,23 @@ namespace nodetool { if(conn_count < expected_white_connections) { - //start from anchor list - if(!make_expected_connections_count(anchor, P2P_DEFAULT_ANCHOR_CONNECTIONS_COUNT)) - return false; - //then do white list + //start from white list if(!make_expected_connections_count(white, expected_white_connections)) return false; + //then do anchor list + if(!make_expected_connections_count(anchor, P2P_DEFAULT_ANCHOR_CONNECTIONS_COUNT)) + return false; //then do grey list if(!make_expected_connections_count(gray, m_config.m_net_config.max_out_connection_count)) return false; }else { - //start from grey list - if(!make_expected_connections_count(gray, m_config.m_net_config.max_out_connection_count)) - return false; - //and then do white list + //start from white list if(!make_expected_connections_count(white, m_config.m_net_config.max_out_connection_count)) return false; + //then do grey list + if(!make_expected_connections_count(gray, m_config.m_net_config.max_out_connection_count)) + return false; } } @@ -1154,11 +1154,11 @@ namespace nodetool if(m_net_server.is_stop_signal_sent()) return false; - if (peer_type == anchor && !make_new_connection_from_anchor_peerlist(apl)) { + if (peer_type == white && !make_new_connection_from_peerlist(true)) { break; } - if (peer_type == white && !make_new_connection_from_peerlist(true)) { + if (peer_type == anchor && !make_new_connection_from_anchor_peerlist(apl)) { break; } @@ -1670,7 +1670,7 @@ namespace nodetool bool node_server::set_max_out_peers(const boost::program_options::variables_map& vm, int64_t max) { if(max == -1) { - m_config.m_net_config.max_out_connection_count = P2P_DEFAULT_CONNECTIONS_COUNT; + m_config.m_net_config.max_out_connection_count = -1; return true; } m_config.m_net_config.max_out_connection_count = max;