Skip to content

Commit

Permalink
Switch anchorlist and whitelist in precendence, fix max out conn
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
who-biz committed Jul 31, 2019
1 parent e1cda4d commit cf98530
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/p2p/net_node.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(local_peers_count -1, 20);
max_random_index = std::min<uint64_t>(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<size_t>() % local_peers_count;
random_index = crypto::rand<size_t>() % (local_peers_count+1);
}

CHECK_AND_ASSERT_MES(random_index < local_peers_count, false, "random_starter_index < peers_local.size() failed!!");
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1670,7 +1670,7 @@ namespace nodetool
bool node_server<t_payload_net_handler>::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;
Expand Down

0 comments on commit cf98530

Please sign in to comment.