aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-02-16 15:55:03 +0000
committerJohn Newbery <john@johnnewbery.com>2021-04-01 11:35:27 +0100
commit5ed535a02f8f0a6f65bbe19f48a8c81f43298393 (patch)
tree31e10f4a24bb2efbb1b94abba82bb43c9a37e5e8 /src/net.cpp
parent2b2ab9ab7895cd6356e5dc4db17aa9ce475d495e (diff)
[net] Changes to RunInactivityChecks
- rename to ShouldRunInactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r576394790) - take optional time now (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575895661) - call from within InactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894665) - update comment (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894343) - change ordering of inequality (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r574925129)
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 1dcb141421..c43c53795e 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1255,9 +1255,10 @@ void CConnman::NotifyNumConnectionsChanged()
}
}
-bool CConnman::RunInactivityChecks(const CNode& node) const
+bool CConnman::ShouldRunInactivityChecks(const CNode& node, std::optional<int64_t> now_in) const
{
- return GetSystemTimeInSeconds() > node.nTimeConnected + m_peer_connect_timeout;
+ const int64_t now = now_in ? now_in.value() : GetSystemTimeInSeconds();
+ return node.nTimeConnected + m_peer_connect_timeout < now;
}
bool CConnman::InactivityCheck(const CNode& node) const
@@ -1266,6 +1267,8 @@ bool CConnman::InactivityCheck(const CNode& node) const
// use setmocktime in the tests).
int64_t now = GetSystemTimeInSeconds();
+ if (!ShouldRunInactivityChecks(node, now)) 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;
@@ -1562,7 +1565,7 @@ void CConnman::SocketHandler()
if (bytes_sent) RecordBytesSent(bytes_sent);
}
- if (RunInactivityChecks(*pnode) && InactivityCheck(*pnode)) pnode->fDisconnect = true;
+ if (InactivityCheck(*pnode)) pnode->fDisconnect = true;
}
{
LOCK(cs_vNodes);