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 
36 using node::NodeContext;
37 
39  return RPCHelpMan{
40  "getconnectioncount",
41  "Returns the number of connections to other nodes.\n",
42  {},
43  RPCResult{RPCResult::Type::NUM, "", "The connection count"},
44  RPCExamples{HelpExampleCli("getconnectioncount", "") +
45  HelpExampleRpc("getconnectioncount", "")},
46  [&](const RPCHelpMan &self, const Config &config,
47  const JSONRPCRequest &request) -> UniValue {
48  NodeContext &node = EnsureAnyNodeContext(request.context);
49  const CConnman &connman = EnsureConnman(node);
50 
52  },
53  };
54 }
55 
56 static RPCHelpMan ping() {
57  return RPCHelpMan{
58  "ping",
59  "Requests that a ping be sent to all other nodes, to measure ping "
60  "time.\n"
61  "Results provided in getpeerinfo, pingtime and pingwait fields are "
62  "decimal seconds.\n"
63  "Ping command is handled in queue with all other commands, so it "
64  "measures processing backlog, not just network ping.\n",
65  {},
67  RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")},
68  [&](const RPCHelpMan &self, const Config &config,
69  const JSONRPCRequest &request) -> UniValue {
70  NodeContext &node = EnsureAnyNodeContext(request.context);
71  PeerManager &peerman = EnsurePeerman(node);
72 
73  // Request that each node send a ping during next message processing
74  // pass
75  peerman.SendPings();
76  return NullUniValue;
77  },
78  };
79 }
80 
82  return RPCHelpMan{
83  "getpeerinfo",
84  "Returns data about each connected network node as a json array of "
85  "objects.\n",
86  {},
87  RPCResult{
89  "",
90  "",
91  {{
93  "",
94  "",
95  {{
96  {RPCResult::Type::NUM, "id", "Peer index"},
97  {RPCResult::Type::STR, "addr",
98  "(host:port) The IP address and port of the peer"},
99  {RPCResult::Type::STR, "addrbind",
100  "(ip:port) Bind address of the connection to the peer"},
101  {RPCResult::Type::STR, "addrlocal",
102  "(ip:port) Local address as reported by the 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, "presynced_headers",
169  /*optional=*/true,
170  "The current height of header pre-synchronization with "
171  "this peer, or -1 if no low-work sync is in progress"},
172  {RPCResult::Type::NUM, "synced_headers",
173  "The last header we have in common with this peer"},
174  {RPCResult::Type::NUM, "synced_blocks",
175  "The last block we have in common with this peer"},
177  "inflight",
178  "",
179  {
180  {RPCResult::Type::NUM, "n",
181  "The heights of blocks we're currently asking from "
182  "this peer"},
183  }},
184  {RPCResult::Type::BOOL, "addr_relay_enabled",
185  "Whether we participate in address relay with this peer"},
186  {RPCResult::Type::NUM, "minfeefilter",
187  "The minimum fee rate for transactions this peer accepts"},
189  "bytessent_per_msg",
190  "",
191  {{RPCResult::Type::NUM, "msg",
192  "The total bytes sent aggregated by message type\n"
193  "When a message type is not listed in this json object, "
194  "the bytes sent are 0.\n"
195  "Only known message types can appear as keys in the "
196  "object."}}},
198  "bytesrecv_per_msg",
199  "",
200  {{RPCResult::Type::NUM, "msg",
201  "The total bytes received aggregated by message type\n"
202  "When a message type is not listed in this json object, "
203  "the bytes received are 0.\n"
204  "Only known message types can appear as keys in the "
205  "object and all bytes received\n"
206  "of unknown message types are listed under '" +
207  NET_MESSAGE_COMMAND_OTHER + "'."}}},
208  {RPCResult::Type::NUM, "availability_score",
209  "Avalanche availability score of this node (if any)"},
210  }},
211  }},
212  },
213  RPCExamples{HelpExampleCli("getpeerinfo", "") +
214  HelpExampleRpc("getpeerinfo", "")},
215  [&](const RPCHelpMan &self, const Config &config,
216  const JSONRPCRequest &request) -> UniValue {
217  NodeContext &node = EnsureAnyNodeContext(request.context);
218  const CConnman &connman = EnsureConnman(node);
219  const PeerManager &peerman = EnsurePeerman(node);
220 
221  std::vector<CNodeStats> vstats;
222  connman.GetNodeStats(vstats);
223 
225 
226  for (const CNodeStats &stats : vstats) {
228  CNodeStateStats statestats;
229  bool fStateStats =
230  peerman.GetNodeStateStats(stats.nodeid, statestats);
231  obj.pushKV("id", stats.nodeid);
232  obj.pushKV("addr", stats.m_addr_name);
233  if (stats.addrBind.IsValid()) {
234  obj.pushKV("addrbind", stats.addrBind.ToString());
235  }
236  if (!(stats.addrLocal.empty())) {
237  obj.pushKV("addrlocal", stats.addrLocal);
238  }
239  obj.pushKV("network", GetNetworkName(stats.m_network));
240  if (stats.m_mapped_as != 0) {
241  obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
242  }
243  ServiceFlags services{fStateStats ? statestats.their_services
245  obj.pushKV("services", strprintf("%016x", services));
246  obj.pushKV("servicesnames", GetServicesNames(services));
247  obj.pushKV("lastsend", count_seconds(stats.m_last_send));
248  obj.pushKV("lastrecv", count_seconds(stats.m_last_recv));
249  obj.pushKV("last_transaction",
250  count_seconds(stats.m_last_tx_time));
251  if (node.avalanche) {
252  obj.pushKV("last_proof",
253  count_seconds(stats.m_last_proof_time));
254  }
255  obj.pushKV("last_block",
256  count_seconds(stats.m_last_block_time));
257  obj.pushKV("bytessent", stats.nSendBytes);
258  obj.pushKV("bytesrecv", stats.nRecvBytes);
259  obj.pushKV("conntime", count_seconds(stats.m_connected));
260  obj.pushKV("timeoffset", stats.nTimeOffset);
261  if (stats.m_last_ping_time > 0us) {
262  obj.pushKV("pingtime",
263  CountSecondsDouble(stats.m_last_ping_time));
264  }
265  if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
266  obj.pushKV("minping",
267  CountSecondsDouble(stats.m_min_ping_time));
268  }
269  if (fStateStats && statestats.m_ping_wait > 0s) {
270  obj.pushKV("pingwait",
271  CountSecondsDouble(statestats.m_ping_wait));
272  }
273  obj.pushKV("version", stats.nVersion);
274  // Use the sanitized form of subver here, to avoid tricksy
275  // remote peers from corrupting or modifying the JSON output by
276  // putting special characters in their ver message.
277  obj.pushKV("subver", stats.cleanSubVer);
278  obj.pushKV("inbound", stats.fInbound);
279  obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to);
280  obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from);
281  if (fStateStats) {
282  obj.pushKV("startingheight", statestats.m_starting_height);
283  obj.pushKV("presynced_headers", statestats.presync_height);
284  obj.pushKV("synced_headers", statestats.nSyncHeight);
285  obj.pushKV("synced_blocks", statestats.nCommonHeight);
286  UniValue heights(UniValue::VARR);
287  for (const int height : statestats.vHeightInFlight) {
288  heights.push_back(height);
289  }
290  obj.pushKV("inflight", heights);
291  obj.pushKV("relaytxes", statestats.m_relay_txs);
292  obj.pushKV("minfeefilter",
293  statestats.m_fee_filter_received);
294  obj.pushKV("addr_relay_enabled",
295  statestats.m_addr_relay_enabled);
296  obj.pushKV("addr_processed", statestats.m_addr_processed);
297  obj.pushKV("addr_rate_limited",
298  statestats.m_addr_rate_limited);
299  }
300  UniValue permissions(UniValue::VARR);
301  for (const auto &permission :
302  NetPermissions::ToStrings(stats.m_permissionFlags)) {
303  permissions.push_back(permission);
304  }
305  obj.pushKV("permissions", permissions);
306 
307  UniValue sendPerMsgCmd(UniValue::VOBJ);
308  for (const auto &i : stats.mapSendBytesPerMsgCmd) {
309  if (i.second > 0) {
310  sendPerMsgCmd.pushKV(i.first, i.second);
311  }
312  }
313  obj.pushKV("bytessent_per_msg", sendPerMsgCmd);
314 
315  UniValue recvPerMsgCmd(UniValue::VOBJ);
316  for (const auto &i : stats.mapRecvBytesPerMsgCmd) {
317  if (i.second > 0) {
318  recvPerMsgCmd.pushKV(i.first, i.second);
319  }
320  }
321  obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
322  obj.pushKV("connection_type",
323  ConnectionTypeAsString(stats.m_conn_type));
324 
325  if (stats.m_availabilityScore) {
326  obj.pushKV("availability_score",
327  *stats.m_availabilityScore);
328  }
329 
330  ret.push_back(obj);
331  }
332 
333  return ret;
334  },
335  };
336 }
337 
338 static RPCHelpMan addnode() {
339  return RPCHelpMan{
340  "addnode",
341  "Attempts to add or remove a node from the addnode list.\n"
342  "Or try a connection to a node once.\n"
343  "Nodes added using addnode (or -connect) are protected from "
344  "DoS disconnection and are not required to be\n"
345  "full nodes as other outbound peers are (though such peers "
346  "will not be synced from).\n",
347  {
349  "The node (see getpeerinfo for nodes)"},
351  "'add' to add a node to the list, 'remove' to remove a "
352  "node from the list, 'onetry' to try a connection to the "
353  "node once"},
354  },
356  RPCExamples{
357  HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") +
358  HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")},
359  [&](const RPCHelpMan &self, const Config &config,
360  const JSONRPCRequest &request) -> UniValue {
361  std::string strCommand;
362  if (!request.params[1].isNull()) {
363  strCommand = request.params[1].get_str();
364  }
365 
366  if (strCommand != "onetry" && strCommand != "add" &&
367  strCommand != "remove") {
368  throw std::runtime_error(self.ToString());
369  }
370 
371  NodeContext &node = EnsureAnyNodeContext(request.context);
372  CConnman &connman = EnsureConnman(node);
373 
374  std::string strNode = request.params[0].get_str();
375 
376  if (strCommand == "onetry") {
377  CAddress addr;
378  connman.OpenNetworkConnection(addr, false, nullptr,
379  strNode.c_str(),
381  return NullUniValue;
382  }
383 
384  if ((strCommand == "add") && (!connman.AddNode(strNode))) {
386  "Error: Node already added");
387  } else if ((strCommand == "remove") &&
388  (!connman.RemoveAddedNode(strNode))) {
389  throw JSONRPCError(
391  "Error: Node could not be removed. It has not been "
392  "added previously.");
393  }
394 
395  return NullUniValue;
396  },
397  };
398 }
399 
401  return RPCHelpMan{
402  "addconnection",
403  "\nOpen an outbound connection to a specified node. This RPC is for "
404  "testing only.\n",
405  {
407  "The IP address and port to attempt connecting to."},
408  {"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO,
409  "Type of connection to open (\"outbound-full-relay\", "
410  "\"block-relay-only\", \"addr-fetch\", \"feeler\" or "
411  "\"avalanche\")."},
412  },
414  "",
415  "",
416  {
417  {RPCResult::Type::STR, "address",
418  "Address of newly added connection."},
419  {RPCResult::Type::STR, "connection_type",
420  "Type of connection opened."},
421  }},
422  RPCExamples{
423  HelpExampleCli("addconnection",
424  "\"192.168.0.6:8333\" \"outbound-full-relay\"") +
425  HelpExampleRpc("addconnection",
426  "\"192.168.0.6:8333\" \"outbound-full-relay\"")},
427  [&](const RPCHelpMan &self, const Config &config,
428  const JSONRPCRequest &request) -> UniValue {
429  if (config.GetChainParams().NetworkIDString() !=
431  throw std::runtime_error("addconnection is for regression "
432  "testing (-regtest mode) only.");
433  }
434 
435  NodeContext &node = EnsureAnyNodeContext(request.context);
436 
437  const std::string address = request.params[0].get_str();
438  const std::string conn_type_in{
439  TrimString(request.params[1].get_str())};
440  ConnectionType conn_type{};
441  if (conn_type_in == "outbound-full-relay") {
443  } else if (conn_type_in == "block-relay-only") {
444  conn_type = ConnectionType::BLOCK_RELAY;
445  } else if (conn_type_in == "addr-fetch") {
446  conn_type = ConnectionType::ADDR_FETCH;
447  } else if (conn_type_in == "feeler") {
448  conn_type = ConnectionType::FEELER;
449  } else if (conn_type_in == "avalanche") {
450  if (!node.avalanche) {
452  "Error: avalanche outbound requested "
453  "but avalanche is not enabled.");
454  }
456  } else {
458  }
459 
460  CConnman &connman = EnsureConnman(node);
461 
462  const bool success = connman.AddConnection(address, conn_type);
463  if (!success) {
465  "Error: Already at capacity for specified "
466  "connection type.");
467  }
468 
469  UniValue info(UniValue::VOBJ);
470  info.pushKV("address", address);
471  info.pushKV("connection_type", conn_type_in);
472 
473  return info;
474  },
475  };
476 }
477 
479  return RPCHelpMan{
480  "disconnectnode",
481  "Immediately disconnects from the specified peer node.\n"
482  "\nStrictly one out of 'address' and 'nodeid' can be provided to "
483  "identify the node.\n"
484  "\nTo disconnect by nodeid, either set 'address' to the empty string, "
485  "or call using the named 'nodeid' argument only.\n",
486  {
487  {"address", RPCArg::Type::STR,
488  RPCArg::DefaultHint{"fallback to nodeid"},
489  "The IP address/port of the node"},
490  {"nodeid", RPCArg::Type::NUM,
491  RPCArg::DefaultHint{"fallback to address"},
492  "The node ID (see getpeerinfo for node IDs)"},
493  },
495  RPCExamples{HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") +
496  HelpExampleCli("disconnectnode", "\"\" 1") +
497  HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") +
498  HelpExampleRpc("disconnectnode", "\"\", 1")},
499  [&](const RPCHelpMan &self, const Config &config,
500  const JSONRPCRequest &request) -> UniValue {
501  NodeContext &node = EnsureAnyNodeContext(request.context);
502  CConnman &connman = EnsureConnman(node);
503 
504  bool success;
505  const UniValue &address_arg = request.params[0];
506  const UniValue &id_arg = request.params[1];
507 
508  if (!address_arg.isNull() && id_arg.isNull()) {
509  /* handle disconnect-by-address */
510  success = connman.DisconnectNode(address_arg.get_str());
511  } else if (!id_arg.isNull() && (address_arg.isNull() ||
512  (address_arg.isStr() &&
513  address_arg.get_str().empty()))) {
514  /* handle disconnect-by-id */
515  NodeId nodeid = (NodeId)id_arg.getInt<int64_t>();
516  success = connman.DisconnectNode(nodeid);
517  } else {
518  throw JSONRPCError(
520  "Only one of address and nodeid should be provided.");
521  }
522 
523  if (!success) {
525  "Node not found in connected nodes");
526  }
527 
528  return NullUniValue;
529  },
530  };
531 }
532 
534  return RPCHelpMan{
535  "getaddednodeinfo",
536  "Returns information about the given added node, or all added nodes\n"
537  "(note that onetry addnodes are not listed here)\n",
538  {
539  {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"},
540  "If provided, return information about this specific node, "
541  "otherwise all nodes are returned."},
542  },
543  RPCResult{
545  "",
546  "",
547  {
549  "",
550  "",
551  {
552  {RPCResult::Type::STR, "addednode",
553  "The node IP address or name (as provided to addnode)"},
554  {RPCResult::Type::BOOL, "connected", "If connected"},
556  "addresses",
557  "Only when connected = true",
558  {
560  "",
561  "",
562  {
563  {RPCResult::Type::STR, "address",
564  "The bitcoin server IP and port we're "
565  "connected to"},
566  {RPCResult::Type::STR, "connected",
567  "connection, inbound or outbound"},
568  }},
569  }},
570  }},
571  }},
572  RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") +
573  HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")},
574  [&](const RPCHelpMan &self, const Config &config,
575  const JSONRPCRequest &request) -> UniValue {
576  NodeContext &node = EnsureAnyNodeContext(request.context);
577  const CConnman &connman = EnsureConnman(node);
578 
579  std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo();
580 
581  if (!request.params[0].isNull()) {
582  bool found = false;
583  for (const AddedNodeInfo &info : vInfo) {
584  if (info.strAddedNode == request.params[0].get_str()) {
585  vInfo.assign(1, info);
586  found = true;
587  break;
588  }
589  }
590  if (!found) {
592  "Error: Node has not been added.");
593  }
594  }
595 
597 
598  for (const AddedNodeInfo &info : vInfo) {
600  obj.pushKV("addednode", info.strAddedNode);
601  obj.pushKV("connected", info.fConnected);
602  UniValue addresses(UniValue::VARR);
603  if (info.fConnected) {
604  UniValue address(UniValue::VOBJ);
605  address.pushKV("address", info.resolvedAddress.ToString());
606  address.pushKV("connected",
607  info.fInbound ? "inbound" : "outbound");
608  addresses.push_back(address);
609  }
610  obj.pushKV("addresses", addresses);
611  ret.push_back(obj);
612  }
613 
614  return ret;
615  },
616  };
617 }
618 
620  return RPCHelpMan{
621  "getnettotals",
622  "Returns information about network traffic, including bytes in, "
623  "bytes out,\n"
624  "and current time.\n",
625  {},
626  RPCResult{
628  "",
629  "",
630  {
631  {RPCResult::Type::NUM, "totalbytesrecv",
632  "Total bytes received"},
633  {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"},
634  {RPCResult::Type::NUM_TIME, "timemillis",
635  "Current " + UNIX_EPOCH_TIME + " in milliseconds"},
637  "uploadtarget",
638  "",
639  {
640  {RPCResult::Type::NUM, "timeframe",
641  "Length of the measuring timeframe in seconds"},
642  {RPCResult::Type::NUM, "target", "Target in bytes"},
643  {RPCResult::Type::BOOL, "target_reached",
644  "True if target is reached"},
645  {RPCResult::Type::BOOL, "serve_historical_blocks",
646  "True if serving historical blocks"},
647  {RPCResult::Type::NUM, "bytes_left_in_cycle",
648  "Bytes left in current time cycle"},
649  {RPCResult::Type::NUM, "time_left_in_cycle",
650  "Seconds left in current time cycle"},
651  }},
652  }},
653  RPCExamples{HelpExampleCli("getnettotals", "") +
654  HelpExampleRpc("getnettotals", "")},
655  [&](const RPCHelpMan &self, const Config &config,
656  const JSONRPCRequest &request) -> UniValue {
657  NodeContext &node = EnsureAnyNodeContext(request.context);
658  const CConnman &connman = EnsureConnman(node);
659 
661  obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv());
662  obj.pushKV("totalbytessent", connman.GetTotalBytesSent());
663  obj.pushKV("timemillis", GetTimeMillis());
664 
665  UniValue outboundLimit(UniValue::VOBJ);
666  outboundLimit.pushKV(
667  "timeframe", count_seconds(connman.GetMaxOutboundTimeframe()));
668  outboundLimit.pushKV("target", connman.GetMaxOutboundTarget());
669  outboundLimit.pushKV("target_reached",
670  connman.OutboundTargetReached(false));
671  outboundLimit.pushKV("serve_historical_blocks",
672  !connman.OutboundTargetReached(true));
673  outboundLimit.pushKV("bytes_left_in_cycle",
674  connman.GetOutboundTargetBytesLeft());
675  outboundLimit.pushKV(
676  "time_left_in_cycle",
678  obj.pushKV("uploadtarget", outboundLimit);
679  return obj;
680  },
681  };
682 }
683 
685  UniValue networks(UniValue::VARR);
686  for (int n = 0; n < NET_MAX; ++n) {
687  enum Network network = static_cast<enum Network>(n);
688  if (network == NET_UNROUTABLE || network == NET_CJDNS ||
689  network == NET_INTERNAL) {
690  continue;
691  }
692  proxyType proxy;
694  GetProxy(network, proxy);
695  obj.pushKV("name", GetNetworkName(network));
696  obj.pushKV("limited", !IsReachable(network));
697  obj.pushKV("reachable", IsReachable(network));
698  obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort()
699  : std::string());
700  obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
701  networks.push_back(obj);
702  }
703  return networks;
704 }
705 
707  const auto &ticker = Currency::get().ticker;
708  return RPCHelpMan{
709  "getnetworkinfo",
710  "Returns an object containing various state info regarding P2P "
711  "networking.\n",
712  {},
713  RPCResult{
715  "",
716  "",
717  {
718  {RPCResult::Type::NUM, "version", "the server version"},
719  {RPCResult::Type::STR, "subversion",
720  "the server subversion string"},
721  {RPCResult::Type::NUM, "protocolversion",
722  "the protocol version"},
723  {RPCResult::Type::STR_HEX, "localservices",
724  "the services we offer to the network"},
726  "localservicesnames",
727  "the services we offer to the network, in human-readable form",
728  {
729  {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
730  }},
731  {RPCResult::Type::BOOL, "localrelay",
732  "true if transaction relay is requested from peers"},
733  {RPCResult::Type::NUM, "timeoffset", "the time offset"},
734  {RPCResult::Type::NUM, "connections",
735  "the total number of connections"},
736  {RPCResult::Type::NUM, "connections_in",
737  "the number of inbound connections"},
738  {RPCResult::Type::NUM, "connections_out",
739  "the number of outbound connections"},
740  {RPCResult::Type::BOOL, "networkactive",
741  "whether p2p networking is enabled"},
743  "networks",
744  "information per network",
745  {
747  "",
748  "",
749  {
750  {RPCResult::Type::STR, "name",
751  "network (" + Join(GetNetworkNames(), ", ") + ")"},
752  {RPCResult::Type::BOOL, "limited",
753  "is the network limited using -onlynet?"},
754  {RPCResult::Type::BOOL, "reachable",
755  "is the network reachable?"},
756  {RPCResult::Type::STR, "proxy",
757  "(\"host:port\") the proxy that is used for this "
758  "network, or empty if none"},
759  {RPCResult::Type::BOOL, "proxy_randomize_credentials",
760  "Whether randomized credentials are used"},
761  }},
762  }},
763  {RPCResult::Type::NUM, "relayfee",
764  "minimum relay fee for transactions in " + ticker + "/kB"},
766  "localaddresses",
767  "list of local addresses",
768  {
770  "",
771  "",
772  {
773  {RPCResult::Type::STR, "address", "network address"},
774  {RPCResult::Type::NUM, "port", "network port"},
775  {RPCResult::Type::NUM, "score", "relative score"},
776  }},
777  }},
778  {RPCResult::Type::STR, "warnings",
779  "any network and blockchain warnings"},
780  }},
781  RPCExamples{HelpExampleCli("getnetworkinfo", "") +
782  HelpExampleRpc("getnetworkinfo", "")},
783  [&](const RPCHelpMan &self, const Config &config,
784  const JSONRPCRequest &request) -> UniValue {
785  LOCK(cs_main);
787  obj.pushKV("version", CLIENT_VERSION);
788  obj.pushKV("subversion", userAgent(config));
789  obj.pushKV("protocolversion", PROTOCOL_VERSION);
790  NodeContext &node = EnsureAnyNodeContext(request.context);
791  if (node.connman) {
792  ServiceFlags services = node.connman->GetLocalServices();
793  obj.pushKV("localservices", strprintf("%016x", services));
794  obj.pushKV("localservicesnames", GetServicesNames(services));
795  }
796  if (node.peerman) {
797  obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
798  }
799  obj.pushKV("timeoffset", GetTimeOffset());
800  if (node.connman) {
801  obj.pushKV("networkactive", node.connman->GetNetworkActive());
802  obj.pushKV("connections", node.connman->GetNodeCount(
804  obj.pushKV("connections_in", node.connman->GetNodeCount(
806  obj.pushKV("connections_out", node.connman->GetNodeCount(
808  }
809  obj.pushKV("networks", GetNetworksInfo());
810  if (node.mempool) {
811  // This field can be deprecated, to be replaced by the
812  // getmempoolinfo fields
813  obj.pushKV("relayfee",
814  node.mempool->m_min_relay_feerate.GetFeePerK());
815  }
816  UniValue localAddresses(UniValue::VARR);
817  {
819  for (const std::pair<const CNetAddr, LocalServiceInfo> &item :
820  mapLocalHost) {
822  rec.pushKV("address", item.first.ToString());
823  rec.pushKV("port", item.second.nPort);
824  rec.pushKV("score", item.second.nScore);
825  localAddresses.push_back(rec);
826  }
827  }
828  obj.pushKV("localaddresses", localAddresses);
829  obj.pushKV("warnings", GetWarnings(false).original);
830  return obj;
831  },
832  };
833 }
834 
835 static RPCHelpMan setban() {
836  return RPCHelpMan{
837  "setban",
838  "Attempts to add or remove an IP/Subnet from the banned list.\n",
839  {
841  "The IP/Subnet (see getpeerinfo for nodes IP) with an optional "
842  "netmask (default is /32 = single IP)"},
844  "'add' to add an IP/Subnet to the list, 'remove' to remove an "
845  "IP/Subnet from the list"},
846  {"bantime", RPCArg::Type::NUM, RPCArg::Default{0},
847  "time in seconds how long (or until when if [absolute] is set) "
848  "the IP is banned (0 or empty means using the default time of 24h "
849  "which can also be overwritten by the -bantime startup argument)"},
850  {"absolute", RPCArg::Type::BOOL, RPCArg::Default{false},
851  "If set, the bantime must be an absolute timestamp expressed in " +
853  },
855  RPCExamples{
856  HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") +
857  HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") +
858  HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")},
859  [&](const RPCHelpMan &help, const Config &config,
860  const JSONRPCRequest &request) -> UniValue {
861  std::string strCommand;
862  if (!request.params[1].isNull()) {
863  strCommand = request.params[1].get_str();
864  }
865 
866  if (strCommand != "add" && strCommand != "remove") {
867  throw std::runtime_error(help.ToString());
868  }
869 
870  NodeContext &node = EnsureAnyNodeContext(request.context);
871  if (!node.banman) {
873  "Error: Ban database not loaded");
874  }
875 
876  CSubNet subNet;
877  CNetAddr netAddr;
878  bool isSubnet = false;
879 
880  if (request.params[0].get_str().find('/') != std::string::npos) {
881  isSubnet = true;
882  }
883 
884  if (!isSubnet) {
885  CNetAddr resolved;
886  LookupHost(request.params[0].get_str(), resolved, false);
887  netAddr = resolved;
888  } else {
889  LookupSubNet(request.params[0].get_str(), subNet);
890  }
891 
892  if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) {
894  "Error: Invalid IP/Subnet");
895  }
896 
897  if (strCommand == "add") {
898  if (isSubnet ? node.banman->IsBanned(subNet)
899  : node.banman->IsBanned(netAddr)) {
901  "Error: IP/Subnet already banned");
902  }
903 
904  // Use standard bantime if not specified.
905  int64_t banTime = 0;
906  if (!request.params[2].isNull()) {
907  banTime = request.params[2].getInt<int64_t>();
908  }
909 
910  bool absolute = false;
911  if (request.params[3].isTrue()) {
912  absolute = true;
913  }
914 
915  if (isSubnet) {
916  node.banman->Ban(subNet, banTime, absolute);
917  if (node.connman) {
918  node.connman->DisconnectNode(subNet);
919  }
920  } else {
921  node.banman->Ban(netAddr, banTime, absolute);
922  if (node.connman) {
923  node.connman->DisconnectNode(netAddr);
924  }
925  }
926  } else if (strCommand == "remove") {
927  if (!(isSubnet ? node.banman->Unban(subNet)
928  : node.banman->Unban(netAddr))) {
929  throw JSONRPCError(
931  "Error: Unban failed. Requested address/subnet "
932  "was not previously manually banned.");
933  }
934  }
935  return NullUniValue;
936  },
937  };
938 }
939 
941  return RPCHelpMan{
942  "listbanned",
943  "List all manually banned IPs/Subnets.\n",
944  {},
946  "",
947  "",
948  {
950  "",
951  "",
952  {
953  {RPCResult::Type::STR, "address", ""},
954  {RPCResult::Type::NUM_TIME, "banned_until", ""},
955  {RPCResult::Type::NUM_TIME, "ban_created", ""},
956  {RPCResult::Type::STR, "ban_reason", ""},
957  }},
958  }},
959  RPCExamples{HelpExampleCli("listbanned", "") +
960  HelpExampleRpc("listbanned", "")},
961  [&](const RPCHelpMan &self, const Config &config,
962  const JSONRPCRequest &request) -> UniValue {
963  NodeContext &node = EnsureAnyNodeContext(request.context);
964  if (!node.banman) {
966  "Error: Ban database not loaded");
967  }
968 
969  banmap_t banMap;
970  node.banman->GetBanned(banMap);
971 
972  UniValue bannedAddresses(UniValue::VARR);
973  for (const auto &entry : banMap) {
974  const CBanEntry &banEntry = entry.second;
976  rec.pushKV("address", entry.first.ToString());
977  rec.pushKV("banned_until", banEntry.nBanUntil);
978  rec.pushKV("ban_created", banEntry.nCreateTime);
979 
980  bannedAddresses.push_back(rec);
981  }
982 
983  return bannedAddresses;
984  },
985  };
986 }
987 
989  return RPCHelpMan{
990  "clearbanned",
991  "Clear all banned IPs.\n",
992  {},
994  RPCExamples{HelpExampleCli("clearbanned", "") +
995  HelpExampleRpc("clearbanned", "")},
996  [&](const RPCHelpMan &self, const Config &config,
997  const JSONRPCRequest &request) -> UniValue {
998  NodeContext &node = EnsureAnyNodeContext(request.context);
999  if (!node.banman) {
1000  throw JSONRPCError(
1002  "Error: Peer-to-peer functionality missing or disabled");
1003  }
1004 
1005  node.banman->ClearBanned();
1006 
1007  return NullUniValue;
1008  },
1009  };
1010 }
1011 
1013  return RPCHelpMan{
1014  "setnetworkactive",
1015  "Disable/enable all p2p network activity.\n",
1016  {
1018  "true to enable networking, false to disable"},
1019  },
1020  RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
1021  RPCExamples{""},
1022  [&](const RPCHelpMan &self, const Config &config,
1023  const JSONRPCRequest &request) -> UniValue {
1024  NodeContext &node = EnsureAnyNodeContext(request.context);
1025  CConnman &connman = EnsureConnman(node);
1026 
1027  connman.SetNetworkActive(request.params[0].get_bool());
1028 
1029  return connman.GetNetworkActive();
1030  },
1031  };
1032 }
1033 
1035  return RPCHelpMan{
1036  "getnodeaddresses",
1037  "Return known addresses, which can potentially be used to find new "
1038  "nodes in the network.\n",
1039  {
1040  {"count", RPCArg::Type::NUM, RPCArg::Default{1},
1041  "The maximum number of addresses to return. Specify 0 to return "
1042  "all known addresses."},
1043  {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"},
1044  "Return only addresses of the specified network. Can be one of: " +
1045  Join(GetNetworkNames(), ", ") + "."},
1046  },
1048  "",
1049  "",
1050  {
1052  "",
1053  "",
1054  {
1055  {RPCResult::Type::NUM_TIME, "time",
1056  "The " + UNIX_EPOCH_TIME +
1057  " when the node was last seen"},
1058  {RPCResult::Type::NUM, "services",
1059  "The services offered by the node"},
1060  {RPCResult::Type::STR, "address",
1061  "The address of the node"},
1062  {RPCResult::Type::NUM, "port",
1063  "The port number of the node"},
1064  {RPCResult::Type::STR, "network",
1065  "The network (" + Join(GetNetworkNames(), ", ") +
1066  ") the node connected through"},
1067  }},
1068  }},
1069  RPCExamples{HelpExampleCli("getnodeaddresses", "8") +
1070  HelpExampleCli("getnodeaddresses", "4 \"i2p\"") +
1071  HelpExampleCli("-named getnodeaddresses",
1072  "network=onion count=12") +
1073  HelpExampleRpc("getnodeaddresses", "8") +
1074  HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")},
1075  [&](const RPCHelpMan &self, const Config &config,
1076  const JSONRPCRequest &request) -> UniValue {
1077  NodeContext &node = EnsureAnyNodeContext(request.context);
1078  const CConnman &connman = EnsureConnman(node);
1079 
1080  const int count{request.params[0].isNull()
1081  ? 1
1082  : request.params[0].getInt<int>()};
1083  if (count < 0) {
1085  "Address count out of range");
1086  }
1087 
1088  const std::optional<Network> network{
1089  request.params[1].isNull()
1090  ? std::nullopt
1091  : std::optional<Network>{
1092  ParseNetwork(request.params[1].get_str())}};
1093  if (network == NET_UNROUTABLE) {
1095  strprintf("Network not recognized: %s",
1096  request.params[1].get_str()));
1097  }
1098  // returns a shuffled list of CAddress
1099  const std::vector<CAddress> vAddr{
1100  connman.GetAddresses(count, /* max_pct */ 0, network)};
1101  UniValue ret(UniValue::VARR);
1102 
1103  for (const CAddress &addr : vAddr) {
1104  UniValue obj(UniValue::VOBJ);
1105  obj.pushKV(
1106  "time",
1107  int64_t{TicksSinceEpoch<std::chrono::seconds>(addr.nTime)});
1108  obj.pushKV("services", uint64_t(addr.nServices));
1109  obj.pushKV("address", addr.ToStringIP());
1110  obj.pushKV("port", addr.GetPort());
1111  obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
1112  ret.push_back(obj);
1113  }
1114  return ret;
1115  },
1116  };
1117 }
1118 
1120  return RPCHelpMan{
1121  "addpeeraddress",
1122  "Add the address of a potential peer to the address manager. This "
1123  "RPC is for testing only.\n",
1124  {
1126  "The IP address of the peer"},
1128  "The port of the peer"},
1129  {"tried", RPCArg::Type::BOOL, RPCArg::Default{false},
1130  "If true, attempt to add the peer to the tried addresses table"},
1131  },
1132  RPCResult{
1134  "",
1135  "",
1136  {
1137  {RPCResult::Type::BOOL, "success",
1138  "whether the peer address was successfully added to the "
1139  "address manager"},
1140  },
1141  },
1142  RPCExamples{
1143  HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true") +
1144  HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")},
1145  [&](const RPCHelpMan &self, const Config &config,
1146  const JSONRPCRequest &request) -> UniValue {
1147  NodeContext &node = EnsureAnyNodeContext(request.context);
1148  if (!node.addrman) {
1149  throw JSONRPCError(
1151  "Error: Address manager functionality missing or disabled");
1152  }
1153 
1154  const std::string &addr_string{request.params[0].get_str()};
1155  const uint16_t port{
1156  static_cast<uint16_t>(request.params[1].getInt<int>())};
1157  const bool tried{request.params[2].isTrue()};
1158 
1159  UniValue obj(UniValue::VOBJ);
1160  CNetAddr net_addr;
1161  bool success{false};
1162 
1163  if (LookupHost(addr_string, net_addr, false)) {
1164  CAddress address{{net_addr, port}, ServiceFlags(NODE_NETWORK)};
1165  address.nTime = AdjustedTime();
1166  // The source address is set equal to the address. This is
1167  // equivalent to the peer announcing itself.
1168  if (node.addrman->Add({address}, address)) {
1169  success = true;
1170  if (tried) {
1171  // Attempt to move the address to the tried addresses
1172  // table.
1173  node.addrman->Good(address);
1174  }
1175  }
1176  }
1177 
1178  obj.pushKV("success", success);
1179  return obj;
1180  },
1181  };
1182 }
1183 
1185  // clang-format off
1186  static const CRPCCommand commands[] = {
1187  // category actor (function)
1188  // ------------------ ----------------------
1189  { "network", getconnectioncount, },
1190  { "network", ping, },
1191  { "network", getpeerinfo, },
1192  { "network", addnode, },
1193  { "network", disconnectnode, },
1194  { "network", getaddednodeinfo, },
1195  { "network", getnettotals, },
1196  { "network", getnetworkinfo, },
1197  { "network", setban, },
1198  { "network", listbanned, },
1199  { "network", clearbanned, },
1200  { "network", setnetworkactive, },
1201  { "network", getnodeaddresses, },
1202  { "hidden", addconnection, },
1203  { "hidden", addpeeraddress, },
1204  };
1205  // clang-format on
1206  for (const auto &c : commands) {
1207  t.appendCommand(c.name, &c);
1208  }
1209 }
A CService with information about it as peer.
Definition: protocol.h:442
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:845
size_t GetNodeCount(NumConnections num) const
Definition: net.cpp:3249
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:3351
bool OutboundTargetReached(bool historicalBlockServingLimit) const
check if the outbound target is reached.
Definition: net.cpp:3367
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1415
bool RemoveAddedNode(const std::string &node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:3237
bool GetNetworkActive() const
Definition: net.h:938
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:3390
std::chrono::seconds GetMaxOutboundTimeframe() const
Definition: net.cpp:3347
bool DisconnectNode(const std::string &node)
Definition: net.cpp:3278
uint64_t GetMaxOutboundTarget() const
Definition: net.cpp:3342
@ CONNECTIONS_IN
Definition: net.h:849
@ CONNECTIONS_ALL
Definition: net.h:851
@ CONNECTIONS_OUT
Definition: net.h:850
void GetNodeStats(std::vector< CNodeStats > &vstats) const
Definition: net.cpp:3267
std::vector< AddedNodeInfo > GetAddedNodeInfo() const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:2472
uint64_t GetTotalBytesRecv() const
Definition: net.cpp:3401
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:3159
void SetNetworkActive(bool active)
Definition: net.cpp:2842
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2561
bool AddNode(const std::string &node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:3225
uint64_t GetTotalBytesSent() const
Definition: net.cpp:3405
Network address.
Definition: netaddress.h:121
bool IsValid() const
Definition: netaddress.cpp:479
RPC command dispatcher.
Definition: server.h:194
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:327
std::string ToStringIPPort() const
bool IsValid() const
Definition: config.h:19
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:664
void push_back(UniValue val)
Definition: univalue.cpp:96
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:31
@ VARR
Definition: univalue.h:32
bool isNull() const
Definition: univalue.h:104
bool isStr() const
Definition: univalue.h:108
Int getInt() const
Definition: univalue.h:157
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:115
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:38
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
static path absolute(const path &p)
Definition: fs.h:96
Definition: init.h:28
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:112
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:127
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
Definition: net.cpp:576
std::string userAgent(const Config &config)
Definition: net.cpp:3591
bool IsReachable(enum Network net)
Definition: net.cpp:325
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.h:138
ConnectionType
Different types of connections to a peer.
Definition: net.h:151
@ 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:44
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:62
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:69
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:47
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:66
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:335
@ NODE_NONE
Definition: protocol.h:338
@ NODE_NETWORK
Definition: protocol.h:342
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:58
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
Definition: net.cpp:1184
static RPCHelpMan getnetworkinfo()
Definition: net.cpp:706
static RPCHelpMan addconnection()
Definition: net.cpp:400
static RPCHelpMan getaddednodeinfo()
Definition: net.cpp:533
static RPCHelpMan clearbanned()
Definition: net.cpp:988
static RPCHelpMan getnettotals()
Definition: net.cpp:619
static RPCHelpMan addnode()
Definition: net.cpp:338
static RPCHelpMan getnodeaddresses()
Definition: net.cpp:1034
static RPCHelpMan setban()
Definition: net.cpp:835
static UniValue GetNetworksInfo()
Definition: net.cpp:684
static RPCHelpMan ping()
Definition: net.cpp:56
static RPCHelpMan getconnectioncount()
Definition: net.cpp:38
static RPCHelpMan disconnectnode()
Definition: net.cpp:478
static RPCHelpMan listbanned()
Definition: net.cpp:940
static RPCHelpMan setnetworkactive()
Definition: net.cpp:1012
static RPCHelpMan addpeeraddress()
Definition: net.cpp:1119
static RPCHelpMan getpeerinfo()
Definition: net.cpp:81
@ 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
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:150
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
Definition: util.cpp:1337
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:167
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:182
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:21
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:63
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:72
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:53
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
Definition: string.h:28
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:86
std::chrono::microseconds m_ping_wait
Amount m_fee_filter_received
std::vector< int > vHeightInFlight
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
int64_t presync_height
ServiceFlags their_services
POD that contains various stats about a node.
Definition: net.h:290
static const Currency & get()
Definition: amount.cpp:18
std::string ticker
Definition: amount.h:150
std::string DefaultHint
Hint for default value.
Definition: util.h:195
@ 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.
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43
#define LOCK(cs)
Definition: sync.h:306
static int count
Definition: tests.c:31
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:101
constexpr int64_t count_seconds(std::chrono::seconds t)
Definition: time.h:55
double CountSecondsDouble(SecondsDouble t)
Helper to count the seconds in any std::chrono::duration type.
Definition: time.h:72
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
Definition: timedata.cpp:30
NodeSeconds AdjustedTime()
Definition: timedata.h:70
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
const UniValue NullUniValue
Definition: univalue.cpp:16
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