Bitcoin ABC  0.26.3
P2P Digital Currency
net.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <rpc/server.h>
6 
7 #include <addrman.h>
8 #include <avalanche/avalanche.h>
9 #include <banman.h>
10 #include <chainparams.h>
11 #include <clientversion.h>
12 #include <config.h>
13 #include <net_permissions.h>
14 #include <net_processing.h>
15 #include <net_types.h> // For banmap_t
16 #include <netbase.h>
17 #include <node/context.h>
18 #include <policy/settings.h>
19 #include <rpc/blockchain.h>
20 #include <rpc/protocol.h>
21 #include <rpc/server_util.h>
22 #include <rpc/util.h>
23 #include <sync.h>
24 #include <timedata.h>
25 #include <util/strencodings.h>
26 #include <util/string.h>
27 #include <util/translation.h>
28 #include <validation.h>
29 #include <version.h>
30 #include <warnings.h>
31 
32 #include <optional>
33 
34 #include <univalue.h>
35 
37  return RPCHelpMan{
38  "getconnectioncount",
39  "Returns the number of connections to other nodes.\n",
40  {},
41  RPCResult{RPCResult::Type::NUM, "", "The connection count"},
42  RPCExamples{HelpExampleCli("getconnectioncount", "") +
43  HelpExampleRpc("getconnectioncount", "")},
44  [&](const RPCHelpMan &self, const Config &config,
45  const JSONRPCRequest &request) -> UniValue {
46  NodeContext &node = EnsureAnyNodeContext(request.context);
47  const CConnman &connman = EnsureConnman(node);
48 
49  return int(connman.GetNodeCount(CConnman::CONNECTIONS_ALL));
50  },
51  };
52 }
53 
54 static RPCHelpMan ping() {
55  return RPCHelpMan{
56  "ping",
57  "Requests that a ping be sent to all other nodes, to measure ping "
58  "time.\n"
59  "Results provided in getpeerinfo, pingtime and pingwait fields are "
60  "decimal seconds.\n"
61  "Ping command is handled in queue with all other commands, so it "
62  "measures processing backlog, not just network ping.\n",
63  {},
65  RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")},
66  [&](const RPCHelpMan &self, const Config &config,
67  const JSONRPCRequest &request) -> UniValue {
68  NodeContext &node = EnsureAnyNodeContext(request.context);
69  PeerManager &peerman = EnsurePeerman(node);
70 
71  // Request that each node send a ping during next message processing
72  // pass
73  peerman.SendPings();
74  return NullUniValue;
75  },
76  };
77 }
78 
80  return RPCHelpMan{
81  "getpeerinfo",
82  "Returns data about each connected network node as a json array of "
83  "objects.\n",
84  {},
85  RPCResult{
87  "",
88  "",
89  {{
91  "",
92  "",
93  {{
94  {RPCResult::Type::NUM, "id", "Peer index"},
95  {RPCResult::Type::STR, "addr",
96  "(host:port) The IP address and port of the peer"},
97  {RPCResult::Type::STR, "addrbind",
98  "(ip:port) Bind address of the connection to the peer"},
99  {RPCResult::Type::STR, "addrlocal",
100  "(ip:port) Local address as reported by the peer"},
101  {RPCResult::Type::BOOL, "addr_relay_enabled",
102  "Whether we participate in address relay with this peer"},
103  {RPCResult::Type::NUM, "addr_processed",
104  "The total number of addresses processed, excluding those "
105  "dropped due to rate limiting"},
106  {RPCResult::Type::NUM, "addr_rate_limited",
107  "The total number of addresses dropped due to rate "
108  "limiting"},
109  {RPCResult::Type::STR, "network",
110  "Network (" +
111  Join(GetNetworkNames(/* append_unroutable */ true),
112  ", ") +
113  ")"},
114  {RPCResult::Type::NUM, "mapped_as",
115  "The AS in the BGP route to the peer used for "
116  "diversifying\n"
117  "peer selection (only available if the asmap config flag "
118  "is set)\n"},
119  {RPCResult::Type::STR_HEX, "services",
120  "The services offered"},
122  "servicesnames",
123  "the services offered, in human-readable form",
124  {{RPCResult::Type::STR, "SERVICE_NAME",
125  "the service name if it is recognised"}}},
126  {RPCResult::Type::BOOL, "relaytxes",
127  "Whether peer has asked us to relay transactions to it"},
128  {RPCResult::Type::NUM_TIME, "lastsend",
129  "The " + UNIX_EPOCH_TIME + " of the last send"},
130  {RPCResult::Type::NUM_TIME, "lastrecv",
131  "The " + UNIX_EPOCH_TIME + " of the last receive"},
132  {RPCResult::Type::NUM_TIME, "last_transaction",
133  "The " + UNIX_EPOCH_TIME +
134  " of the last valid transaction received from this "
135  "peer"},
136  {RPCResult::Type::NUM_TIME, "last_block",
137  "The " + UNIX_EPOCH_TIME +
138  " of the last block received from this peer"},
139  {RPCResult::Type::NUM, "bytessent", "The total bytes sent"},
140  {RPCResult::Type::NUM, "bytesrecv",
141  "The total bytes received"},
142  {RPCResult::Type::NUM_TIME, "conntime",
143  "The " + UNIX_EPOCH_TIME + " of the connection"},
144  {RPCResult::Type::NUM, "timeoffset",
145  "The time offset in seconds"},
146  {RPCResult::Type::NUM, "pingtime",
147  "ping time (if available)"},
148  {RPCResult::Type::NUM, "minping",
149  "minimum observed ping time (if any at all)"},
150  {RPCResult::Type::NUM, "pingwait",
151  "ping wait (if non-zero)"},
152  {RPCResult::Type::NUM, "version",
153  "The peer version, such as 70001"},
154  {RPCResult::Type::STR, "subver", "The string version"},
155  {RPCResult::Type::BOOL, "inbound",
156  "Inbound (true) or Outbound (false)"},
157  {RPCResult::Type::BOOL, "bip152_hb_to",
158  "Whether we selected peer as (compact blocks) "
159  "high-bandwidth peer"},
160  {RPCResult::Type::BOOL, "bip152_hb_from",
161  "Whether peer selected us as (compact blocks) "
162  "high-bandwidth peer"},
163  {RPCResult::Type::STR, "connection_type",
164  "Type of connection: \n" +
165  Join(CONNECTION_TYPE_DOC, ",\n") + "."},
166  {RPCResult::Type::NUM, "startingheight",
167  "The starting height (block) of the peer"},
168  {RPCResult::Type::NUM, "synced_headers",
169  "The last header we have in common with this peer"},
170  {RPCResult::Type::NUM, "synced_blocks",
171  "The last block we have in common with this peer"},
173  "inflight",
174  "",
175  {
176  {RPCResult::Type::NUM, "n",
177  "The heights of blocks we're currently asking from "
178  "this peer"},
179  }},
180  {RPCResult::Type::NUM, "minfeefilter",
181  "The minimum fee rate for transactions this peer accepts"},
183  "bytessent_per_msg",
184  "",
185  {{RPCResult::Type::NUM, "msg",
186  "The total bytes sent aggregated by message type\n"
187  "When a message type is not listed in this json object, "
188  "the bytes sent are 0.\n"
189  "Only known message types can appear as keys in the "
190  "object."}}},
192  "bytesrecv_per_msg",
193  "",
194  {{RPCResult::Type::NUM, "msg",
195  "The total bytes received aggregated by message type\n"
196  "When a message type is not listed in this json object, "
197  "the bytes received are 0.\n"
198  "Only known message types can appear as keys in the "
199  "object and all bytes received\n"
200  "of unknown message types are listed under '" +
201  NET_MESSAGE_COMMAND_OTHER + "'."}}},
202  {RPCResult::Type::NUM, "activity_score",
203  "Avalanche activity score of this node (if any)"},
204  }},
205  }},
206  },
207  RPCExamples{HelpExampleCli("getpeerinfo", "") +
208  HelpExampleRpc("getpeerinfo", "")},
209  [&](const RPCHelpMan &self, const Config &config,
210  const JSONRPCRequest &request) -> UniValue {
211  NodeContext &node = EnsureAnyNodeContext(request.context);
212  const CConnman &connman = EnsureConnman(node);
213  const PeerManager &peerman = EnsurePeerman(node);
214 
215  std::vector<CNodeStats> vstats;
216  connman.GetNodeStats(vstats);
217 
219 
220  for (const CNodeStats &stats : vstats) {
222  CNodeStateStats statestats;
223  bool fStateStats =
224  peerman.GetNodeStateStats(stats.nodeid, statestats);
225  obj.pushKV("id", stats.nodeid);
226  obj.pushKV("addr", stats.m_addr_name);
227  if (stats.addrBind.IsValid()) {
228  obj.pushKV("addrbind", stats.addrBind.ToString());
229  }
230  if (!(stats.addrLocal.empty())) {
231  obj.pushKV("addrlocal", stats.addrLocal);
232  }
233  obj.pushKV("addr_relay_enabled",
234  statestats.m_addr_relay_enabled);
235  obj.pushKV("network", GetNetworkName(stats.m_network));
236  if (stats.m_mapped_as != 0) {
237  obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
238  }
239  obj.pushKV("services", strprintf("%016x", stats.nServices));
240  obj.pushKV("servicesnames", GetServicesNames(stats.nServices));
241  obj.pushKV("relaytxes", stats.fRelayTxes);
242  obj.pushKV("lastsend", count_seconds(stats.m_last_send));
243  obj.pushKV("lastrecv", count_seconds(stats.m_last_recv));
244  obj.pushKV("last_transaction",
245  count_seconds(stats.m_last_tx_time));
246  if (g_avalanche) {
247  obj.pushKV("last_proof",
248  count_seconds(stats.m_last_proof_time));
249  }
250  obj.pushKV("last_block",
251  count_seconds(stats.m_last_block_time));
252  obj.pushKV("bytessent", stats.nSendBytes);
253  obj.pushKV("bytesrecv", stats.nRecvBytes);
254  obj.pushKV("conntime", count_seconds(stats.m_connected));
255  obj.pushKV("timeoffset", stats.nTimeOffset);
256  if (stats.m_last_ping_time > 0us) {
257  obj.pushKV("pingtime",
258  CountSecondsDouble(stats.m_last_ping_time));
259  }
260  if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
261  obj.pushKV("minping",
262  CountSecondsDouble(stats.m_min_ping_time));
263  }
264  if (fStateStats && statestats.m_ping_wait > 0s) {
265  obj.pushKV("pingwait",
266  CountSecondsDouble(statestats.m_ping_wait));
267  }
268  obj.pushKV("version", stats.nVersion);
269  // Use the sanitized form of subver here, to avoid tricksy
270  // remote peers from corrupting or modifying the JSON output by
271  // putting special characters in their ver message.
272  obj.pushKV("subver", stats.cleanSubVer);
273  obj.pushKV("inbound", stats.fInbound);
274  obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to);
275  obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from);
276  if (fStateStats) {
277  obj.pushKV("startingheight", statestats.m_starting_height);
278  obj.pushKV("synced_headers", statestats.nSyncHeight);
279  obj.pushKV("synced_blocks", statestats.nCommonHeight);
280  UniValue heights(UniValue::VARR);
281  for (const int height : statestats.vHeightInFlight) {
282  heights.push_back(height);
283  }
284  obj.pushKV("inflight", heights);
285  obj.pushKV("addr_processed", statestats.m_addr_processed);
286  obj.pushKV("addr_rate_limited",
287  statestats.m_addr_rate_limited);
288  }
289  UniValue permissions(UniValue::VARR);
290  for (const auto &permission :
291  NetPermissions::ToStrings(stats.m_permissionFlags)) {
292  permissions.push_back(permission);
293  }
294  obj.pushKV("permissions", permissions);
295  obj.pushKV("minfeefilter", stats.minFeeFilter);
296 
297  UniValue sendPerMsgCmd(UniValue::VOBJ);
298  for (const auto &i : stats.mapSendBytesPerMsgCmd) {
299  if (i.second > 0) {
300  sendPerMsgCmd.pushKV(i.first, i.second);
301  }
302  }
303  obj.pushKV("bytessent_per_msg", sendPerMsgCmd);
304 
305  UniValue recvPerMsgCmd(UniValue::VOBJ);
306  for (const auto &i : stats.mapRecvBytesPerMsgCmd) {
307  if (i.second > 0) {
308  recvPerMsgCmd.pushKV(i.first, i.second);
309  }
310  }
311  obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
312  obj.pushKV("connection_type", stats.m_conn_type_string);
313 
314  if (stats.m_availabilityScore) {
315  obj.pushKV("availability_score",
316  *stats.m_availabilityScore);
317  }
318 
319  ret.push_back(obj);
320  }
321 
322  return ret;
323  },
324  };
325 }
326 
327 static RPCHelpMan addnode() {
328  return RPCHelpMan{
329  "addnode",
330  "Attempts to add or remove a node from the addnode list.\n"
331  "Or try a connection to a node once.\n"
332  "Nodes added using addnode (or -connect) are protected from "
333  "DoS disconnection and are not required to be\n"
334  "full nodes as other outbound peers are (though such peers "
335  "will not be synced from).\n",
336  {
338  "The node (see getpeerinfo for nodes)"},
340  "'add' to add a node to the list, 'remove' to remove a "
341  "node from the list, 'onetry' to try a connection to the "
342  "node once"},
343  },
345  RPCExamples{
346  HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") +
347  HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")},
348  [&](const RPCHelpMan &self, const Config &config,
349  const JSONRPCRequest &request) -> UniValue {
350  std::string strCommand;
351  if (!request.params[1].isNull()) {
352  strCommand = request.params[1].get_str();
353  }
354 
355  if (strCommand != "onetry" && strCommand != "add" &&
356  strCommand != "remove") {
357  throw std::runtime_error(self.ToString());
358  }
359 
360  NodeContext &node = EnsureAnyNodeContext(request.context);
361  CConnman &connman = EnsureConnman(node);
362 
363  std::string strNode = request.params[0].get_str();
364 
365  if (strCommand == "onetry") {
366  CAddress addr;
367  connman.OpenNetworkConnection(addr, false, nullptr,
368  strNode.c_str(),
370  return NullUniValue;
371  }
372 
373  if ((strCommand == "add") && (!connman.AddNode(strNode))) {
375  "Error: Node already added");
376  } else if ((strCommand == "remove") &&
377  (!connman.RemoveAddedNode(strNode))) {
378  throw JSONRPCError(
380  "Error: Node could not be removed. It has not been "
381  "added previously.");
382  }
383 
384  return NullUniValue;
385  },
386  };
387 }
388 
390  return RPCHelpMan{
391  "addconnection",
392  "\nOpen an outbound connection to a specified node. This RPC is for "
393  "testing only.\n",
394  {
396  "The IP address and port to attempt connecting to."},
397  {"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO,
398  "Type of connection to open (\"outbound-full-relay\", "
399  "\"block-relay-only\", \"addr-fetch\", \"feeler\" or "
400  "\"avalanche\")."},
401  },
403  "",
404  "",
405  {
406  {RPCResult::Type::STR, "address",
407  "Address of newly added connection."},
408  {RPCResult::Type::STR, "connection_type",
409  "Type of connection opened."},
410  }},
411  RPCExamples{
412  HelpExampleCli("addconnection",
413  "\"192.168.0.6:8333\" \"outbound-full-relay\"") +
414  HelpExampleRpc("addconnection",
415  "\"192.168.0.6:8333\" \"outbound-full-relay\"")},
416  [&](const RPCHelpMan &self, const Config &config,
417  const JSONRPCRequest &request) -> UniValue {
418  if (config.GetChainParams().NetworkIDString() !=
420  throw std::runtime_error("addconnection is for regression "
421  "testing (-regtest mode) only.");
422  }
423 
424  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR});
425  const std::string address = request.params[0].get_str();
426  const std::string conn_type_in{
427  TrimString(request.params[1].get_str())};
428  ConnectionType conn_type{};
429  if (conn_type_in == "outbound-full-relay") {
431  } else if (conn_type_in == "block-relay-only") {
432  conn_type = ConnectionType::BLOCK_RELAY;
433  } else if (conn_type_in == "addr-fetch") {
434  conn_type = ConnectionType::ADDR_FETCH;
435  } else if (conn_type_in == "feeler") {
436  conn_type = ConnectionType::FEELER;
437  } else if (conn_type_in == "avalanche") {
440  "Error: avalanche outbound requested "
441  "but avalanche is not enabled.");
442  }
444  } else {
446  }
447 
448  NodeContext &node = EnsureAnyNodeContext(request.context);
449  CConnman &connman = EnsureConnman(node);
450 
451  const bool success = connman.AddConnection(address, conn_type);
452  if (!success) {
454  "Error: Already at capacity for specified "
455  "connection type.");
456  }
457 
458  UniValue info(UniValue::VOBJ);
459  info.pushKV("address", address);
460  info.pushKV("connection_type", conn_type_in);
461 
462  return info;
463  },
464  };
465 }
466 
468  return RPCHelpMan{
469  "disconnectnode",
470  "Immediately disconnects from the specified peer node.\n"
471  "\nStrictly one out of 'address' and 'nodeid' can be provided to "
472  "identify the node.\n"
473  "\nTo disconnect by nodeid, either set 'address' to the empty string, "
474  "or call using the named 'nodeid' argument only.\n",
475  {
476  {"address", RPCArg::Type::STR,
477  /* default */ "fallback to nodeid",
478  "The IP address/port of the node"},
479  {"nodeid", RPCArg::Type::NUM,
480  /* default */ "fallback to address",
481  "The node ID (see getpeerinfo for node IDs)"},
482  },
484  RPCExamples{HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") +
485  HelpExampleCli("disconnectnode", "\"\" 1") +
486  HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") +
487  HelpExampleRpc("disconnectnode", "\"\", 1")},
488  [&](const RPCHelpMan &self, const Config &config,
489  const JSONRPCRequest &request) -> UniValue {
490  NodeContext &node = EnsureAnyNodeContext(request.context);
491  CConnman &connman = EnsureConnman(node);
492 
493  bool success;
494  const UniValue &address_arg = request.params[0];
495  const UniValue &id_arg = request.params[1];
496 
497  if (!address_arg.isNull() && id_arg.isNull()) {
498  /* handle disconnect-by-address */
499  success = connman.DisconnectNode(address_arg.get_str());
500  } else if (!id_arg.isNull() && (address_arg.isNull() ||
501  (address_arg.isStr() &&
502  address_arg.get_str().empty()))) {
503  /* handle disconnect-by-id */
504  NodeId nodeid = (NodeId)id_arg.get_int64();
505  success = connman.DisconnectNode(nodeid);
506  } else {
507  throw JSONRPCError(
509  "Only one of address and nodeid should be provided.");
510  }
511 
512  if (!success) {
514  "Node not found in connected nodes");
515  }
516 
517  return NullUniValue;
518  },
519  };
520 }
521 
523  return RPCHelpMan{
524  "getaddednodeinfo",
525  "Returns information about the given added node, or all added nodes\n"
526  "(note that onetry addnodes are not listed here)\n",
527  {
528  {"node", RPCArg::Type::STR, /* default */ "all nodes",
529  "If provided, return information about this specific node, "
530  "otherwise all nodes are returned."},
531  },
532  RPCResult{
534  "",
535  "",
536  {
538  "",
539  "",
540  {
541  {RPCResult::Type::STR, "addednode",
542  "The node IP address or name (as provided to addnode)"},
543  {RPCResult::Type::BOOL, "connected", "If connected"},
545  "addresses",
546  "Only when connected = true",
547  {
549  "",
550  "",
551  {
552  {RPCResult::Type::STR, "address",
553  "The bitcoin server IP and port we're "
554  "connected to"},
555  {RPCResult::Type::STR, "connected",
556  "connection, inbound or outbound"},
557  }},
558  }},
559  }},
560  }},
561  RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") +
562  HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")},
563  [&](const RPCHelpMan &self, const Config &config,
564  const JSONRPCRequest &request) -> UniValue {
565  NodeContext &node = EnsureAnyNodeContext(request.context);
566  const CConnman &connman = EnsureConnman(node);
567 
568  std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo();
569 
570  if (!request.params[0].isNull()) {
571  bool found = false;
572  for (const AddedNodeInfo &info : vInfo) {
573  if (info.strAddedNode == request.params[0].get_str()) {
574  vInfo.assign(1, info);
575  found = true;
576  break;
577  }
578  }
579  if (!found) {
581  "Error: Node has not been added.");
582  }
583  }
584 
586 
587  for (const AddedNodeInfo &info : vInfo) {
589  obj.pushKV("addednode", info.strAddedNode);
590  obj.pushKV("connected", info.fConnected);
591  UniValue addresses(UniValue::VARR);
592  if (info.fConnected) {
593  UniValue address(UniValue::VOBJ);
594  address.pushKV("address", info.resolvedAddress.ToString());
595  address.pushKV("connected",
596  info.fInbound ? "inbound" : "outbound");
597  addresses.push_back(address);
598  }
599  obj.pushKV("addresses", addresses);
600  ret.push_back(obj);
601  }
602 
603  return ret;
604  },
605  };
606 }
607 
609  return RPCHelpMan{
610  "getnettotals",
611  "Returns information about network traffic, including bytes in, "
612  "bytes out,\n"
613  "and current time.\n",
614  {},
615  RPCResult{
617  "",
618  "",
619  {
620  {RPCResult::Type::NUM, "totalbytesrecv",
621  "Total bytes received"},
622  {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"},
623  {RPCResult::Type::NUM_TIME, "timemillis",
624  "Current " + UNIX_EPOCH_TIME + " in milliseconds"},
626  "uploadtarget",
627  "",
628  {
629  {RPCResult::Type::NUM, "timeframe",
630  "Length of the measuring timeframe in seconds"},
631  {RPCResult::Type::NUM, "target", "Target in bytes"},
632  {RPCResult::Type::BOOL, "target_reached",
633  "True if target is reached"},
634  {RPCResult::Type::BOOL, "serve_historical_blocks",
635  "True if serving historical blocks"},
636  {RPCResult::Type::NUM, "bytes_left_in_cycle",
637  "Bytes left in current time cycle"},
638  {RPCResult::Type::NUM, "time_left_in_cycle",
639  "Seconds left in current time cycle"},
640  }},
641  }},
642  RPCExamples{HelpExampleCli("getnettotals", "") +
643  HelpExampleRpc("getnettotals", "")},
644  [&](const RPCHelpMan &self, const Config &config,
645  const JSONRPCRequest &request) -> UniValue {
646  NodeContext &node = EnsureAnyNodeContext(request.context);
647  const CConnman &connman = EnsureConnman(node);
648 
650  obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv());
651  obj.pushKV("totalbytessent", connman.GetTotalBytesSent());
652  obj.pushKV("timemillis", GetTimeMillis());
653 
654  UniValue outboundLimit(UniValue::VOBJ);
655  outboundLimit.pushKV(
656  "timeframe", count_seconds(connman.GetMaxOutboundTimeframe()));
657  outboundLimit.pushKV("target", connman.GetMaxOutboundTarget());
658  outboundLimit.pushKV("target_reached",
659  connman.OutboundTargetReached(false));
660  outboundLimit.pushKV("serve_historical_blocks",
661  !connman.OutboundTargetReached(true));
662  outboundLimit.pushKV("bytes_left_in_cycle",
663  connman.GetOutboundTargetBytesLeft());
664  outboundLimit.pushKV(
665  "time_left_in_cycle",
667  obj.pushKV("uploadtarget", outboundLimit);
668  return obj;
669  },
670  };
671 }
672 
674  UniValue networks(UniValue::VARR);
675  for (int n = 0; n < NET_MAX; ++n) {
676  enum Network network = static_cast<enum Network>(n);
677  if (network == NET_UNROUTABLE || network == NET_CJDNS ||
678  network == NET_INTERNAL) {
679  continue;
680  }
681  proxyType proxy;
683  GetProxy(network, proxy);
684  obj.pushKV("name", GetNetworkName(network));
685  obj.pushKV("limited", !IsReachable(network));
686  obj.pushKV("reachable", IsReachable(network));
687  obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort()
688  : std::string());
689  obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
690  networks.push_back(obj);
691  }
692  return networks;
693 }
694 
696  const auto &ticker = Currency::get().ticker;
697  return RPCHelpMan{
698  "getnetworkinfo",
699  "Returns an object containing various state info regarding P2P "
700  "networking.\n",
701  {},
702  RPCResult{
704  "",
705  "",
706  {
707  {RPCResult::Type::NUM, "version", "the server version"},
708  {RPCResult::Type::STR, "subversion",
709  "the server subversion string"},
710  {RPCResult::Type::NUM, "protocolversion",
711  "the protocol version"},
712  {RPCResult::Type::STR_HEX, "localservices",
713  "the services we offer to the network"},
715  "localservicesnames",
716  "the services we offer to the network, in human-readable form",
717  {
718  {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
719  }},
720  {RPCResult::Type::BOOL, "localrelay",
721  "true if transaction relay is requested from peers"},
722  {RPCResult::Type::NUM, "timeoffset", "the time offset"},
723  {RPCResult::Type::NUM, "connections",
724  "the total number of connections"},
725  {RPCResult::Type::NUM, "connections_in",
726  "the number of inbound connections"},
727  {RPCResult::Type::NUM, "connections_out",
728  "the number of outbound connections"},
729  {RPCResult::Type::BOOL, "networkactive",
730  "whether p2p networking is enabled"},
732  "networks",
733  "information per network",
734  {
736  "",
737  "",
738  {
739  {RPCResult::Type::STR, "name",
740  "network (" + Join(GetNetworkNames(), ", ") + ")"},
741  {RPCResult::Type::BOOL, "limited",
742  "is the network limited using -onlynet?"},
743  {RPCResult::Type::BOOL, "reachable",
744  "is the network reachable?"},
745  {RPCResult::Type::STR, "proxy",
746  "(\"host:port\") the proxy that is used for this "
747  "network, or empty if none"},
748  {RPCResult::Type::BOOL, "proxy_randomize_credentials",
749  "Whether randomized credentials are used"},
750  }},
751  }},
752  {RPCResult::Type::NUM, "relayfee",
753  "minimum relay fee for transactions in " + ticker + "/kB"},
754  {RPCResult::Type::NUM, "excessutxocharge",
755  "minimum charge for excess utxos in " + ticker},
757  "localaddresses",
758  "list of local addresses",
759  {
761  "",
762  "",
763  {
764  {RPCResult::Type::STR, "address", "network address"},
765  {RPCResult::Type::NUM, "port", "network port"},
766  {RPCResult::Type::NUM, "score", "relative score"},
767  }},
768  }},
769  {RPCResult::Type::STR, "warnings",
770  "any network and blockchain warnings"},
771  }},
772  RPCExamples{HelpExampleCli("getnetworkinfo", "") +
773  HelpExampleRpc("getnetworkinfo", "")},
774  [&](const RPCHelpMan &self, const Config &config,
775  const JSONRPCRequest &request) -> UniValue {
776  LOCK(cs_main);
778  obj.pushKV("version", CLIENT_VERSION);
779  obj.pushKV("subversion", userAgent(config));
780  obj.pushKV("protocolversion", PROTOCOL_VERSION);
781  NodeContext &node = EnsureAnyNodeContext(request.context);
782  if (node.connman) {
783  ServiceFlags services = node.connman->GetLocalServices();
784  obj.pushKV("localservices", strprintf("%016x", services));
785  obj.pushKV("localservicesnames", GetServicesNames(services));
786  }
787  if (node.peerman) {
788  obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
789  }
790  obj.pushKV("timeoffset", GetTimeOffset());
791  if (node.connman) {
792  obj.pushKV("networkactive", node.connman->GetNetworkActive());
793  obj.pushKV("connections", int(node.connman->GetNodeCount(
795  obj.pushKV("connections_in", int(node.connman->GetNodeCount(
797  obj.pushKV("connections_out", int(node.connman->GetNodeCount(
799  }
800  obj.pushKV("networks", GetNetworksInfo());
801  obj.pushKV("relayfee", ::minRelayTxFee.GetFeePerK());
802  obj.pushKV("excessutxocharge", config.GetExcessUTXOCharge());
803  UniValue localAddresses(UniValue::VARR);
804  {
806  for (const std::pair<const CNetAddr, LocalServiceInfo> &item :
807  mapLocalHost) {
809  rec.pushKV("address", item.first.ToString());
810  rec.pushKV("port", item.second.nPort);
811  rec.pushKV("score", item.second.nScore);
812  localAddresses.push_back(rec);
813  }
814  }
815  obj.pushKV("localaddresses", localAddresses);
816  obj.pushKV("warnings", GetWarnings(false).original);
817  return obj;
818  },
819  };
820 }
821 
822 static RPCHelpMan setban() {
823  return RPCHelpMan{
824  "setban",
825  "Attempts to add or remove an IP/Subnet from the banned list.\n",
826  {
828  "The IP/Subnet (see getpeerinfo for nodes IP) with an optional "
829  "netmask (default is /32 = single IP)"},
831  "'add' to add an IP/Subnet to the list, 'remove' to remove an "
832  "IP/Subnet from the list"},
833  {"bantime", RPCArg::Type::NUM, /* default */ "0",
834  "time in seconds how long (or until when if [absolute] is set) "
835  "the IP is banned (0 or empty means using the default time of 24h "
836  "which can also be overwritten by the -bantime startup argument)"},
837  {"absolute", RPCArg::Type::BOOL, /* default */ "false",
838  "If set, the bantime must be an absolute timestamp expressed in " +
840  },
842  RPCExamples{
843  HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") +
844  HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") +
845  HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")},
846  [&](const RPCHelpMan &help, const Config &config,
847  const JSONRPCRequest &request) -> UniValue {
848  std::string strCommand;
849  if (!request.params[1].isNull()) {
850  strCommand = request.params[1].get_str();
851  }
852 
853  if (strCommand != "add" && strCommand != "remove") {
854  throw std::runtime_error(help.ToString());
855  }
856 
857  NodeContext &node = EnsureAnyNodeContext(request.context);
858  if (!node.banman) {
860  "Error: Ban database not loaded");
861  }
862 
863  CSubNet subNet;
864  CNetAddr netAddr;
865  bool isSubnet = false;
866 
867  if (request.params[0].get_str().find('/') != std::string::npos) {
868  isSubnet = true;
869  }
870 
871  if (!isSubnet) {
872  CNetAddr resolved;
873  LookupHost(request.params[0].get_str(), resolved, false);
874  netAddr = resolved;
875  } else {
876  LookupSubNet(request.params[0].get_str(), subNet);
877  }
878 
879  if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) {
881  "Error: Invalid IP/Subnet");
882  }
883 
884  if (strCommand == "add") {
885  if (isSubnet ? node.banman->IsBanned(subNet)
886  : node.banman->IsBanned(netAddr)) {
888  "Error: IP/Subnet already banned");
889  }
890 
891  // Use standard bantime if not specified.
892  int64_t banTime = 0;
893  if (!request.params[2].isNull()) {
894  banTime = request.params[2].get_int64();
895  }
896 
897  bool absolute = false;
898  if (request.params[3].isTrue()) {
899  absolute = true;
900  }
901 
902  if (isSubnet) {
903  node.banman->Ban(subNet, banTime, absolute);
904  if (node.connman) {
905  node.connman->DisconnectNode(subNet);
906  }
907  } else {
908  node.banman->Ban(netAddr, banTime, absolute);
909  if (node.connman) {
910  node.connman->DisconnectNode(netAddr);
911  }
912  }
913  } else if (strCommand == "remove") {
914  if (!(isSubnet ? node.banman->Unban(subNet)
915  : node.banman->Unban(netAddr))) {
916  throw JSONRPCError(
918  "Error: Unban failed. Requested address/subnet "
919  "was not previously manually banned.");
920  }
921  }
922  return NullUniValue;
923  },
924  };
925 }
926 
928  return RPCHelpMan{
929  "listbanned",
930  "List all manually banned IPs/Subnets.\n",
931  {},
933  "",
934  "",
935  {
937  "",
938  "",
939  {
940  {RPCResult::Type::STR, "address", ""},
941  {RPCResult::Type::NUM_TIME, "banned_until", ""},
942  {RPCResult::Type::NUM_TIME, "ban_created", ""},
943  {RPCResult::Type::STR, "ban_reason", ""},
944  }},
945  }},
946  RPCExamples{HelpExampleCli("listbanned", "") +
947  HelpExampleRpc("listbanned", "")},
948  [&](const RPCHelpMan &self, const Config &config,
949  const JSONRPCRequest &request) -> UniValue {
950  NodeContext &node = EnsureAnyNodeContext(request.context);
951  if (!node.banman) {
953  "Error: Ban database not loaded");
954  }
955 
956  banmap_t banMap;
957  node.banman->GetBanned(banMap);
958 
959  UniValue bannedAddresses(UniValue::VARR);
960  for (const auto &entry : banMap) {
961  const CBanEntry &banEntry = entry.second;
963  rec.pushKV("address", entry.first.ToString());
964  rec.pushKV("banned_until", banEntry.nBanUntil);
965  rec.pushKV("ban_created", banEntry.nCreateTime);
966 
967  bannedAddresses.push_back(rec);
968  }
969 
970  return bannedAddresses;
971  },
972  };
973 }
974 
976  return RPCHelpMan{
977  "clearbanned",
978  "Clear all banned IPs.\n",
979  {},
981  RPCExamples{HelpExampleCli("clearbanned", "") +
982  HelpExampleRpc("clearbanned", "")},
983  [&](const RPCHelpMan &self, const Config &config,
984  const JSONRPCRequest &request) -> UniValue {
985  NodeContext &node = EnsureAnyNodeContext(request.context);
986  if (!node.banman) {
987  throw JSONRPCError(
989  "Error: Peer-to-peer functionality missing or disabled");
990  }
991 
992  node.banman->ClearBanned();
993 
994  return NullUniValue;
995  },
996  };
997 }
998 
1000  return RPCHelpMan{
1001  "setnetworkactive",
1002  "Disable/enable all p2p network activity.\n",
1003  {
1005  "true to enable networking, false to disable"},
1006  },
1007  RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
1008  RPCExamples{""},
1009  [&](const RPCHelpMan &self, const Config &config,
1010  const JSONRPCRequest &request) -> UniValue {
1011  NodeContext &node = EnsureAnyNodeContext(request.context);
1012  CConnman &connman = EnsureConnman(node);
1013 
1014  connman.SetNetworkActive(request.params[0].get_bool());
1015 
1016  return connman.GetNetworkActive();
1017  },
1018  };
1019 }
1020 
1022  return RPCHelpMan{
1023  "getnodeaddresses",
1024  "Return known addresses, which can potentially be used to find new "
1025  "nodes in the network.\n",
1026  {
1027  {"count", RPCArg::Type::NUM, /* default */ "1",
1028  "The maximum number of addresses to return. Specify 0 to return "
1029  "all known addresses."},
1030  {"network", RPCArg::Type::STR, "all networks",
1031  "Return only addresses of the specified network. Can be one of: " +
1032  Join(GetNetworkNames(), ", ") + "."},
1033  },
1035  "",
1036  "",
1037  {
1039  "",
1040  "",
1041  {
1042  {RPCResult::Type::NUM_TIME, "time",
1043  "The " + UNIX_EPOCH_TIME +
1044  " when the node was last seen"},
1045  {RPCResult::Type::NUM, "services",
1046  "The services offered by the node"},
1047  {RPCResult::Type::STR, "address",
1048  "The address of the node"},
1049  {RPCResult::Type::NUM, "port",
1050  "The port number of the node"},
1051  {RPCResult::Type::STR, "network",
1052  "The network (" + Join(GetNetworkNames(), ", ") +
1053  ") the node connected through"},
1054  }},
1055  }},
1056  RPCExamples{HelpExampleCli("getnodeaddresses", "8") +
1057  HelpExampleCli("getnodeaddresses", "4 \"i2p\"") +
1058  HelpExampleCli("-named getnodeaddresses",
1059  "network=onion count=12") +
1060  HelpExampleRpc("getnodeaddresses", "8") +
1061  HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")},
1062  [&](const RPCHelpMan &self, const Config &config,
1063  const JSONRPCRequest &request) -> UniValue {
1064  NodeContext &node = EnsureAnyNodeContext(request.context);
1065  const CConnman &connman = EnsureConnman(node);
1066 
1067  const int count{
1068  request.params[0].isNull() ? 1 : request.params[0].get_int()};
1069  if (count < 0) {
1071  "Address count out of range");
1072  }
1073 
1074  const std::optional<Network> network{
1075  request.params[1].isNull()
1076  ? std::nullopt
1077  : std::optional<Network>{
1078  ParseNetwork(request.params[1].get_str())}};
1079  if (network == NET_UNROUTABLE) {
1081  strprintf("Network not recognized: %s",
1082  request.params[1].get_str()));
1083  }
1084  // returns a shuffled list of CAddress
1085  const std::vector<CAddress> vAddr{
1086  connman.GetAddresses(count, /* max_pct */ 0, network)};
1087  UniValue ret(UniValue::VARR);
1088 
1089  for (const CAddress &addr : vAddr) {
1090  UniValue obj(UniValue::VOBJ);
1091  obj.pushKV("time", int(addr.nTime));
1092  obj.pushKV("services", uint64_t(addr.nServices));
1093  obj.pushKV("address", addr.ToStringIP());
1094  obj.pushKV("port", addr.GetPort());
1095  obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
1096  ret.push_back(obj);
1097  }
1098  return ret;
1099  },
1100  };
1101 }
1102 
1104  return RPCHelpMan{
1105  "addpeeraddress",
1106  "Add the address of a potential peer to the address manager. This "
1107  "RPC is for testing only.\n",
1108  {
1110  "The IP address of the peer"},
1112  "The port of the peer"},
1113  {"tried", RPCArg::Type::BOOL, "false",
1114  "If true, attempt to add the peer to the tried addresses table"},
1115  },
1116  RPCResult{
1118  "",
1119  "",
1120  {
1121  {RPCResult::Type::BOOL, "success",
1122  "whether the peer address was successfully added to the "
1123  "address manager"},
1124  },
1125  },
1126  RPCExamples{
1127  HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true") +
1128  HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")},
1129  [&](const RPCHelpMan &self, const Config &config,
1130  const JSONRPCRequest &request) -> UniValue {
1131  NodeContext &node = EnsureAnyNodeContext(request.context);
1132  if (!node.addrman) {
1133  throw JSONRPCError(
1135  "Error: Address manager functionality missing or disabled");
1136  }
1137 
1138  const std::string &addr_string{request.params[0].get_str()};
1139  const uint16_t port{
1140  static_cast<uint16_t>(request.params[1].get_int())};
1141  const bool tried{request.params[2].isTrue()};
1142 
1143  UniValue obj(UniValue::VOBJ);
1144  CNetAddr net_addr;
1145  bool success{false};
1146 
1147  if (LookupHost(addr_string, net_addr, false)) {
1148  CAddress address{{net_addr, port}, ServiceFlags(NODE_NETWORK)};
1149  address.nTime = GetAdjustedTime();
1150  // The source address is set equal to the address. This is
1151  // equivalent to the peer announcing itself.
1152  if (node.addrman->Add({address}, address)) {
1153  success = true;
1154  if (tried) {
1155  // Attempt to move the address to the tried addresses
1156  // table.
1157  node.addrman->Good(address);
1158  }
1159  }
1160  }
1161 
1162  obj.pushKV("success", success);
1163  return obj;
1164  },
1165  };
1166 }
1167 
1169  // clang-format off
1170  static const CRPCCommand commands[] = {
1171  // category actor (function)
1172  // ------------------ ----------------------
1173  { "network", getconnectioncount, },
1174  { "network", ping, },
1175  { "network", getpeerinfo, },
1176  { "network", addnode, },
1177  { "network", disconnectnode, },
1178  { "network", getaddednodeinfo, },
1179  { "network", getnettotals, },
1180  { "network", getnetworkinfo, },
1181  { "network", setban, },
1182  { "network", listbanned, },
1183  { "network", clearbanned, },
1184  { "network", setnetworkactive, },
1185  { "network", getnodeaddresses, },
1186  { "hidden", addconnection, },
1187  { "hidden", addpeeraddress, },
1188  };
1189  // clang-format on
1190  for (const auto &c : commands) {
1191  t.appendCommand(c.name, &c);
1192  }
1193 }
bool isAvalancheEnabled(const ArgsManager &argsman)
Definition: avalanche.cpp:9
std::unique_ptr< avalanche::Processor > g_avalanche
Global avalanche instance.
Definition: processor.cpp:35
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:94
A CService with information about it as peer.
Definition: protocol.h:445
Definition: addrdb.h:30
int64_t nCreateTime
Definition: addrdb.h:34
int64_t nBanUntil
Definition: addrdb.h:35
static const std::string REGTEST
Definition: net.h:923
size_t GetNodeCount(NumConnections num) const
Definition: net.cpp:3237
std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const
returns the time in second left in the current max outbound cycle in case of no limit,...
Definition: net.cpp:3340
bool OutboundTargetReached(bool historicalBlockServingLimit) const
check if the outbound target is reached.
Definition: net.cpp:3356
std::vector< AddedNodeInfo > GetAddedNodeInfo() const
Definition: net.cpp:2473
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1405
bool GetNetworkActive() const
Definition: net.h:1013
uint64_t GetOutboundTargetBytesLeft() const
response the bytes left in the current max outbound cycle in case of no limit, it will always respons...
Definition: net.cpp:3379
std::chrono::seconds GetMaxOutboundTimeframe() const
Definition: net.cpp:3336
bool DisconnectNode(const std::string &node)
Definition: net.cpp:3266
uint64_t GetMaxOutboundTarget() const
Definition: net.cpp:3331
@ CONNECTIONS_IN
Definition: net.h:927
@ CONNECTIONS_ALL
Definition: net.h:929
@ CONNECTIONS_OUT
Definition: net.h:928
void GetNodeStats(std::vector< CNodeStats > &vstats) const
Definition: net.cpp:3255
uint64_t GetTotalBytesRecv() const
Definition: net.cpp:3390
std::vector< CAddress > GetAddresses(size_t max_addresses, size_t max_pct, std::optional< Network > network) const
Return all or many randomly selected addresses, optionally by network.
Definition: net.cpp:3147
void SetNetworkActive(bool active)
Definition: net.cpp:2836
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2562
bool AddNode(const std::string &node)
Definition: net.cpp:3213
uint64_t GetTotalBytesSent() const
Definition: net.cpp:3395
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:3225
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
Network address.
Definition: netaddress.h:122
bool IsValid() const
Definition: netaddress.cpp:479
RPC command dispatcher.
Definition: server.h:183
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:325
std::string ToStringIPPort() const
bool IsValid() const
Definition: config.h:17
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
virtual void SendPings()=0
Send ping message to all peers.
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) const =0
Get statistics from node state.
std::string ToString() const
Definition: util.cpp:534
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:27
@ VARR
Definition: univalue.h:27
int64_t get_int64() const
bool isNull() const
Definition: univalue.h:89
bool isStr() const
Definition: univalue.h:93
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
bool IsValid() const
Definition: netbase.h:38
CService proxy
Definition: netbase.h:40
bool randomize_credentials
Definition: netbase.h:41
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:44
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:125
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:110
std::string userAgent(const Config &config)
Definition: net.cpp:3610
bool IsReachable(enum Network net)
Definition: net.cpp:287
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.h:141
ConnectionType
Different types of connections to a peer.
Definition: net.h:154
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly inputted via the addnode RPC,...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
@ AVALANCHE_OUTBOUND
Special case of connection to a full relay outbound with avalanche service enabled.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
Network
A network type.
Definition: netaddress.h:45
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:63
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:70
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:48
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:67
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:113
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:720
bool LookupSubNet(const std::string &strSubnet, CSubNet &ret, DNSLookupFn dns_lookup_function)
Parse and resolve a specified subnet string into the appropriate internal representation.
Definition: netbase.cpp:786
enum Network ParseNetwork(const std::string &net_in)
Definition: netbase.cpp:91
std::vector< std::string > GetNetworkNames(bool append_unroutable)
Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE.
Definition: netbase.cpp:136
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
Definition: netbase.cpp:190
int64_t NodeId
Definition: nodeid.h:10
ServiceFlags
nServices flags.
Definition: protocol.h:338
@ NODE_NETWORK
Definition: protocol.h:345
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:52
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
Definition: net.cpp:1168
static RPCHelpMan getnetworkinfo()
Definition: net.cpp:695
static RPCHelpMan addconnection()
Definition: net.cpp:389
static RPCHelpMan getaddednodeinfo()
Definition: net.cpp:522
static RPCHelpMan clearbanned()
Definition: net.cpp:975
static RPCHelpMan getnettotals()
Definition: net.cpp:608
static RPCHelpMan addnode()
Definition: net.cpp:327
static RPCHelpMan getnodeaddresses()
Definition: net.cpp:1021
static RPCHelpMan setban()
Definition: net.cpp:822
static UniValue GetNetworksInfo()
Definition: net.cpp:673
static RPCHelpMan ping()
Definition: net.cpp:54
static RPCHelpMan getconnectioncount()
Definition: net.cpp:36
static RPCHelpMan disconnectnode()
Definition: net.cpp:467
static RPCHelpMan listbanned()
Definition: net.cpp:927
static RPCHelpMan setnetworkactive()
Definition: net.cpp:999
static RPCHelpMan addpeeraddress()
Definition: net.cpp:1103
static RPCHelpMan getpeerinfo()
Definition: net.cpp:79
@ RPC_CLIENT_NODE_NOT_CONNECTED
Node to disconnect not found in connected nodes.
Definition: protocol.h:77
@ RPC_CLIENT_INVALID_IP_OR_SUBNET
Invalid IP/Subnet.
Definition: protocol.h:79
@ RPC_CLIENT_NODE_ALREADY_ADDED
Node is already added.
Definition: protocol.h:73
@ RPC_INVALID_PARAMS
Definition: protocol.h:30
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition: protocol.h:46
@ RPC_DATABASE_ERROR
Database error.
Definition: protocol.h:48
@ RPC_CLIENT_NODE_NOT_ADDED
Node has not been added before.
Definition: protocol.h:75
@ RPC_CLIENT_NODE_CAPACITY_REACHED
Max number of outbound or block-relay connections already open.
Definition: protocol.h:83
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition: protocol.h:81
void RPCTypeCheck(const UniValue &params, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: util.cpp:26
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:139
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
Definition: util.cpp:1011
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:144
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
Definition: util.cpp:22
static RPCHelpMan help()
Definition: server.cpp:177
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:17
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:48
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:57
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
Definition: string.h:44
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
Definition: string.h:19
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:77
std::chrono::microseconds m_ping_wait
std::vector< int > vHeightInFlight
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
POD that contains various stats about a node.
Definition: net.h:284
static const Currency & get()
Definition: amount.cpp:18
std::string ticker
Definition: amount.h:160
NodeContext struct containing references to chain state and connection state.
Definition: context.h:37
std::unique_ptr< PeerManager > peerman
Definition: context.h:41
std::unique_ptr< AddrMan > addrman
Definition: context.h:38
std::unique_ptr< BanMan > banman
Definition: context.h:43
std::unique_ptr< CConnman > connman
Definition: context.h:39
@ NO
Required arg.
@ NUM_TIME
Special numeric to denote unix epoch time.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
#define LOCK(cs)
Definition: sync.h:243
ArgsManager gArgs
Definition: system.cpp:77
static int count
Definition: tests.c:31
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:106
constexpr int64_t count_seconds(std::chrono::seconds t)
Helper to count the seconds of a duration.
Definition: time.h:29
double CountSecondsDouble(SecondsDouble t)
Helper to count the seconds in any std::chrono::duration type.
Definition: time.h:45
int64_t GetAdjustedTime()
Definition: timedata.cpp:34
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
Definition: timedata.cpp:29
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
const UniValue NullUniValue
Definition: univalue.cpp:13
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
Definition: validation.cpp:108
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11
bilingual_str GetWarnings(bool verbose)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:41