From 68871b93ecfc4c2d3395f1691f9c825da749d090 Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 20 Jul 2025 22:54:32 +0300 Subject: [PATCH] p2p minor improvements --- .../currency_protocol_handler.inl | 2 +- src/daemon/daemon_commands_handler.h | 6 ++-- src/p2p/net_node.h | 2 +- src/p2p/net_node.inl | 32 +++++++++++-------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index 9de4ddf8..0d772d45 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -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 diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index c87f92dc..69df1340 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -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), " - 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 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; diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index b4a004ba..e9367faa 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -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 diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 5ba43f4a..89232295 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -37,7 +37,7 @@ namespace nodetool const command_line::arg_descriptor arg_p2p_hide_my_port ("hide-my-port", "Do not announce yourself as peerlist candidate"); const command_line::arg_descriptor arg_p2p_offline_mode ( "offline-mode", "Don't connect to any node and reject any connections"); const command_line::arg_descriptor arg_p2p_disable_debug_reqs ( "disable-debug-p2p-requests", "Disable p2p debug requests"); - const command_line::arg_descriptor 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 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 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 bool node_server::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 @@ -132,7 +136,7 @@ namespace nodetool } //----------------------------------------------------------------------------------- template - bool node_server::is_ip_in_blacklist(uint32_t addr) + bool node_server::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))