aboutsummaryrefslogtreecommitdiff
path: root/src/rpcnet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcnet.cpp')
-rw-r--r--src/rpcnet.cpp186
1 files changed, 171 insertions, 15 deletions
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index 5d87a2449..baa3268fb 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -1,9 +1,22 @@
// Copyright (c) 2009-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
+#include "rpcserver.h"
#include "net.h"
-#include "bitcoinrpc.h"
+#include "netbase.h"
+#include "protocol.h"
+#include "sync.h"
+#include "util.h"
+#ifdef ENABLE_WALLET
+#include "wallet.h" // for getinfo
+#include "init.h" // for getinfo
+#endif
+#include "main.h" // for getinfo
+
+#include <inttypes.h>
+
+#include <boost/foreach.hpp>
+#include "json/json_spirit_value.h"
using namespace json_spirit;
using namespace std;
@@ -13,7 +26,13 @@ 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.");
+ "\nReturns the number of connections to other nodes.\n"
+ "\nbResult:\n"
+ "n (numeric) The connection count\n"
+ "\nExamples:\n"
+ + HelpExampleCli("getconnectioncount", "")
+ + HelpExampleRpc("getconnectioncount", "")
+ );
LOCK(cs_vNodes);
return (int)vNodes.size();
@@ -24,9 +43,13 @@ 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"
+ "\nRequests 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.");
+ "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping."
+ "\nExamples:\n"
+ + HelpExampleCli("ping", "")
+ + HelpExampleRpc("ping", "")
+ );
// Request that each node send a ping during next message processing pass
LOCK(cs_vNodes);
@@ -55,7 +78,34 @@ Value getpeerinfo(const Array& params, bool fHelp)
if (fHelp || params.size() != 0)
throw runtime_error(
"getpeerinfo\n"
- "Returns data about each connected network node.");
+ "\nReturns data about each connected network node as a json array of objects.\n"
+ "\nbResult:\n"
+ "[\n"
+ " {\n"
+ " \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
+ " \"addrlocal\":\"ip:port\", (string) local address\n"
+ " \"services\":\"00000001\", (string) The services\n"
+ " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
+ " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
+ " \"bytessent\": n, (numeric) The total bytes sent\n"
+ " \"bytesrecv\": n, (numeric) The total bytes received\n"
+ " \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n"
+ " \"pingtime\": n, (numeric) ping time\n"
+ " \"pingwait\": n, (numeric) ping wait\n"
+ " \"version\": v, (numeric) The peer version, such as 7001\n"
+ " \"subver\": \"/Satoshi:0.8.5/\", (string) The string version\n"
+ " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n"
+ " \"startingheight\": n, (numeric) The starting height (block) of the peer\n"
+ " \"banscore\": n, (numeric) The ban score (stats.nMisbehavior)\n"
+ " \"syncnode\" : true|false (booleamn) if sync node\n"
+ " }\n"
+ " ,...\n"
+ "}\n"
+
+ "\nExamples:\n"
+ + HelpExampleCli("getpeerinfo", "")
+ + HelpExampleRpc("getpeerinfo", "")
+ );
vector<CNodeStats> vstats;
CopyNodeStats(vstats);
@@ -68,7 +118,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("addr", stats.addrName));
if (!(stats.addrLocal.empty()))
obj.push_back(Pair("addrlocal", stats.addrLocal));
- obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices)));
+ obj.push_back(Pair("services", strprintf("%08"PRIx64, 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("bytessent", (boost::int64_t)stats.nSendBytes));
@@ -78,7 +128,10 @@ Value getpeerinfo(const Array& params, bool fHelp)
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));
+ // Use the sanitized form of subver here, to avoid tricksy remote peers from
+ // corrupting or modifiying the JSON output by putting special characters in
+ // their ver message.
+ obj.push_back(Pair("subver", stats.cleanSubVer));
obj.push_back(Pair("inbound", stats.fInbound));
obj.push_back(Pair("startingheight", stats.nStartingHeight));
obj.push_back(Pair("banscore", stats.nMisbehavior));
@@ -99,8 +152,16 @@ Value addnode(const Array& params, bool fHelp)
if (fHelp || params.size() != 2 ||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
throw runtime_error(
- "addnode <node> <add|remove|onetry>\n"
- "Attempts add or remove <node> from the addnode list or try a connection to <node> once.");
+ "addnode \"node\" \"add|remove|onetry\"\n"
+ "\nAttempts add or remove a node from the addnode list.\n"
+ "Or try a connection to a node once.\n"
+ "\nArguments:\n"
+ "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
+ "2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n"
+ "\nExamples:\n"
+ + HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"")
+ + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")
+ );
string strNode = params[0].get_str();
@@ -137,11 +198,34 @@ Value getaddednodeinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
- "getaddednodeinfo <dns> [node]\n"
- "Returns information about the given added node, or all added nodes\n"
+ "getaddednodeinfo dns ( \"node\" )\n"
+ "\nReturns information about the given added node, or all added nodes\n"
"(note that onetry addnodes are not listed here)\n"
"If dns is false, only a list of added nodes will be provided,\n"
- "otherwise connected information will also be available.");
+ "otherwise connected information will also be available.\n"
+ "\nArguments:\n"
+ "1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available.\n"
+ "2. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n"
+ "\nResult:\n"
+ "[\n"
+ " {\n"
+ " \"addednode\" : \"192.168.0.201\", (string) The node ip address\n"
+ " \"connected\" : true|false, (boolean) If connected\n"
+ " \"addresses\" : [\n"
+ " {\n"
+ " \"address\" : \"192.168.0.201:8333\", (string) The bitcoin server host and port\n"
+ " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n"
+ " }\n"
+ " ,...\n"
+ " ]\n"
+ " }\n"
+ " ,...\n"
+ "]\n"
+ "\nExamples:\n"
+ + HelpExampleCli("getaddednodeinfo", "true")
+ + HelpExampleCli("getaddednodeinfo", "true \"192.168.0.201\"")
+ + HelpExampleRpc("getaddednodeinfo", "true, \"192.168.0.201\"")
+ );
bool fDns = params[0].get_bool();
@@ -230,8 +314,18 @@ Value getnettotals(const Array& params, bool fHelp)
if (fHelp || params.size() > 0)
throw runtime_error(
"getnettotals\n"
- "Returns information about network traffic, including bytes in, bytes out,\n"
- "and current time.");
+ "\nReturns information about network traffic, including bytes in, bytes out,\n"
+ "and current time.\n"
+ "\nResult:\n"
+ "{\n"
+ " \"totalbytesrecv\": n, (numeric) Total bytes received\n"
+ " \"totalbytessent\": n, (numeric) Total bytes sent\n"
+ " \"timemillis\": t (numeric) Total cpu time\n"
+ "}\n"
+ "\nExamples:\n"
+ + HelpExampleCli("getnettotals", "")
+ + HelpExampleRpc("getnettotals", "")
+ );
Object obj;
obj.push_back(Pair("totalbytesrecv", static_cast< boost::uint64_t>(CNode::GetTotalBytesRecv())));
@@ -239,3 +333,65 @@ Value getnettotals(const Array& params, bool fHelp)
obj.push_back(Pair("timemillis", static_cast<boost::int64_t>(GetTimeMillis())));
return obj;
}
+
+Value getinfo(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "getinfo\n"
+ "Returns an object containing various state info.\n"
+ "\nResult:\n"
+ "{\n"
+ " \"version\": xxxxx, (numeric) the server version\n"
+ " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
+ " \"walletversion\": xxxxx, (numeric) the wallet version\n"
+ " \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
+ " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
+ " \"timeoffset\": xxxxx, (numeric) the time offset\n"
+ " \"connections\": xxxxx, (numeric) the number of connections\n"
+ " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
+ " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
+ " \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
+ " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
+ " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
+ " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc\n"
+ " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
+ " \"errors\": \"...\" (string) any error messages\n"
+ "}\n"
+ "\nExamples:\n"
+ + HelpExampleCli("getinfo", "")
+ + HelpExampleRpc("getinfo", "")
+ );
+
+ proxyType proxy;
+ GetProxy(NET_IPV4, proxy);
+
+ Object obj;
+ obj.push_back(Pair("version", (int)CLIENT_VERSION));
+ obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
+#ifdef ENABLE_WALLET
+ if (pwalletMain) {
+ obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
+ obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
+ }
+#endif
+ obj.push_back(Pair("blocks", (int)chainActive.Height()));
+ obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
+ obj.push_back(Pair("connections", (int)vNodes.size()));
+ obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
+ obj.push_back(Pair("difficulty", (double)GetDifficulty()));
+ obj.push_back(Pair("testnet", TestNet()));
+#ifdef ENABLE_WALLET
+ if (pwalletMain) {
+ obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
+ obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
+ }
+#endif
+ obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
+#ifdef ENABLE_WALLET
+ if (pwalletMain && pwalletMain->IsCrypted())
+ obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
+#endif
+ obj.push_back(Pair("errors", GetWarnings("statusbar")));
+ return obj;
+}