mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
[net] Add RunInactivityChecks()
Moves the logic to prevent running inactivity checks until the peer has been connected for -peertimeout time into its own function. This will be reused by net_processing later.
This commit is contained in:
parent
f8b3058992
commit
1a07600b4b
13
src/net.cpp
13
src/net.cpp
@ -1221,18 +1221,17 @@ void CConnman::NotifyNumConnectionsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
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 peer=%d\n", m_peer_connect_timeout, node.nLastRecv != 0, node.nLastSend != 0, node.GetId());
|
||||
return true;
|
||||
@ -1537,7 +1536,7 @@ void CConnman::SocketHandler()
|
||||
if (bytes_sent) RecordBytesSent(bytes_sent);
|
||||
}
|
||||
|
||||
if (InactivityCheck(*pnode)) pnode->fDisconnect = true;
|
||||
if (RunInactivityChecks(*pnode) && InactivityCheck(*pnode)) pnode->fDisconnect = true;
|
||||
}
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
|
@ -1022,6 +1022,9 @@ public:
|
||||
|
||||
void SetAsmap(std::vector<bool> asmap) { 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:
|
||||
|
Loading…
Reference in New Issue
Block a user