From fcbf7b3f747b068f993d22ec8deabea643254da3 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 18 Jun 2019 22:27:47 +0000 Subject: [PATCH 1/2] p2p: propagate out peers limit to payload handler --- src/p2p/net_node.inl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index ba29d92c9..5280e777c 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -2213,6 +2213,7 @@ namespace nodetool public_zone->second.m_config.m_net_config.max_out_connection_count = count; if(current > count) public_zone->second.m_net_server.get_config_object().del_out_connections(current - count); + m_payload_handler.set_max_out_peers(count); } } From 098aadf084ad0ab0584e92e8f2bc5667b7cd5c89 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 18 Jun 2019 22:47:05 +0000 Subject: [PATCH 2/2] p2p: close the right number of connections on setting max in/out peers --- .../net/levin_protocol_handler_async.h | 24 +++++++++++++++++++ src/p2p/net_node.inl | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 116b3ace1..8d7ffb2c2 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -99,6 +99,8 @@ public: template bool for_connection(const boost::uuids::uuid &connection_id, const callback_t &cb); size_t get_connections_count(); + size_t get_out_connections_count(); + size_t get_in_connections_count(); void set_handler(levin_commands_handler* handler, void (*destroy)(levin_commands_handler*) = NULL); async_protocol_handler_config():m_pcommands_handler(NULL), m_pcommands_handler_destroy(NULL), m_max_packet_size(LEVIN_DEFAULT_MAX_PACKET_SIZE), m_invoke_timeout(LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED) @@ -882,6 +884,28 @@ size_t async_protocol_handler_config::get_connections_coun } //------------------------------------------------------------------------------------------ template +size_t async_protocol_handler_config::get_out_connections_count() +{ + CRITICAL_REGION_LOCAL(m_connects_lock); + size_t count = 0; + for (const auto &c: m_connects) + if (!c.second->m_connection_context.m_is_income) + ++count; + return count; +} +//------------------------------------------------------------------------------------------ +template +size_t async_protocol_handler_config::get_in_connections_count() +{ + CRITICAL_REGION_LOCAL(m_connects_lock); + size_t count = 0; + for (const auto &c: m_connects) + if (c.second->m_connection_context.m_is_income) + ++count; + return count; +} +//------------------------------------------------------------------------------------------ +template void async_protocol_handler_config::set_handler(levin_commands_handler* handler, void (*destroy)(levin_commands_handler*)) { if (m_pcommands_handler && m_pcommands_handler_destroy) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 5280e777c..9f5f874c2 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -2209,7 +2209,7 @@ namespace nodetool auto public_zone = m_network_zones.find(epee::net_utils::zone::public_); if (public_zone != m_network_zones.end()) { - const auto current = public_zone->second.m_config.m_net_config.max_out_connection_count; + const auto current = public_zone->second.m_net_server.get_config_object().get_out_connections_count(); public_zone->second.m_config.m_net_config.max_out_connection_count = count; if(current > count) public_zone->second.m_net_server.get_config_object().del_out_connections(current - count); @@ -2223,7 +2223,7 @@ namespace nodetool auto public_zone = m_network_zones.find(epee::net_utils::zone::public_); if (public_zone != m_network_zones.end()) { - const auto current = public_zone->second.m_config.m_net_config.max_in_connection_count; + const auto current = public_zone->second.m_net_server.get_config_object().get_in_connections_count(); public_zone->second.m_config.m_net_config.max_in_connection_count = count; if(current > count) public_zone->second.m_net_server.get_config_object().del_in_connections(current - count);