You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #20927: [refactor] [net] Clean up InactivityCheck()
bf100f8 [net] Cleanup InactivityChecks() and add commenting about time (John Newbery)
06fa85c [net] InactivityCheck() takes a CNode reference (John Newbery)
Pull request description:
This is a pure refactor and should not change any behavior. It clarifies and documents the InactivityCheck() function
This makes #20721 easier to review. In particular, this function uses a mixture of (unmockable) system time and mockable time. It's important to understand where those are being used when reviewing #20721.
#20721 doesn't require this change, so if others don't agree that it's useful and makes review easier, then I'm happy to close this and just do #20721 directly.
ACKs for top commit:
fanquake:
ACK bf100f8
MarcoFalke:
review ACK bf100f8 💫
Tree-SHA512: 7b001de2a5fbe8a6dc37baeae930db5775290afb2e8a6aecdf13161f1e5b06ef813bc6291d8ee5cefcf1e430c955ea702833a8db84192eebe6e6acf0b9304cb2
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)
1223
-
{
1224
-
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
1225
-
{
1226
-
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", m_peer_connect_timeout, pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId());
1247
-
pnode->fDisconnect = true;
1248
-
}
1221
+
// Use non-mockable system time (otherwise these timers will pop when we
1222
+
// use setmocktime in the tests).
1223
+
int64_t now = GetSystemTimeInSeconds();
1224
+
1225
+
if (now <= node.nTimeConnected + m_peer_connect_timeout) {
1226
+
// Only run inactivity checks if the peer has been connected longer
1227
+
// than m_peer_connect_timeout.
1228
+
returnfalse;
1249
1229
}
1230
+
1231
+
if (node.nLastRecv == 0 || node.nLastSend == 0) {
1232
+
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d from %d\n", m_peer_connect_timeout, node.nLastRecv != 0, node.nLastSend != 0, node.GetId());
1233
+
returntrue;
1234
+
}
1235
+
1236
+
if (now > node.nLastSend + TIMEOUT_INTERVAL) {
1237
+
LogPrintf("socket sending timeout: %is\n", now - node.nLastSend);
1238
+
returntrue;
1239
+
}
1240
+
1241
+
if (now > node.nLastRecv + TIMEOUT_INTERVAL) {
1242
+
LogPrintf("socket receive timeout: %is\n", now - node.nLastRecv);
1243
+
returntrue;
1244
+
}
1245
+
1246
+
if (node.nPingNonceSent && node.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL} < GetTime<std::chrono::microseconds>()) {
1247
+
// We use mockable time for ping timeouts. This means that setmocktime
1248
+
// may cause pings to time out for peers that have been connected for
0 commit comments