aboutsummaryrefslogtreecommitdiff
path: root/src/rpcnet.cpp
diff options
context:
space:
mode:
authorJosh Lehan <krellan@krellan.net>2013-08-22 04:34:33 -0700
committerJosh Lehan <krellan@krellan.net>2013-10-04 01:30:12 -0700
commit971bb3e901aad5d4f04a651e3e2a75161d3a4e2a (patch)
treeb3c28acdf4f64c005c81af7d77416499ab8feeb8 /src/rpcnet.cpp
parentacb3ebc45506701fdb7e060d8b941a5ba6a1b5ac (diff)
downloadbitcoin-971bb3e901aad5d4f04a651e3e2a75161d3a4e2a.tar.xz
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.
Diffstat (limited to 'src/rpcnet.cpp')
-rw-r--r--src/rpcnet.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index bd7bc0ba10..7df86cc2db 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -19,6 +19,24 @@ Value getconnectioncount(const Array& params, bool fHelp)
return (int)vNodes.size();
}
+Value ping(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "ping\n"
+ "Requests that a ping be sent to all other nodes, to measure ping time.\n"
+ "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
+ "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.");
+
+ // Request that each node send a ping during next message processing pass
+ LOCK(cs_vNodes);
+ BOOST_FOREACH(CNode* pNode, vNodes) {
+ pNode->fPingQueued = true;
+ }
+
+ return Value::null;
+}
+
static void CopyNodeStats(std::vector<CNodeStats>& vstats)
{
vstats.clear();
@@ -54,6 +72,9 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes));
obj.push_back(Pair("bytesrecv", (boost::int64_t)stats.nRecvBytes));
obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected));
+ obj.push_back(Pair("pingtime", stats.dPingTime));
+ if (stats.dPingWait > 0.0)
+ obj.push_back(Pair("pingwait", stats.dPingWait));
obj.push_back(Pair("version", stats.nVersion));
obj.push_back(Pair("subver", stats.strSubVer));
obj.push_back(Pair("inbound", stats.fInbound));