From 7c0dd5e46c528d26987c7eed9e40a1996e4801cf Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 3 Dec 2016 11:20:48 +0000 Subject: [PATCH] net_node: drop connections from banned IPs after looping through connections This keeps the connections lock just for the time of looping and adding connectoins to a list, and the dropping happens after it. This should avoid lengthy delays waiting for the connections lock. --- src/p2p/net_node.inl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index b5bfc297..bf925167 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -203,15 +203,17 @@ namespace nodetool m_blocked_ips[addr] = time(nullptr) + seconds; // drop any connection to that IP - while (!m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) + std::list conns; + m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) { if (cntxt.m_remote_ip == addr) { - drop_connection(cntxt); - return false; + conns.push_back(cntxt.m_connection_id); } return true; - })); + }); + for (const auto &c: conns) + m_net_server.get_config_object().close(c); LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " blocked.", LOG_LEVEL_0); return true;