Skip to content

Commit 1a07600

Browse files
committed
[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.
1 parent f8b3058 commit 1a07600

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/net.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,18 +1221,17 @@ void CConnman::NotifyNumConnectionsChanged()
12211221
}
12221222
}
12231223

1224+
bool CConnman::RunInactivityChecks(const CNode& node) const
1225+
{
1226+
return GetSystemTimeInSeconds() > node.nTimeConnected + m_peer_connect_timeout;
1227+
}
1228+
12241229
bool CConnman::InactivityCheck(const CNode& node) const
12251230
{
12261231
// Use non-mockable system time (otherwise these timers will pop when we
12271232
// use setmocktime in the tests).
12281233
int64_t now = GetSystemTimeInSeconds();
12291234

1230-
if (now <= node.nTimeConnected + m_peer_connect_timeout) {
1231-
// Only run inactivity checks if the peer has been connected longer
1232-
// than m_peer_connect_timeout.
1233-
return false;
1234-
}
1235-
12361235
if (node.nLastRecv == 0 || node.nLastSend == 0) {
12371236
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());
12381237
return true;
@@ -1537,7 +1536,7 @@ void CConnman::SocketHandler()
15371536
if (bytes_sent) RecordBytesSent(bytes_sent);
15381537
}
15391538

1540-
if (InactivityCheck(*pnode)) pnode->fDisconnect = true;
1539+
if (RunInactivityChecks(*pnode) && InactivityCheck(*pnode)) pnode->fDisconnect = true;
15411540
}
15421541
{
15431542
LOCK(cs_vNodes);

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,9 @@ class CConnman
10221022

10231023
void SetAsmap(std::vector<bool> asmap) { addrman.m_asmap = std::move(asmap); }
10241024

1025+
/** Return true if the peer has been connected for long enough to do inactivity checks. */
1026+
bool RunInactivityChecks(const CNode& node) const;
1027+
10251028
private:
10261029
struct ListenSocket {
10271030
public:

0 commit comments

Comments
 (0)