1
0
Fork 0
forked from lthn/blockchain

p2p minor improvements

This commit is contained in:
sowle 2025-07-20 22:54:32 +03:00
parent 32194f88b1
commit 68871b93ec
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 24 additions and 18 deletions

View file

@ -124,7 +124,7 @@ namespace currency
for(auto it = conn_map.rbegin(); it != conn_map.rend(); ++it)
ss << it->second;
LOG_PRINT_L0("Connections (" << incoming_count << " in, " << outgoing_count << " out, " << incoming_count + outgoing_count << " total):" << ENDL << ss.str());
LOG_PRINT_L0("Connections:" << ENDL << ss.str() << ENDL << "(" << incoming_count << " in, " << outgoing_count << " out, " << incoming_count + outgoing_count << " total)");
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>

View file

@ -81,7 +81,7 @@ public:
m_cmd_binder.set_handler("debug_remote_node_mode", boost::bind(&daemon_commands_handler::debug_remote_node_mode, this, ph::_1), "<ip-address> - If node got connected put node into 'debug mode' i.e. no sync process of other communication except ping responses, maintenance secrete key will be requested");
m_cmd_binder.set_handler("full_db_cache_warmup", boost::bind(&daemon_commands_handler::full_db_cache_warmup, this, ph::_1), "(Experimental) Perform full DB loading to RAM cache(make sense only with big numbers passed to --db-cache-l2 option)");
m_cmd_binder.set_handler("print_cache_state", boost::bind(&daemon_commands_handler::print_cache_state, this, ph::_1), "Print db l2 cache state");
m_cmd_binder.set_handler("reload_p2p_manual_config", boost::bind(&daemon_commands_handler::reload_p2p_manual_config, this, ph::_1), "Reload manual p2p config from 'p2p_manual_config.json'");
m_cmd_binder.set_handler("reload_p2p_manual_config", boost::bind(&daemon_commands_handler::reload_p2p_manual_config, this, ph::_1), "Reload manual p2p config from '" P2P_MANUAL_CONFIG_FILENAME "'");
#ifdef _DEBUG
m_cmd_binder.set_handler("debug_set_time_adj", boost::bind(&daemon_commands_handler::debug_set_time_adj, this, ph::_1), "DEBUG: set core time adjustment");
#endif
@ -227,10 +227,10 @@ private:
std::map<uint32_t, time_t> blocklist;
m_srv.get_ip_block_list(blocklist);
std::stringstream ss;
ss << "BLOCKED IPS:" << ENDL;
ss << "AUTO BLOCKED IPs:" << ENDL << "ip block time" << ENDL;
for (const auto& e : blocklist)
{
ss << string_tools::get_ip_string_from_int32(e.first) << ", time: " << std::put_time(std::localtime(&e.second), "%Y-%m-%d %H:%M:%S") << ENDL;
ss << std::left << std::setw(15) << string_tools::get_ip_string_from_int32(e.first) << " " << std::put_time(std::localtime(&e.second), "%Y-%m-%d %H:%M:%S") << ENDL;
}
LOG_PRINT_L0(ss.str());
return true;

View file

@ -224,7 +224,7 @@ namespace nodetool
bool critical_alert_worker();
bool remove_dead_connections();
bool is_ip_good_for_adding_to_peerlist(uint32_t adress);
bool is_ip_in_blacklist(uint32_t adress);
bool is_ip_in_blacklist(uint32_t adress, bool ignore_auto_blocked_list = false);
//debug functions

View file

@ -37,7 +37,7 @@ namespace nodetool
const command_line::arg_descriptor<bool> arg_p2p_hide_my_port ("hide-my-port", "Do not announce yourself as peerlist candidate");
const command_line::arg_descriptor<bool> arg_p2p_offline_mode ( "offline-mode", "Don't connect to any node and reject any connections");
const command_line::arg_descriptor<bool> arg_p2p_disable_debug_reqs ( "disable-debug-p2p-requests", "Disable p2p debug requests");
const command_line::arg_descriptor<uint32_t> arg_p2p_ip_auto_blocking ( "p2p-ip-auto-blocking", "Enable (1) or disable (0) peers auto-blocking by IP <0|1>. Default: 0", 1);
const command_line::arg_descriptor<uint32_t> arg_p2p_ip_auto_blocking ( "p2p-ip-auto-blocking", "Enable (1) or disable (0) peers auto-blocking by IP <0|1>. Default: 1", 1);
const command_line::arg_descriptor<uint32_t> arg_p2p_server_threads ( "p2p-server-threads", "Specify number of p2p server threads. Default: 10", P2P_SERVER_DEFAULT_THREADS_NUM);
}
@ -108,16 +108,20 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::is_remote_ip_allowed(uint32_t addr, bool is_incoming)
{
if (is_incoming && m_p2p_manual_config.incoming_connections_limit && *m_p2p_manual_config.incoming_connections_limit >= get_incoming_connections_count())
return false;
if (m_offline_mode)
return false;
if (!m_ip_auto_blocking_enabled)
return true;
return !is_ip_in_blacklist(addr);
if (is_incoming)
{
if (m_p2p_manual_config.incoming_connections_limit && *m_p2p_manual_config.incoming_connections_limit >= get_incoming_connections_count())
return false;
if (m_use_only_priority_peers)
return false;
}
bool ignore_auto_blocked_list = !m_ip_auto_blocking_enabled;
return !is_ip_in_blacklist(addr, ignore_auto_blocked_list);
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
@ -132,7 +136,7 @@ namespace nodetool
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::is_ip_in_blacklist(uint32_t addr)
bool node_server<t_payload_net_handler>::is_ip_in_blacklist(uint32_t addr, bool ignore_auto_blocked_list /* = false */)
{
CRITICAL_REGION_LOCAL(m_blocked_ips_lock);
@ -140,6 +144,8 @@ namespace nodetool
if (m_permanently_blocked_ips.find(addr) != m_permanently_blocked_ips.end())
return true;
if (ignore_auto_blocked_list)
return false;
//check temporary blocked
auto it = m_blocked_ips.find(addr);
@ -1005,22 +1011,22 @@ namespace nodetool
size_t expected_white_connections = (m_config.m_net_config.connections_count*P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT)/100;
size_t conn_count = get_outgoing_connections_count();
size_t out_conn_count = get_outgoing_connections_count();
bool need_more_connections = false;
if (m_p2p_manual_config.outgoing_connections_limit)
{
// m_p2p_manual_config always override default settings from m_config.m_net_config
need_more_connections = conn_count < *m_p2p_manual_config.outgoing_connections_limit;
need_more_connections = out_conn_count < *m_p2p_manual_config.outgoing_connections_limit;
}
else
{
// use default policy
need_more_connections = conn_count < m_config.m_net_config.connections_count;
need_more_connections = out_conn_count < m_config.m_net_config.connections_count;
}
if(need_more_connections)
{
if(conn_count < expected_white_connections)
if(out_conn_count < expected_white_connections)
{
//start from white list
if(!make_expected_connections_count(true, expected_white_connections))