diff --git a/src/net.cpp b/src/net.cpp index ef1c63044a8..a6e115b247b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2000,16 +2000,15 @@ void CConnman::NotifyNumConnectionsChanged() } } -bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const +bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::chrono::microseconds now) const { return node.m_connected + m_peer_connect_timeout < now; } -bool CConnman::InactivityCheck(const CNode& node) const +bool CConnman::InactivityCheck(const CNode& node, std::chrono::microseconds now) const { // Tests that see disconnects after using mocktime can start nodes with a // large timeout. For example, -peertimeout=999999999. - const auto now{GetTime()}; const auto last_send{node.m_last_send.load()}; const auto last_recv{node.m_last_recv.load()}; @@ -2033,7 +2032,7 @@ bool CConnman::InactivityCheck(const CNode& node) const if (now > last_send + TIMEOUT_INTERVAL) { LogDebug(BCLog::NET, - "socket sending timeout: %is, %s\n", count_seconds(now - last_send), + "socket sending timeout: %is, %s\n", Ticks(now - last_send), node.DisconnectMsg(fLogIPs) ); return true; @@ -2041,7 +2040,7 @@ bool CConnman::InactivityCheck(const CNode& node) const if (now > last_recv + TIMEOUT_INTERVAL) { LogDebug(BCLog::NET, - "socket receive timeout: %is, %s\n", count_seconds(now - last_recv), + "socket receive timeout: %is, %s\n", Ticks(now - last_recv), node.DisconnectMsg(fLogIPs) ); return true; @@ -2123,6 +2122,8 @@ void CConnman::SocketHandlerConnected(const std::vector& nodes, { AssertLockNotHeld(m_total_bytes_sent_mutex); + auto now = GetTime(); + for (CNode* pnode : nodes) { if (m_interrupt_net->interrupted()) { return; @@ -2214,7 +2215,7 @@ void CConnman::SocketHandlerConnected(const std::vector& nodes, } } - if (InactivityCheck(*pnode)) pnode->fDisconnect = true; + if (InactivityCheck(*pnode, now)) pnode->fDisconnect = true; } } diff --git a/src/net.h b/src/net.h index c822afe06d1..387a8c06b82 100644 --- a/src/net.h +++ b/src/net.h @@ -1314,7 +1314,7 @@ public: void WakeMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc); /** Return true if we should disconnect the peer for failing an inactivity check. */ - bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const; + bool ShouldRunInactivityChecks(const CNode& node, std::chrono::microseconds now) const; bool MultipleManualOrFullOutboundConns(Network net) const EXCLUSIVE_LOCKS_REQUIRED(m_nodes_mutex); @@ -1364,7 +1364,7 @@ private: void DisconnectNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_nodes_mutex); void NotifyNumConnectionsChanged(); /** Return true if the peer is inactive and should be disconnected. */ - bool InactivityCheck(const CNode& node) const; + bool InactivityCheck(const CNode& node, std::chrono::microseconds now) const; /** * Generate a collection of sockets to check for IO readiness.