14 #include <boost/foreach.hpp>
15 #include "json/json_spirit_value.h"
22 if (fHelp || params.size() != 0)
24 "getconnectioncount\n"
25 "\nReturns the number of connections to other nodes.\n"
27 "n (numeric) The connection count\n"
37 Value
ping(
const Array& params,
bool fHelp)
39 if (fHelp || params.size() != 0)
42 "\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
43 "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
44 "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n"
64 vstats.reserve(
vNodes.size());
68 vstats.push_back(stats);
74 if (fHelp || params.size() != 0)
77 "\nReturns data about each connected network node as a json array of objects.\n"
81 " \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
82 " \"addrlocal\":\"ip:port\", (string) local address\n"
83 " \"services\":\"00000001\", (string) The services\n"
84 " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
85 " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
86 " \"bytessent\": n, (numeric) The total bytes sent\n"
87 " \"bytesrecv\": n, (numeric) The total bytes received\n"
88 " \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n"
89 " \"pingtime\": n, (numeric) ping time\n"
90 " \"pingwait\": n, (numeric) ping wait\n"
91 " \"version\": v, (numeric) The peer version, such as 7001\n"
92 " \"subver\": \"/Satoshi:0.8.5/\", (string) The string version\n"
93 " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n"
94 " \"startingheight\": n, (numeric) The starting height (block) of the peer\n"
95 " \"banscore\": n, (numeric) The ban score (stats.nMisbehavior)\n"
96 " \"syncnode\" : true|false (booleamn) if sync node\n"
106 vector<CNodeStats> vstats;
111 BOOST_FOREACH(
const CNodeStats& stats, vstats) {
115 obj.push_back(Pair(
"addr", stats.
addrName));
117 obj.push_back(Pair(
"addrlocal", stats.
addrLocal));
119 obj.push_back(Pair(
"lastsend", stats.
nLastSend));
120 obj.push_back(Pair(
"lastrecv", stats.
nLastRecv));
121 obj.push_back(Pair(
"bytessent", stats.
nSendBytes));
122 obj.push_back(Pair(
"bytesrecv", stats.
nRecvBytes));
124 obj.push_back(Pair(
"pingtime", stats.
dPingTime));
126 obj.push_back(Pair(
"pingwait", stats.
dPingWait));
127 obj.push_back(Pair(
"version", stats.
nVersion));
132 obj.push_back(Pair(
"inbound", stats.
fInbound));
135 obj.push_back(Pair(
"banscore", statestats.
nMisbehavior));
137 obj.push_back(Pair(
"syncnode", stats.
fSyncNode));
145 Value
addnode(
const Array& params,
bool fHelp)
148 if (params.size() == 2)
149 strCommand = params[1].get_str();
150 if (fHelp || params.size() != 2 ||
151 (strCommand !=
"onetry" && strCommand !=
"add" && strCommand !=
"remove"))
153 "addnode \"node\" \"add|remove|onetry\"\n"
154 "\nAttempts add or remove a node from the addnode list.\n"
155 "Or try a connection to a node once.\n"
157 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
158 "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"
164 string strNode = params[0].get_str();
166 if (strCommand ==
"onetry")
179 if (strCommand ==
"add")
185 else if(strCommand ==
"remove")
197 if (fHelp || params.size() < 1 || params.size() > 2)
199 "getaddednodeinfo dns ( \"node\" )\n"
200 "\nReturns information about the given added node, or all added nodes\n"
201 "(note that onetry addnodes are not listed here)\n"
202 "If dns is false, only a list of added nodes will be provided,\n"
203 "otherwise connected information will also be available.\n"
205 "1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available.\n"
206 "2. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n"
210 " \"addednode\" : \"192.168.0.201\", (string) The node ip address\n"
211 " \"connected\" : true|false, (boolean) If connected\n"
212 " \"addresses\" : [\n"
214 " \"address\" : \"192.168.0.201:8333\", (string) The bitcoin server host and port\n"
215 " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n"
228 bool fDns = params[0].get_bool();
230 list<string> laddedNodes(0);
231 if (params.size() == 1)
235 laddedNodes.push_back(strAddNode);
239 string strNode = params[1].get_str();
242 if (strAddNode == strNode)
244 laddedNodes.push_back(strAddNode);
247 if (laddedNodes.size() == 0)
254 BOOST_FOREACH(
string& strAddNode, laddedNodes)
257 obj.push_back(Pair(
"addednode", strAddNode));
263 list<pair<string, vector<CService> > > laddedAddreses(0);
264 BOOST_FOREACH(
string& strAddNode, laddedNodes)
266 vector<CService> vservNode(0);
268 laddedAddreses.push_back(make_pair(strAddNode, vservNode));
272 obj.push_back(Pair(
"addednode", strAddNode));
273 obj.push_back(Pair(
"connected",
false));
275 obj.push_back(Pair(
"addresses", addresses));
280 for (list<pair<
string, vector<CService> > >::iterator it = laddedAddreses.begin(); it != laddedAddreses.end(); it++)
283 obj.push_back(Pair(
"addednode", it->first));
286 bool fConnected =
false;
287 BOOST_FOREACH(
CService& addrNode, it->second)
291 node.push_back(Pair(
"address", addrNode.
ToString()));
293 if (pnode->
addr == addrNode)
297 node.push_back(Pair(
"connected", pnode->
fInbound ?
"inbound" :
"outbound"));
301 node.push_back(Pair(
"connected",
"false"));
302 addresses.push_back(node);
304 obj.push_back(Pair(
"connected", fConnected));
305 obj.push_back(Pair(
"addresses", addresses));
314 if (fHelp || params.size() > 0)
317 "\nReturns information about network traffic, including bytes in, bytes out,\n"
318 "and current time.\n"
321 " \"totalbytesrecv\": n, (numeric) Total bytes received\n"
322 " \"totalbytessent\": n, (numeric) Total bytes sent\n"
323 " \"timemillis\": t (numeric) Total cpu time\n"
339 if (fHelp || params.size() != 0)
342 "Returns an object containing various state info regarding P2P networking.\n"
345 " \"version\": xxxxx, (numeric) the server version\n"
346 " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
347 " \"timeoffset\": xxxxx, (numeric) the time offset\n"
348 " \"connections\": xxxxx, (numeric) the number of connections\n"
349 " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
350 " \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in btc/kb\n"
351 " \"localaddresses\": [, (array) list of local addresses\n"
352 " \"address\": \"xxxx\", (string) network address\n"
353 " \"port\": xxx, (numeric) network port\n"
354 " \"score\": xxx (numeric) relative score\n"
369 obj.push_back(Pair(
"connections", (
int)
vNodes.size()));
370 obj.push_back(Pair(
"proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
372 Array localAddresses;
378 rec.push_back(Pair(
"address", item.first.ToString()));
379 rec.push_back(Pair(
"port", item.second.
nPort));
380 rec.push_back(Pair(
"score", item.second.
nScore));
381 localAddresses.push_back(rec);
384 obj.push_back(Pair(
"localaddresses", localAddresses));
static uint64_t GetTotalBytesRecv()
Value addnode(const Array ¶ms, bool fHelp)
std::string HelpExampleRpc(string methodname, string args)
static const int CLIENT_VERSION
Object JSONRPCError(int code, const string &message)
Value getnetworkinfo(const Array ¶ms, bool fHelp)
vector< std::string > vAddedNodes
Value ValueFromAmount(int64_t amount)
int GetDefaultPort() const
CCriticalSection cs_mapLocalHost
A combination of a network address (CNetAddr) and a (TCP) port.
Value getconnectioncount(const Array ¶ms, bool fHelp)
A CService with information about it as peer.
std::string ToString() const
static uint64_t GetTotalBytesSent()
map< CNetAddr, LocalServiceInfo > mapLocalHost
CNode * ConnectNode(CAddress addrConnect, const char *pszDest)
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
Value getnettotals(const Array ¶ms, bool fHelp)
static void CopyNodeStats(std::vector< CNodeStats > &vstats)
CCriticalSection cs_vAddedNodes
Value getpeerinfo(const Array ¶ms, bool fHelp)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
const CChainParams & Params()
Return the currently selected parameters.
static const int PROTOCOL_VERSION
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
std::pair< CService, int > proxyType
Value getaddednodeinfo(const Array ¶ms, bool fHelp)
static int64_t nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) ...
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
std::string HelpExampleCli(string methodname, string args)
Information about a peer.
Value ping(const Array ¶ms, bool fHelp)
void copyStats(CNodeStats &stats)
CCriticalSection cs_vNodes