10 #include <validation.h> 29 throw std::runtime_error(
30 "getconnectioncount\n" 31 "\nReturns the number of connections to other nodes.\n" 33 "n (numeric) The connection count\n" 48 throw std::runtime_error(
50 "\nRequests that a ping be sent to all other nodes, to measure ping time.\n" 51 "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" 52 "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n" 71 throw std::runtime_error(
73 "\nReturns data about each connected network node as a json array of objects.\n" 77 " \"id\": n, (numeric) Peer index\n" 78 " \"addr\":\"host:port\", (string) The IP address and port of the peer\n" 79 " \"addrbind\":\"ip:port\", (string) Bind address of the connection to the peer\n" 80 " \"addrlocal\":\"ip:port\", (string) Local address as reported by the peer\n" 81 " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n" 82 " \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n" 83 " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" 84 " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" 85 " \"bytessent\": n, (numeric) The total bytes sent\n" 86 " \"bytesrecv\": n, (numeric) The total bytes received\n" 87 " \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n" 88 " \"timeoffset\": ttt, (numeric) The time offset in seconds\n" 89 " \"pingtime\": n, (numeric) ping time (if available)\n" 90 " \"minping\": n, (numeric) minimum observed ping time (if any at all)\n" 91 " \"pingwait\": n, (numeric) ping wait (if non-zero)\n" 92 " \"version\": v, (numeric) The peer version, such as 70001\n" 93 " \"subver\": \"/Satoshi:0.8.5/\", (string) The string version\n" 94 " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n" 95 " \"addnode\": true|false, (boolean) Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n" 96 " \"startingheight\": n, (numeric) The starting height (block) of the peer\n" 97 " \"banscore\": n, (numeric) The ban score\n" 98 " \"synced_headers\": n, (numeric) The last header we have in common with this peer\n" 99 " \"synced_blocks\": n, (numeric) The last block we have in common with this peer\n" 101 " n, (numeric) The heights of blocks we're currently asking from this peer\n" 104 " \"whitelisted\": true|false, (boolean) Whether the peer is whitelisted\n" 105 " \"minfeefilter\": n, (numeric) The minimum fee rate for transactions this peer accepts\n" 106 " \"bytessent_per_msg\": {\n" 107 " \"addr\": n, (numeric) The total bytes sent aggregated by message type\n" 110 " \"bytesrecv_per_msg\": {\n" 111 " \"addr\": n, (numeric) The total bytes received aggregated by message type\n" 125 std::vector<CNodeStats> vstats;
134 obj.pushKV(
"id", stats.nodeid);
135 obj.pushKV(
"addr", stats.addrName);
136 if (!(stats.addrLocal.empty()))
137 obj.pushKV(
"addrlocal", stats.addrLocal);
138 if (stats.addrBind.IsValid())
139 obj.pushKV(
"addrbind", stats.addrBind.ToString());
140 obj.pushKV(
"services",
strprintf(
"%016x", stats.nServices));
141 obj.pushKV(
"relaytxes", stats.fRelayTxes);
142 obj.pushKV(
"lastsend", stats.nLastSend);
143 obj.pushKV(
"lastrecv", stats.nLastRecv);
144 obj.pushKV(
"bytessent", stats.nSendBytes);
145 obj.pushKV(
"bytesrecv", stats.nRecvBytes);
146 obj.pushKV(
"conntime", stats.nTimeConnected);
147 obj.pushKV(
"timeoffset", stats.nTimeOffset);
148 if (stats.dPingTime > 0.0)
149 obj.pushKV(
"pingtime", stats.dPingTime);
150 if (stats.dMinPing < static_cast<double>(std::numeric_limits<int64_t>::max())/1e6)
151 obj.pushKV(
"minping", stats.dMinPing);
152 if (stats.dPingWait > 0.0)
153 obj.pushKV(
"pingwait", stats.dPingWait);
154 obj.pushKV(
"version", stats.nVersion);
158 obj.pushKV(
"subver", stats.cleanSubVer);
159 obj.pushKV(
"inbound", stats.fInbound);
160 obj.pushKV(
"addnode", stats.m_manual_connection);
161 obj.pushKV(
"startingheight", stats.nStartingHeight);
164 obj.pushKV(
"synced_headers", statestats.
nSyncHeight);
168 heights.push_back(height);
170 obj.pushKV(
"inflight", heights);
172 obj.pushKV(
"whitelisted", stats.fWhitelisted);
176 for (
const mapMsgCmdSize::value_type &i : stats.mapSendBytesPerMsgCmd) {
178 sendPerMsgCmd.pushKV(i.first, i.second);
180 obj.pushKV(
"bytessent_per_msg", sendPerMsgCmd);
183 for (
const mapMsgCmdSize::value_type &i : stats.mapRecvBytesPerMsgCmd) {
185 recvPerMsgCmd.pushKV(i.first, i.second);
187 obj.pushKV(
"bytesrecv_per_msg", recvPerMsgCmd);
197 std::string strCommand;
201 (strCommand !=
"onetry" && strCommand !=
"add" && strCommand !=
"remove"))
202 throw std::runtime_error(
203 "addnode \"node\" \"add|remove|onetry\"\n" 204 "\nAttempts to add or remove a node from the addnode list.\n" 205 "Or try a connection to a node once.\n" 206 "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n" 207 "full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n" 209 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n" 210 "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" 221 if (strCommand ==
"onetry")
224 g_connman->OpenNetworkConnection(addr,
false,
nullptr, strNode.c_str(),
false,
false,
true);
228 if (strCommand ==
"add")
233 else if(strCommand ==
"remove")
245 throw std::runtime_error(
246 "disconnectnode \"[address]\" [nodeid]\n" 247 "\nImmediately disconnects from the specified peer node.\n" 248 "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n" 249 "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n" 251 "1. \"address\" (string, optional) The IP address/port of the node\n" 252 "2. \"nodeid\" (number, optional) The node ID (see getpeerinfo for node IDs)\n" 273 success =
g_connman->DisconnectNode(nodeid);
288 throw std::runtime_error(
289 "getaddednodeinfo ( \"node\" )\n" 290 "\nReturns information about the given added node, or all added nodes\n" 291 "(note that onetry addnodes are not listed here)\n" 293 "1. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n" 297 " \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n" 298 " \"connected\" : true|false, (boolean) If connected\n" 299 " \"addresses\" : [ (list of objects) Only when connected = true\n" 301 " \"address\" : \"192.168.0.201:8335\", (string) The bitcoin server IP and port we're connected to\n" 302 " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" 316 std::vector<AddedNodeInfo> vInfo =
g_connman->GetAddedNodeInfo();
322 vInfo.assign(1, info);
336 obj.pushKV(
"addednode", info.strAddedNode);
337 obj.pushKV(
"connected", info.fConnected);
339 if (info.fConnected) {
341 address.pushKV(
"address", info.resolvedAddress.ToString());
342 address.pushKV(
"connected", info.fInbound ?
"inbound" :
"outbound");
343 addresses.push_back(address);
345 obj.pushKV(
"addresses", addresses);
355 throw std::runtime_error(
357 "\nReturns information about network traffic, including bytes in, bytes out,\n" 358 "and current time.\n" 361 " \"totalbytesrecv\": n, (numeric) Total bytes received\n" 362 " \"totalbytessent\": n, (numeric) Total bytes sent\n" 363 " \"timemillis\": t, (numeric) Current UNIX time in milliseconds\n" 364 " \"uploadtarget\":\n" 366 " \"timeframe\": n, (numeric) Length of the measuring timeframe in seconds\n" 367 " \"target\": n, (numeric) Target in bytes\n" 368 " \"target_reached\": true|false, (boolean) True if target is reached\n" 369 " \"serve_historical_blocks\": true|false, (boolean) True if serving historical blocks\n" 370 " \"bytes_left_in_cycle\": t, (numeric) Bytes left in current time cycle\n" 371 " \"time_left_in_cycle\": t (numeric) Seconds left in current time cycle\n" 382 obj.pushKV(
"totalbytesrecv",
g_connman->GetTotalBytesRecv());
383 obj.pushKV(
"totalbytessent",
g_connman->GetTotalBytesSent());
387 outboundLimit.pushKV(
"timeframe",
g_connman->GetMaxOutboundTimeframe());
388 outboundLimit.pushKV(
"target",
g_connman->GetMaxOutboundTarget());
389 outboundLimit.pushKV(
"target_reached",
g_connman->OutboundTargetReached(
false));
390 outboundLimit.pushKV(
"serve_historical_blocks", !
g_connman->OutboundTargetReached(
true));
391 outboundLimit.pushKV(
"bytes_left_in_cycle",
g_connman->GetOutboundTargetBytesLeft());
392 outboundLimit.pushKV(
"time_left_in_cycle",
g_connman->GetMaxOutboundTimeLeftInCycle());
393 obj.pushKV(
"uploadtarget", outboundLimit);
409 obj.pushKV(
"limited",
IsLimited(network));
413 networks.push_back(obj);
421 throw std::runtime_error(
423 "Returns an object containing various state info regarding P2P networking.\n" 426 " \"version\": xxxxx, (numeric) the server version\n" 427 " \"subversion\": \"/Satoshi:x.x.x/\", (string) the server subversion string\n" 428 " \"protocolversion\": xxxxx, (numeric) the protocol version\n" 429 " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" 430 " \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n" 431 " \"timeoffset\": xxxxx, (numeric) the time offset\n" 432 " \"connections\": xxxxx, (numeric) the number of connections\n" 433 " \"networkactive\": true|false, (bool) whether p2p networking is enabled\n" 434 " \"networks\": [ (array) information per network\n" 436 " \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n" 437 " \"limited\": true|false, (boolean) is the network limited using -onlynet?\n" 438 " \"reachable\": true|false, (boolean) is the network reachable?\n" 439 " \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n" 440 " \"proxy_randomize_credentials\": true|false, (string) Whether randomized credentials are used\n" 444 " \"relayfee\": x.xxxxxxxx, (numeric) minimum relay fee for transactions in " +
CURRENCY_UNIT +
"/kB\n" 445 " \"incrementalfee\": x.xxxxxxxx, (numeric) minimum fee increment for mempool limiting or BIP 125 replacement in " +
CURRENCY_UNIT +
"/kB\n" 446 " \"localaddresses\": [ (array) list of local addresses\n" 448 " \"address\": \"xxxx\", (string) network address\n" 449 " \"port\": xxx, (numeric) network port\n" 450 " \"score\": xxx (numeric) relative score\n" 454 " \"warnings\": \"...\" (string) any network and blockchain warnings\n" 463 obj.pushKV(
"version", CLIENT_VERSION);
465 obj.pushKV(
"protocolversion",PROTOCOL_VERSION);
471 obj.pushKV(
"networkactive",
g_connman->GetNetworkActive());
474 obj.pushKV(
"networks", GetNetworksInfo());
480 for (
const std::pair<const CNetAddr, LocalServiceInfo> &item :
mapLocalHost)
483 rec.pushKV(
"address", item.first.ToString());
484 rec.pushKV(
"port", item.second.nPort);
485 rec.pushKV(
"score", item.second.nScore);
486 localAddresses.push_back(rec);
489 obj.pushKV(
"localaddresses", localAddresses);
496 std::string strCommand;
500 (strCommand !=
"add" && strCommand !=
"remove"))
501 throw std::runtime_error(
502 "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" 503 "\nAttempts to add or remove an IP/Subnet from the banned list.\n" 505 "1. \"subnet\" (string, required) The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)\n" 506 "2. \"command\" (string, required) 'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list\n" 507 "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" 508 "4. \"absolute\" (boolean, optional) If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n" 519 bool isSubnet =
false;
521 if (request.
params[0].
get_str().find(
'/') != std::string::npos)
535 if (strCommand ==
"add")
544 bool absolute =
false;
550 else if(strCommand ==
"remove")
561 throw std::runtime_error(
563 "\nList all banned IPs/Subnets.\n" 576 for (
const auto& entry : banMap)
578 const CBanEntry& banEntry = entry.second;
580 rec.pushKV(
"address", entry.first.ToString());
581 rec.pushKV(
"banned_until", banEntry.
nBanUntil);
585 bannedAddresses.push_back(rec);
588 return bannedAddresses;
594 throw std::runtime_error(
596 "\nClear all banned IPs.\n" 612 throw std::runtime_error(
613 "setnetworkactive true|false\n" 614 "\nDisable/enable all p2p network activity.\n" 616 "1. \"state\" (boolean, required) true to enable networking, false to disable\n" 632 throw std::runtime_error(
633 "getnodeaddresses ( count )\n" 634 "\nReturn known addresses which can potentially be used to find new nodes in the network\n" 636 "1. \"count\" (numeric, optional) How many addresses to return. Limited to the smaller of " + std::to_string(
ADDRMAN_GETADDR_MAX) +
641 " \"time\": ttt, (numeric) Timestamp in seconds since epoch (Jan 1 1970 GMT) keeping track of when the node was last seen\n" 642 " \"services\": n, (numeric) The services offered\n" 643 " \"address\": \"host\", (string) The address of the node\n" 644 " \"port\": n (numeric) The port of the node\n" 665 std::vector<CAddress> vAddr =
g_connman->GetAddresses();
668 int address_return_count = std::min<int>(count, vAddr.size());
669 for (
int i = 0; i < address_return_count; ++i) {
672 obj.pushKV(
"time", (
int)addr.
nTime);
673 obj.pushKV(
"services", (uint64_t)addr.
nServices);
675 obj.pushKV(
"port", addr.
GetPort());
685 {
"network",
"getconnectioncount", &getconnectioncount, {} },
686 {
"network",
"ping", &ping, {} },
687 {
"network",
"getpeerinfo", &getpeerinfo, {} },
688 {
"network",
"addnode", &addnode, {
"node",
"command"} },
689 {
"network",
"disconnectnode", &disconnectnode, {
"address",
"nodeid"} },
690 {
"network",
"getaddednodeinfo", &getaddednodeinfo, {
"node"} },
691 {
"network",
"getnettotals", &getnettotals, {} },
692 {
"network",
"getnetworkinfo", &getnetworkinfo, {} },
693 {
"network",
"setban", &setban, {
"subnet",
"command",
"bantime",
"absolute"} },
694 {
"network",
"listbanned", &listbanned, {} },
695 {
"network",
"clearbanned", &clearbanned, {} },
696 {
"network",
"setnetworkactive", &setnetworkactive, {
"state"} },
697 {
"network",
"getnodeaddresses", &getnodeaddresses, {
"count"} },
703 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++)
unsigned short GetPort() const
Node has not been added before.
Bitcoin RPC command dispatcher.
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
UniValue ret(UniValue::VARR)
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
UniValue ValueFromAmount(const CAmount &amount)
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.
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
std::string banReasonToString() const
Invalid, missing or duplicate parameter.
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) ...
std::string ToStringIP() const
CCriticalSection cs_mapLocalHost
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
A CService with information about it as peer.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
bool LookupSubNet(const char *pszName, CSubNet &ret)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
#define ADDRMAN_GETADDR_MAX
the maximum number of nodes to return in a getaddr call
std::atomic< bool > fPingQueued
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
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)
#define ADDRMAN_GETADDR_MAX_PCT
the maximum percentage of nodes to return in a getaddr call