diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -1196,6 +1196,12 @@ addrman.m_asmap = std::move(asmap); } + /** + * Return true if the peer has been connected for long enough to do + * inactivity checks. + */ + bool RunInactivityChecks(const CNode &node) const; + private: struct ListenSocket { public: diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -1418,17 +1418,16 @@ } } +bool CConnman::RunInactivityChecks(const CNode &node) const { + return GetSystemTimeInSeconds() > + node.nTimeConnected + m_peer_connect_timeout; +} + bool CConnman::InactivityCheck(const CNode &node) const { // Use non-mockable system time (otherwise these timers will pop when we use // setmocktime in the tests). int64_t now = GetSystemTimeInSeconds(); - if (now <= node.nTimeConnected + m_peer_connect_timeout) { - // Only run inactivity checks if the peer has been connected longer than - // m_peer_connect_timeout. - return false; - } - if (node.nLastRecv == 0 || node.nLastSend == 0) { LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", @@ -1778,7 +1777,7 @@ } } - if (InactivityCheck(*pnode)) { + if (RunInactivityChecks(*pnode) && InactivityCheck(*pnode)) { pnode->fDisconnect = true; } }