aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index e9170d06cd..ae38acdc3c 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -31,6 +31,10 @@
#include <fcntl.h>
#endif
+#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
+#include <ifaddrs.h>
+#endif
+
#ifdef USE_POLL
#include <poll.h>
#endif
@@ -1252,9 +1256,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
@@ -1263,6 +1268,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;
@@ -1559,7 +1566,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);