aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-02-12 10:01:55 +0000
committerJohn Newbery <john@johnnewbery.com>2021-02-15 16:02:43 +0000
commit1a07600b4b0d08cffc7cd5c58af33fcd1ede558e (patch)
treed709d6d3dd0a8dd792ae78650d498a7f860b8b9e /src/net.cpp
parentf8b3058992b507f3a6aac9d4e2db00102ae1b197 (diff)
downloadbitcoin-1a07600b4b0d08cffc7cd5c58af33fcd1ede558e.tar.xz
[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.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 68388da094..a02b66bd74 100644
--- a/src/net.cpp
+++ b/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);