Skip to content

Commit 2af9cff

Browse files
committed
Move InactivityCheck logic to private method.
1 parent 7479b63 commit 2af9cff

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

src/net.cpp

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,39 @@ void CConnman::NotifyNumConnectionsChanged()
12291229
}
12301230
}
12311231

1232+
void CConnman::InactivityCheck(CNode *pnode)
1233+
{
1234+
int64_t nTime = GetSystemTimeInSeconds();
1235+
if (nTime - pnode->nTimeConnected > 60)
1236+
{
1237+
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
1238+
{
1239+
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
1240+
pnode->fDisconnect = true;
1241+
}
1242+
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
1243+
{
1244+
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
1245+
pnode->fDisconnect = true;
1246+
}
1247+
else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
1248+
{
1249+
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
1250+
pnode->fDisconnect = true;
1251+
}
1252+
else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
1253+
{
1254+
LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
1255+
pnode->fDisconnect = true;
1256+
}
1257+
else if (!pnode->fSuccessfullyConnected)
1258+
{
1259+
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId());
1260+
pnode->fDisconnect = true;
1261+
}
1262+
}
1263+
}
1264+
12321265
void CConnman::ThreadSocketHandler()
12331266
{
12341267
while (!interruptNet)
@@ -1425,38 +1458,7 @@ void CConnman::ThreadSocketHandler()
14251458
}
14261459
}
14271460

1428-
//
1429-
// Inactivity checking
1430-
//
1431-
int64_t nTime = GetSystemTimeInSeconds();
1432-
if (nTime - pnode->nTimeConnected > 60)
1433-
{
1434-
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
1435-
{
1436-
LogPrint(BCLog::NET, "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->GetId());
1437-
pnode->fDisconnect = true;
1438-
}
1439-
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
1440-
{
1441-
LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
1442-
pnode->fDisconnect = true;
1443-
}
1444-
else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
1445-
{
1446-
LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
1447-
pnode->fDisconnect = true;
1448-
}
1449-
else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
1450-
{
1451-
LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
1452-
pnode->fDisconnect = true;
1453-
}
1454-
else if (!pnode->fSuccessfullyConnected)
1455-
{
1456-
LogPrint(BCLog::NET, "version handshake timeout from %d\n", pnode->GetId());
1457-
pnode->fDisconnect = true;
1458-
}
1459-
}
1461+
InactivityCheck(pnode);
14601462
}
14611463
{
14621464
LOCK(cs_vNodes);

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class CConnman
338338
void AcceptConnection(const ListenSocket& hListenSocket);
339339
void DisconnectNodes();
340340
void NotifyNumConnectionsChanged();
341+
void InactivityCheck(CNode *pnode);
341342
void ThreadSocketHandler();
342343
void ThreadDNSAddressSeed();
343344

0 commit comments

Comments
 (0)