aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <[email protected]>2013-10-13 17:37:02 +0200
committerPieter Wuille <[email protected]>2013-10-13 17:41:28 +0200
commit9269d0e96e621a6e02da8074785ac310ce64db73 (patch)
tree9707084615745ee0e8a929b220e3588cdaf47e9b /src/net.cpp
parentMerge pull request #3081 from Diapolo/silence_compiler (diff)
parentAdded ping time measurement. (diff)
downloaddiscoin-9269d0e96e621a6e02da8074785ac310ce64db73.tar.xz
discoin-9269d0e96e621a6e02da8074785ac310ce64db73.zip
Merge pull request #2937
971bb3e Added ping time measurement. New RPC "ping" command to request ping. Implemented "pong" message handler. New "pingtime" field in getpeerinfo, to provide results to user. New "pingwait" field, to show pings still in flight, to better see newly lagging peers. (Josh Lehan)
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 781dbfadc..5afedb1fd 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -620,6 +620,21 @@ void CNode::copyStats(CNodeStats &stats)
X(nSendBytes);
X(nRecvBytes);
stats.fSyncNode = (this == pnodeSync);
+
+ // It is common for nodes with good ping times to suddenly become lagged,
+ // due to a new block arriving or other large transfer.
+ // Merely reporting pingtime might fool the caller into thinking the node was still responsive,
+ // since pingtime does not update until the ping is complete, which might take a while.
+ // So, if a ping is taking an unusually long time in flight,
+ // the caller can immediately detect that this is happening.
+ int64 nPingUsecWait = 0;
+ if ((0 != nPingNonceSent) && (0 != nPingUsecStart)) {
+ nPingUsecWait = GetTimeMicros() - nPingUsecStart;
+ }
+
+ // Raw ping time is in microseconds, but show it to user as whole seconds (Bitcoin users should be well used to small numbers with many decimal places by now :)
+ stats.dPingTime = (((double)nPingUsecTime) / 1e6);
+ stats.dPingWait = (((double)nPingUsecWait) / 1e6);
}
#undef X