11 #include "validation.h" 30 throw std::runtime_error(
31 "getconnectioncount\n" 32 "\nReturns the number of connections to other nodes.\n" 34 "n (numeric) The connection count\n" 49 throw std::runtime_error(
51 "\nRequests that a ping be sent to all other nodes, to measure ping time.\n" 52 "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" 53 "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n" 95 throw std::runtime_error(
97 "\nReturns data about each connected network node as a json array of objects.\n" 101 " \"id\": n, (numeric) Peer index\n" 102 " \"addr\":\"host:port\", (string) The IP address and port of the peer\n" 103 " \"addrbind\":\"ip:port\", (string) Bind address of the connection to the peer\n" 104 " \"addrlocal\":\"ip:port\", (string) Local address as reported by the peer\n" 105 " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n" 106 " \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n" 107 " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" 108 " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" 109 " \"bytessent\": n, (numeric) The total bytes sent\n" 110 " \"bytesrecv\": n, (numeric) The total bytes received\n" 111 " \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n" 112 " \"timeoffset\": ttt, (numeric) The time offset in seconds\n" 113 " \"pingtime\": n, (numeric) ping time (if available)\n" 114 " \"minping\": n, (numeric) minimum observed ping time (if any at all)\n" 115 " \"pingwait\": n, (numeric) ping wait (if non-zero)\n" 116 " \"version\": v, (numeric) The peer version, such as 7001\n" 117 " \"subver\": \"/Satoshi:0.8.5/\", (string) The string version\n" 118 " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n" 119 " \"addnode\": true|false, (boolean) Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n" 120 " \"startingheight\": n, (numeric) The starting height (block) of the peer\n" 121 " \"banscore\": n, (numeric) The ban score\n" 122 " \"synced_headers\": n, (numeric) The last header we have in common with this peer\n" 123 " \"synced_blocks\": n, (numeric) The last block we have in common with this peer\n" 125 " n, (numeric) The heights of blocks we're currently asking from this peer\n" 128 " \"whitelisted\": true|false, (boolean) Whether the peer is whitelisted\n" 129 " \"bytessent_per_msg\": {\n" 130 " \"addr\": n, (numeric) The total bytes sent aggregated by message type\n" 133 " \"bytesrecv_per_msg\": {\n" 134 " \"addr\": n, (numeric) The total bytes received aggregated by message type\n" 148 std::vector<CNodeStats> vstats;
158 obj.
push_back(Pair(
"addr", stats.addrName));
159 if (!(stats.addrLocal.empty()))
160 obj.
push_back(Pair(
"addrlocal", stats.addrLocal));
161 if (stats.addrBind.IsValid())
162 obj.
push_back(Pair(
"addrbind", stats.addrBind.ToString()));
164 obj.
push_back(Pair(
"relaytxes", stats.fRelayTxes));
165 obj.
push_back(Pair(
"lastsend", stats.nLastSend));
166 obj.
push_back(Pair(
"lastrecv", stats.nLastRecv));
167 obj.
push_back(Pair(
"bytessent", stats.nSendBytes));
168 obj.
push_back(Pair(
"bytesrecv", stats.nRecvBytes));
169 obj.
push_back(Pair(
"conntime", stats.nTimeConnected));
170 obj.
push_back(Pair(
"timeoffset", stats.nTimeOffset));
171 if (stats.dPingTime > 0.0)
172 obj.
push_back(Pair(
"pingtime", stats.dPingTime));
173 if (stats.dMinPing < static_cast<double>(std::numeric_limits<int64_t>::max())/1e6)
174 obj.
push_back(Pair(
"minping", stats.dMinPing));
175 if (stats.dPingWait > 0.0)
176 obj.
push_back(Pair(
"pingwait", stats.dPingWait));
177 obj.
push_back(Pair(
"version", stats.nVersion));
181 obj.
push_back(Pair(
"subver", stats.cleanSubVer));
182 obj.
push_back(Pair(
"inbound", stats.fInbound));
183 obj.
push_back(Pair(
"addnode", stats.m_manual_connection));
184 obj.
push_back(Pair(
"startingheight", stats.nStartingHeight));
193 obj.
push_back(Pair(
"inflight", heights));
195 obj.
push_back(Pair(
"whitelisted", stats.fWhitelisted));
198 for (
const mapMsgCmdSize::value_type &i : stats.mapSendBytesPerMsgCmd) {
200 sendPerMsgCmd.
push_back(Pair(i.first, i.second));
202 obj.
push_back(Pair(
"bytessent_per_msg", sendPerMsgCmd));
205 for (
const mapMsgCmdSize::value_type &i : stats.mapRecvBytesPerMsgCmd) {
207 recvPerMsgCmd.
push_back(Pair(i.first, i.second));
209 obj.
push_back(Pair(
"bytesrecv_per_msg", recvPerMsgCmd));
219 std::string strCommand;
223 (strCommand !=
"onetry" && strCommand !=
"add" && strCommand !=
"remove"))
224 throw std::runtime_error(
225 "addnode \"node\" \"add|remove|onetry\"\n" 226 "\nAttempts to add or remove a node from the addnode list.\n" 227 "Or try a connection to a node once.\n" 228 "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n" 229 "full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n" 231 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n" 232 "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" 243 if (strCommand ==
"onetry")
246 g_connman->OpenNetworkConnection(addr,
false,
nullptr, strNode.c_str(),
false,
false,
true);
250 if (strCommand ==
"add")
255 else if(strCommand ==
"remove")
267 throw std::runtime_error(
268 "disconnectnode \"[address]\" [nodeid]\n" 269 "\nImmediately disconnects from the specified peer node.\n" 270 "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n" 271 "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n" 273 "1. \"address\" (string, optional) The IP address/port of the node\n" 274 "2. \"nodeid\" (number, optional) The node ID (see getpeerinfo for node IDs)\n" 295 success =
g_connman->DisconnectNode(nodeid);
310 throw std::runtime_error(
311 "getaddednodeinfo ( \"node\" )\n" 312 "\nReturns information about the given added node, or all added nodes\n" 313 "(note that onetry addnodes are not listed here)\n" 315 "1. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n" 319 " \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n" 320 " \"connected\" : true|false, (boolean) If connected\n" 321 " \"addresses\" : [ (list of objects) Only when connected = true\n" 323 " \"address\" : \"192.168.0.201:8767\", (string) The raven server IP and port we're connected to\n" 324 " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" 338 std::vector<AddedNodeInfo> vInfo =
g_connman->GetAddedNodeInfo();
344 vInfo.assign(1, info);
358 obj.
push_back(Pair(
"addednode", info.strAddedNode));
359 obj.
push_back(Pair(
"connected", info.fConnected));
361 if (info.fConnected) {
363 address.
push_back(Pair(
"address", info.resolvedAddress.ToString()));
364 address.
push_back(Pair(
"connected", info.fInbound ?
"inbound" :
"outbound"));
367 obj.
push_back(Pair(
"addresses", addresses));
377 throw std::runtime_error(
379 "\nReturns information about network traffic, including bytes in, bytes out,\n" 380 "and current time.\n" 383 " \"totalbytesrecv\": n, (numeric) Total bytes received\n" 384 " \"totalbytessent\": n, (numeric) Total bytes sent\n" 385 " \"timemillis\": t, (numeric) Current UNIX time in milliseconds\n" 386 " \"uploadtarget\":\n" 388 " \"timeframe\": n, (numeric) Length of the measuring timeframe in seconds\n" 389 " \"target\": n, (numeric) Target in bytes\n" 390 " \"target_reached\": true|false, (boolean) True if target is reached\n" 391 " \"serve_historical_blocks\": true|false, (boolean) True if serving historical blocks\n" 392 " \"bytes_left_in_cycle\": t, (numeric) Bytes left in current time cycle\n" 393 " \"time_left_in_cycle\": t (numeric) Seconds left in current time cycle\n" 411 outboundLimit.
push_back(Pair(
"target_reached",
g_connman->OutboundTargetReached(
false)));
412 outboundLimit.
push_back(Pair(
"serve_historical_blocks", !
g_connman->OutboundTargetReached(
true)));
413 outboundLimit.
push_back(Pair(
"bytes_left_in_cycle",
g_connman->GetOutboundTargetBytesLeft()));
414 outboundLimit.
push_back(Pair(
"time_left_in_cycle",
g_connman->GetMaxOutboundTimeLeftInCycle()));
415 obj.
push_back(Pair(
"uploadtarget", outboundLimit));
443 throw std::runtime_error(
445 "Returns an object containing various state info regarding P2P networking.\n" 448 " \"version\": xxxxx, (numeric) the server version\n" 449 " \"subversion\": \"/Satoshi:x.x.x/\", (string) the server subversion string\n" 450 " \"protocolversion\": xxxxx, (numeric) the protocol version\n" 451 " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" 452 " \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n" 453 " \"timeoffset\": xxxxx, (numeric) the time offset\n" 454 " \"connections\": xxxxx, (numeric) the number of connections\n" 455 " \"networkactive\": true|false, (bool) whether p2p networking is enabled\n" 456 " \"networks\": [ (array) information per network\n" 458 " \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n" 459 " \"limited\": true|false, (boolean) is the network limited using -onlynet?\n" 460 " \"reachable\": true|false, (boolean) is the network reachable?\n" 461 " \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n" 462 " \"proxy_randomize_credentials\": true|false, (string) Whether randomized credentials are used\n" 466 " \"relayfee\": x.xxxxxxxx, (numeric) minimum relay fee for transactions in " +
CURRENCY_UNIT +
"/kB\n" 467 " \"incrementalfee\": x.xxxxxxxx, (numeric) minimum fee increment for mempool limiting or BIP 125 replacement in " +
CURRENCY_UNIT +
"/kB\n" 468 " \"localaddresses\": [ (array) list of local addresses\n" 470 " \"address\": \"xxxx\", (string) network address\n" 471 " \"port\": xxx, (numeric) network port\n" 472 " \"score\": xxx (numeric) relative score\n" 476 " \"warnings\": \"...\" (string) any network and blockchain warnings\n" 485 obj.
push_back(Pair(
"version", CLIENT_VERSION));
487 obj.
push_back(Pair(
"protocolversion",PROTOCOL_VERSION));
496 obj.
push_back(Pair(
"networks", GetNetworksInfo()));
502 for (
const std::pair<CNetAddr, LocalServiceInfo> &item :
mapLocalHost)
505 rec.
push_back(Pair(
"address", item.first.ToString()));
506 rec.
push_back(Pair(
"port", item.second.nPort));
507 rec.
push_back(Pair(
"score", item.second.nScore));
511 obj.
push_back(Pair(
"localaddresses", localAddresses));
518 std::string strCommand;
522 (strCommand !=
"add" && strCommand !=
"remove"))
523 throw std::runtime_error(
524 "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" 525 "\nAttempts to add or remove an IP/Subnet from the banned list.\n" 527 "1. \"subnet\" (string, required) The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)\n" 528 "2. \"command\" (string, required) 'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list\n" 529 "3. \"bantime\" (numeric, optional) time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)\n" 530 "4. \"absolute\" (boolean, optional) If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n" 541 bool isSubnet =
false;
543 if (request.
params[0].
get_str().find(
"/") != std::string::npos)
557 if (strCommand ==
"add")
566 bool absolute =
false;
572 else if(strCommand ==
"remove")
583 throw std::runtime_error(
585 "\nList all banned IPs/Subnets.\n" 598 for (banmap_t::iterator it = banMap.begin(); it != banMap.end(); it++)
602 rec.
push_back(Pair(
"address", (*it).first.ToString()));
610 return bannedAddresses;
616 throw std::runtime_error(
618 "\nClear all banned IPs.\n" 634 throw std::runtime_error(
635 "setnetworkactive true|false\n" 636 "\nDisable/enable all p2p network activity.\n" 638 "1. \"state\" (boolean, required) true to enable networking, false to disable\n" 655 {
"network",
"ping", &
ping, {} },
657 {
"network",
"addnode", &
addnode, {
"node",
"command"} },
658 {
"network",
"disconnectnode", &
disconnectnode, {
"address",
"nodeid"} },
662 {
"network",
"setban", &
setban, {
"subnet",
"command",
"bantime",
"absolute"} },
671 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++)
UniValue setban(const JSONRPCRequest &request)
Node has not been added before.
UniValue getnettotals(const JSONRPCRequest &request)
Raven RPC command dispatcher.
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
CCriticalSection cs_main
Global state.
const std::string & get_str() const
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string CURRENCY_UNIT
int64_t get_int64() const
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are: ...
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
UniValue ValueFromAmount(const CAmount &amount, const int8_t units)
UniValue clearbanned(const JSONRPCRequest &request)
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
UniValue getpeerinfo(const JSONRPCRequest &request)
std::string banReasonToString() const
std::map< CSubNet, CBanEntry > banmap_t
bool push_back(const UniValue &val)
bool randomize_credentials
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
CCriticalSection cs_mapLocalHost
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
A CService with information about it as peer.
UniValue listbanned(const JSONRPCRequest &request)
UniValue setnetworkactive(const JSONRPCRequest &request)
UniValue ping(const JSONRPCRequest &request)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue getaddednodeinfo(const JSONRPCRequest &request)
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
bool LookupSubNet(const char *pszName, CSubNet &ret)
UniValue getconnectioncount(const JSONRPCRequest &request)
UniValue disconnectnode(const JSONRPCRequest &request)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
std::atomic< bool > fPingQueued
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
UniValue addnode(const JSONRPCRequest &request)
std::string ToStringIPPort() const
Node to disconnect not found in connected nodes.
std::unique_ptr< CConnman > g_connman
const UniValue NullUniValue
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
UniValue JSONRPCError(int code, const std::string &message)
No valid connection manager instance found.
std::string GetNetworkName(enum Network net)
Information about a peer.
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
std::vector< int > vHeightInFlight
CFeeRate incrementalRelayFee
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
bool IsLimited(enum Network net)
UniValue getnetworkinfo(const JSONRPCRequest &request)