16 #include <boost/foreach.hpp>
17 #include "json/json_spirit_value.h"
27 if (fHelp || params.size() != 0)
29 "getconnectioncount\n"
30 "\nReturns the number of connections to other nodes.\n"
32 "n (numeric) The connection count\n"
42 Value
ping(
const Array& params,
bool fHelp)
44 if (fHelp || params.size() != 0)
47 "\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
48 "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
49 "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n"
64 static void CopyNodeStats(std::vector<CNodeStats>& vstats)
69 vstats.reserve(
vNodes.size());
73 vstats.push_back(stats);
79 if (fHelp || params.size() != 0)
82 "\nReturns data about each connected network node as a json array of objects.\n"
86 " \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
87 " \"addrlocal\":\"ip:port\", (string) local address\n"
88 " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
89 " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
90 " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
91 " \"bytessent\": n, (numeric) The total bytes sent\n"
92 " \"bytesrecv\": n, (numeric) The total bytes received\n"
93 " \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n"
94 " \"pingtime\": n, (numeric) ping time\n"
95 " \"pingwait\": n, (numeric) ping wait\n"
96 " \"version\": v, (numeric) The peer version, such as 7001\n"
97 " \"subver\": \"/Satoshi:0.8.5/\", (string) The string version\n"
98 " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n"
99 " \"startingheight\": n, (numeric) The starting height (block) of the peer\n"
100 " \"banscore\": n, (numeric) The ban score\n"
101 " \"syncnode\": true|false (boolean) if sync node\n"
111 vector<CNodeStats> vstats;
112 CopyNodeStats(vstats);
116 BOOST_FOREACH(
const CNodeStats& stats, vstats) {
120 obj.push_back(Pair(
"addr", stats.
addrName));
122 obj.push_back(Pair(
"addrlocal", stats.
addrLocal));
124 obj.push_back(Pair(
"lastsend", stats.
nLastSend));
125 obj.push_back(Pair(
"lastrecv", stats.
nLastRecv));
126 obj.push_back(Pair(
"bytessent", stats.
nSendBytes));
127 obj.push_back(Pair(
"bytesrecv", stats.
nRecvBytes));
129 obj.push_back(Pair(
"pingtime", stats.
dPingTime));
131 obj.push_back(Pair(
"pingwait", stats.
dPingWait));
132 obj.push_back(Pair(
"version", stats.
nVersion));
137 obj.push_back(Pair(
"inbound", stats.
fInbound));
140 obj.push_back(Pair(
"banscore", statestats.
nMisbehavior));
142 obj.push_back(Pair(
"syncnode", stats.
fSyncNode));
150 Value
addnode(
const Array& params,
bool fHelp)
153 if (params.size() == 2)
154 strCommand = params[1].get_str();
155 if (fHelp || params.size() != 2 ||
156 (strCommand !=
"onetry" && strCommand !=
"add" && strCommand !=
"remove"))
158 "addnode \"node\" \"add|remove|onetry\"\n"
159 "\nAttempts add or remove a node from the addnode list.\n"
160 "Or try a connection to a node once.\n"
162 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
163 "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"
169 string strNode = params[0].get_str();
171 if (strCommand ==
"onetry")
184 if (strCommand ==
"add")
190 else if(strCommand ==
"remove")
202 if (fHelp || params.size() < 1 || params.size() > 2)
204 "getaddednodeinfo dns ( \"node\" )\n"
205 "\nReturns information about the given added node, or all added nodes\n"
206 "(note that onetry addnodes are not listed here)\n"
207 "If dns is false, only a list of added nodes will be provided,\n"
208 "otherwise connected information will also be available.\n"
210 "1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available.\n"
211 "2. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n"
215 " \"addednode\" : \"192.168.0.201\", (string) The node ip address\n"
216 " \"connected\" : true|false, (boolean) If connected\n"
217 " \"addresses\" : [\n"
219 " \"address\" : \"192.168.0.201:9333\", (string) The anoncoin server host and port\n"
220 " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n"
233 bool fDns = params[0].get_bool();
235 list<string> laddedNodes(0);
236 if (params.size() == 1)
240 laddedNodes.push_back(strAddNode);
244 string strNode = params[1].get_str();
247 if (strAddNode == strNode)
249 laddedNodes.push_back(strAddNode);
252 if (laddedNodes.size() == 0)
259 BOOST_FOREACH(
string& strAddNode, laddedNodes)
262 obj.push_back(Pair(
"addednode", strAddNode));
268 list<pair<string, vector<CService> > > laddedAddreses(0);
269 BOOST_FOREACH(
string& strAddNode, laddedNodes)
271 vector<CService> vservNode(0);
273 laddedAddreses.push_back(make_pair(strAddNode, vservNode));
277 obj.push_back(Pair(
"addednode", strAddNode));
278 obj.push_back(Pair(
"connected",
false));
280 obj.push_back(Pair(
"addresses", addresses));
285 for (list<pair<
string, vector<CService> > >::iterator it = laddedAddreses.begin(); it != laddedAddreses.end(); it++)
288 obj.push_back(Pair(
"addednode", it->first));
291 bool fConnected =
false;
292 BOOST_FOREACH(
CService& addrNode, it->second)
296 node.push_back(Pair(
"address", addrNode.
ToString()));
298 if (pnode->
addr == addrNode)
302 node.push_back(Pair(
"connected", pnode->
fInbound ?
"inbound" :
"outbound"));
306 node.push_back(Pair(
"connected",
"false"));
307 addresses.push_back(node);
309 obj.push_back(Pair(
"connected", fConnected));
310 obj.push_back(Pair(
"addresses", addresses));
319 if (fHelp || params.size() > 0)
322 "\nReturns information about network traffic, including bytes in, bytes out,\n"
323 "and current time.\n"
326 " \"totalbytesrecv\": n, (numeric) Total bytes received\n"
327 " \"totalbytessent\": n, (numeric) Total bytes sent\n"
328 " \"timemillis\": t (numeric) Total cpu time\n"
342 static Array GetNetworksInfo()
354 obj.push_back(Pair(
"limited",
IsLimited(network)));
355 obj.push_back(Pair(
"reachable",
IsReachable(network)));
357 networks.push_back(obj);
364 if (fHelp || params.size() != 0)
367 "Returns an object containing various state info regarding P2P networking.\n"
370 " \"version\": xxxxx, (numeric) the server version\n"
371 " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
372 " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n"
373 " \"timeoffset\": xxxxx, (numeric) the time offset\n"
374 " \"connections\": xxxxx, (numeric) the number of connections\n"
375 " \"networks\": [ (array) information per network\n"
376 " \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n"
377 " \"limited\": xxx, (boolean) is the network limited using -onlynet?\n"
378 " \"reachable\": xxx, (boolean) is the network reachable?\n"
379 " \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n"
382 " \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in btc/kb\n"
383 " \"localaddresses\": [, (array) list of local addresses\n"
384 " \"address\": \"xxxx\", (string) network address\n"
385 " \"port\": xxx, (numeric) network port\n"
386 " \"score\": xxx (numeric) relative score\n"
395 obj.push_back(Pair(
"version", (
int)CLIENT_VERSION));
396 obj.push_back(Pair(
"subversion",
398 obj.push_back(Pair(
"protocolversion",(
int)PROTOCOL_VERSION));
401 obj.push_back(Pair(
"connections", (
int)
vNodes.size()));
402 obj.push_back(Pair(
"networks", GetNetworksInfo()));
404 Array localAddresses;
410 rec.push_back(Pair(
"address", item.first.ToString()));
411 rec.push_back(Pair(
"port", item.second.
nPort));
412 rec.push_back(Pair(
"score", item.second.
nScore));
413 localAddresses.push_back(rec);
416 obj.push_back(Pair(
"localaddresses", localAddresses));
422 if (fHelp || params.size() > 1)
424 "makekeypair [prefix]\n"
425 "Make a public/private key pair.\n"
426 "[prefix] is optional preferred prefix for the public key.\n");
428 string strPrefix =
"";
429 if (params.size() > 0)
430 strPrefix = params[0].get_str();
440 }
while (nCount < 10000 && strPrefix !=
HexStr(pubkey.
begin(), pubkey.
end()).substr(0, strPrefix.size()));
442 if (strPrefix !=
HexStr(pubkey.
begin(), pubkey.
end()).substr(0, strPrefix.size()))
446 result.push_back(Pair(
"PublicKey",
HexStr(pubkey.
begin(), pubkey.
end())));
static uint64_t GetTotalBytesRecv()
Value addnode(const Array ¶ms, bool fHelp)
std::string ToStringIPPort() const
std::string HelpExampleRpc(string methodname, string args)
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
CPubKey GetPubKey() const
A base58-encoded secret key.
CCriticalSection cs_mapLocalHost
A combination of a network address (CNetAddr) and a (TCP) port.
An encapsulated public key.
Value getconnectioncount(const Array ¶ms, bool fHelp)
void MakeNewKey(bool fCompressed)
A CService with information about it as peer.
std::string ToString() const
Value makekeypair(const Array ¶ms, bool fHelp)
const std::string CLIENT_NAME
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)
const unsigned char * begin() const
CCriticalSection cs_vAddedNodes
Value getpeerinfo(const Array ¶ms, bool fHelp)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
const CChainParams & Params()
Return the currently selected parameters.
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
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)
An encapsulated private key.
std::string GetNetworkName(enum Network net)
Information about a peer.
Value ping(const Array ¶ms, bool fHelp)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
void copyStats(CNodeStats &stats)
CCriticalSection cs_vNodes
const unsigned char * end() const
bool IsLimited(enum Network net)