Merge pull request #5674
fcbf7b3
p2p: propagate out peers limit to payload handler (moneromooo-monero)098aadf
p2p: close the right number of connections on setting max in/out peers (moneromooo-monero)
This commit is contained in:
commit
8a0711f2f2
|
@ -99,6 +99,8 @@ public:
|
||||||
template<class callback_t>
|
template<class callback_t>
|
||||||
bool for_connection(const boost::uuids::uuid &connection_id, const callback_t &cb);
|
bool for_connection(const boost::uuids::uuid &connection_id, const callback_t &cb);
|
||||||
size_t get_connections_count();
|
size_t get_connections_count();
|
||||||
|
size_t get_out_connections_count();
|
||||||
|
size_t get_in_connections_count();
|
||||||
void set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*) = NULL);
|
void set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*) = 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)
|
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<t_connection_context>::get_connections_coun
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
template<class t_connection_context>
|
template<class t_connection_context>
|
||||||
|
size_t async_protocol_handler_config<t_connection_context>::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<class t_connection_context>
|
||||||
|
size_t async_protocol_handler_config<t_connection_context>::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<class t_connection_context>
|
||||||
void async_protocol_handler_config<t_connection_context>::set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*))
|
void async_protocol_handler_config<t_connection_context>::set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*))
|
||||||
{
|
{
|
||||||
if (m_pcommands_handler && m_pcommands_handler_destroy)
|
if (m_pcommands_handler && m_pcommands_handler_destroy)
|
||||||
|
|
|
@ -2432,10 +2432,11 @@ namespace nodetool
|
||||||
auto public_zone = m_network_zones.find(epee::net_utils::zone::public_);
|
auto public_zone = m_network_zones.find(epee::net_utils::zone::public_);
|
||||||
if (public_zone != m_network_zones.end())
|
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;
|
public_zone->second.m_config.m_net_config.max_out_connection_count = count;
|
||||||
if(current > count)
|
if(current > count)
|
||||||
public_zone->second.m_net_server.get_config_object().del_out_connections(current - count);
|
public_zone->second.m_net_server.get_config_object().del_out_connections(current - count);
|
||||||
|
m_payload_handler.set_max_out_peers(count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2454,7 +2455,7 @@ namespace nodetool
|
||||||
auto public_zone = m_network_zones.find(epee::net_utils::zone::public_);
|
auto public_zone = m_network_zones.find(epee::net_utils::zone::public_);
|
||||||
if (public_zone != m_network_zones.end())
|
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;
|
public_zone->second.m_config.m_net_config.max_in_connection_count = count;
|
||||||
if(current > count)
|
if(current > count)
|
||||||
public_zone->second.m_net_server.get_config_object().del_in_connections(current - count);
|
public_zone->second.m_net_server.get_config_object().del_in_connections(current - count);
|
||||||
|
|
Loading…
Reference in New Issue