aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <[email protected]>2013-10-15 00:34:20 +0200
committerRoss Nicoll <[email protected]>2015-06-27 13:44:14 +0000
commitd61742461646d7de1269421f9a7ab5f0d58053f4 (patch)
treef9f7061649b7d9073489ace0fd44cd3c2a2f4f30 /src/net.cpp
parentrename fNoListen to fListen and move to net (diff)
downloaddiscoin-d61742461646d7de1269421f9a7ab5f0d58053f4.tar.xz
discoin-d61742461646d7de1269421f9a7ab5f0d58053f4.zip
Ping automatically every 2 minutes (unconditionally)
... instead of after 30 minutes of no sending, for latency measurement and keep-alive. Also, disconnect if no reply arrives within 20 minutes, instead of 90 of inactivity (for peers supporting the 'pong' message).
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/net.cpp b/src/net.cpp
index ad1d105b6..923d948a5 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1011,23 +1011,27 @@ void ThreadSocketHandler()
//
// Inactivity checking
//
- if (pnode->vSendMsg.empty())
- pnode->nLastSendEmpty = GetTime();
- if (GetTime() - pnode->nTimeConnected > 60)
+ int64_t nTime = GetTime();
+ if (nTime - pnode->nTimeConnected > 60)
{
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
{
LogPrint("net", "socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
pnode->fDisconnect = true;
}
- else if (GetTime() - pnode->nLastSend > 90*60 && GetTime() - pnode->nLastSendEmpty > 90*60)
+ else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
{
- LogPrintf("socket not sending\n");
+ LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
pnode->fDisconnect = true;
}
- else if (GetTime() - pnode->nLastRecv > 90*60)
+ else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
{
- LogPrintf("socket inactivity timeout\n");
+ LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
+ pnode->fDisconnect = true;
+ }
+ else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
+ {
+ LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
pnode->fDisconnect = true;
}
}