MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / InactivityCheck

Method InactivityCheck

src/net.cpp:2034–2085  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2032}
2033
2034bool CConnman::InactivityCheck(const CNode& node, NodeClock::time_point now) const
2035{
2036 // Tests that see disconnects after using mocktime can start nodes with a
2037 // large timeout. For example, -peertimeout=999999999.
2038 const auto last_send{node.m_last_send.load()};
2039 const auto last_recv{node.m_last_recv.load()};
2040
2041 if (!ShouldRunInactivityChecks(node, now)) return false;
2042
2043 bool has_received{last_recv > NodeClock::epoch};
2044 bool has_sent{last_send > NodeClock::epoch};
2045
2046 if (!has_received || !has_sent) {
2047 std::string has_never;
2048 if (!has_received) has_never += ", never received from peer";
2049 if (!has_sent) has_never += ", never sent to peer";
2050 LogDebug(BCLog::NET,
2051 "socket no message in first %i seconds%s, %s",
2052 count_seconds(m_peer_connect_timeout),
2053 has_never,
2054 node.DisconnectMsg()
2055 );
2056 return true;
2057 }
2058
2059 if (now > last_send + TIMEOUT_INTERVAL) {
2060 LogDebug(BCLog::NET,
2061 "socket sending timeout: %is, %s", Ticks<std::chrono::seconds>(now - last_send),
2062 node.DisconnectMsg()
2063 );
2064 return true;
2065 }
2066
2067 if (now > last_recv + TIMEOUT_INTERVAL) {
2068 LogDebug(BCLog::NET,
2069 "socket receive timeout: %is, %s", Ticks<std::chrono::seconds>(now - last_recv),
2070 node.DisconnectMsg()
2071 );
2072 return true;
2073 }
2074
2075 if (!node.fSuccessfullyConnected) {
2076 if (node.m_transport->GetInfo().transport_type == TransportProtocolType::DETECTING) {
2077 LogDebug(BCLog::NET, "V2 handshake timeout, %s", node.DisconnectMsg());
2078 } else {
2079 LogDebug(BCLog::NET, "version handshake timeout, %s", node.DisconnectMsg());
2080 }
2081 return true;
2082 }
2083
2084 return false;
2085}
2086
2087Sock::EventsPerSock CConnman::GenerateWaitSockets(std::span<CNode* const> nodes)
2088{

Callers

nothing calls this directly

Calls 4

count_secondsFunction · 0.85
DisconnectMsgMethod · 0.80
loadMethod · 0.45
GetInfoMethod · 0.45

Tested by

no test coverage detected