aboutsummaryrefslogtreecommitdiff
path: root/src/rpcnet.cpp
diff options
context:
space:
mode:
authorGavin Andresen <[email protected]>2012-06-29 17:34:02 -0700
committerGavin Andresen <[email protected]>2012-06-29 17:34:02 -0700
commit3a906d45dc4ed9b6ac5f8422c41e07767b557cb6 (patch)
tree2428f40e938a18a376a355fe31722b6ed606ccf0 /src/rpcnet.cpp
parentMerge pull request #1537 from Diapolo/fix_awesome_typo (diff)
parentRPC: add 'getpeerinfo', returning easy-to-retrieve per-CNode data (diff)
downloaddiscoin-3a906d45dc4ed9b6ac5f8422c41e07767b557cb6.tar.xz
discoin-3a906d45dc4ed9b6ac5f8422c41e07767b557cb6.zip
Merge pull request #1531 from jgarzik/peerinfo
RPC: add 'getpeerinfo', returning easy-to-retrieve per-CNode data
Diffstat (limited to 'src/rpcnet.cpp')
-rw-r--r--src/rpcnet.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
new file mode 100644
index 000000000..c5746651c
--- /dev/null
+++ b/src/rpcnet.cpp
@@ -0,0 +1,67 @@
+// Copyright (c) 2009-2012 Bitcoin Developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "net.h"
+#include "bitcoinrpc.h"
+
+using namespace json_spirit;
+using namespace std;
+
+Value getconnectioncount(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "getconnectioncount\n"
+ "Returns the number of connections to other nodes.");
+
+ LOCK(cs_vNodes);
+ return (int)vNodes.size();
+}
+
+static void CopyNodeStats(std::vector<CNodeStats>& vstats)
+{
+ vstats.clear();
+
+ LOCK(cs_vNodes);
+ vstats.reserve(vNodes.size());
+ BOOST_FOREACH(CNode* pnode, vNodes) {
+ CNodeStats stats;
+ pnode->copyStats(stats);
+ vstats.push_back(stats);
+ }
+}
+
+Value getpeerinfo(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "getpeerinfo\n"
+ "Returns data about each connected network node.");
+
+ vector<CNodeStats> vstats;
+ CopyNodeStats(vstats);
+
+ Array ret;
+
+ BOOST_FOREACH(const CNodeStats& stats, vstats) {
+ Object obj;
+
+ obj.push_back(Pair("addr", stats.addrName));
+ obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices)));
+ obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend));
+ obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv));
+ obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected));
+ obj.push_back(Pair("version", stats.nVersion));
+ obj.push_back(Pair("subver", stats.strSubVer));
+ obj.push_back(Pair("inbound", stats.fInbound));
+ obj.push_back(Pair("releasetime", (boost::int64_t)stats.nReleaseTime));
+ obj.push_back(Pair("height", stats.nStartingHeight));
+ obj.push_back(Pair("banscore", stats.nMisbehavior));
+
+ ret.push_back(obj);
+ }
+
+ return ret;
+}
+