From 0a872798bc3b56401fab842a48150acaf11eab57 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 4 Oct 2017 21:53:06 +0100 Subject: protocol: kick idle peers by dropping them This is safer, as we don't risk break expectations (eg, requesting block hashes and then receiving a late set of blocks). Dropping a connection means another will be attempted in a fresh state. Also bump the kick timeout to 5 minutes, to ensure we only kick really idle peers. --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 58e5fc380..29fe998ed 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -51,7 +51,7 @@ #define BLOCK_QUEUE_NBLOCKS_THRESHOLD 10 // chunks of N blocks #define BLOCK_QUEUE_SIZE_THRESHOLD (100*1024*1024) // MB #define REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD (5 * 1000000) // microseconds -#define IDLE_PEER_KICK_TIME (45 * 1000000) // microseconds +#define IDLE_PEER_KICK_TIME (600 * 1000000) // microseconds namespace cryptonote { @@ -1181,6 +1181,7 @@ skip: bool t_cryptonote_protocol_handler::kick_idle_peers() { MTRACE("Checking for idle peers..."); + std::vector kick_connections; m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool { if (context.m_state == cryptonote_connection_context::state_synchronizing) @@ -1190,12 +1191,18 @@ skip: if (dt.total_microseconds() > IDLE_PEER_KICK_TIME) { MINFO(context << " kicking idle peer"); - ++context.m_callback_request_count; - m_p2p->request_callback(context); + kick_connections.push_back(context.m_connection_id); } } return true; }); + for (const boost::uuids::uuid &conn_id: kick_connections) + { + m_p2p->for_connection(conn_id, [this](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags) { + drop_connection(context, false, false); + return true; + }); + } return true; } //------------------------------------------------------------------------------------------------------------------------ -- cgit v1.2.3