Bitcoin ABC  0.29.2
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 
51  return int(connman.GetNodeCount(CConnman::CONNECTIONS_ALL));
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 (g_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  const ArgsManager &args{EnsureArgsman(node)};
437 
438  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR});
439  const std::string address = request.params[0].get_str();
440  const std::string conn_type_in{
441  TrimString(request.params[1].get_str())};
442  ConnectionType conn_type{};
443  if (conn_type_in == "outbound-full-relay") {
445  } else if (conn_type_in == "block-relay-only") {
446  conn_type = ConnectionType::BLOCK_RELAY;
447  } else if (conn_type_in == "addr-fetch") {
448  conn_type = ConnectionType::ADDR_FETCH;
449  } else if (conn_type_in == "feeler") {
450  conn_type = ConnectionType::FEELER;
451  } else if (conn_type_in == "avalanche") {
452  if (!g_avalanche || !isAvalancheEnabled(args)) {
454  "Error: avalanche outbound requested "
455  "but avalanche is not enabled.");
456  }
458  } else {
460  }
461 
462  CConnman &connman = EnsureConnman(node);
463 
464  const bool success = connman.AddConnection(address, conn_type);
465  if (!success) {
467  "Error: Already at capacity for specified "
468  "connection type.");
469  }
470 
471  UniValue info(UniValue::VOBJ);
472  info.pushKV("address", address);
473  info.pushKV("connection_type", conn_type_in);
474 
475  return info;
476  },
477  };
478 }
479 
481  return RPCHelpMan{
482  "disconnectnode",
483  "Immediately disconnects from the specified peer node.\n"
484  "\nStrictly one out of 'address' and 'nodeid' can be provided to "
485  "identify the node.\n"
486  "\nTo disconnect by nodeid, either set 'address' to the empty string, "
487  "or call using the named 'nodeid' argument only.\n",
488  {
489  {"address", RPCArg::Type::STR,
490  RPCArg::DefaultHint{"fallback to nodeid"},
491  "The IP address/port of the node"},
492  {"nodeid", RPCArg::Type::NUM,
493  RPCArg::DefaultHint{"fallback to address"},
494  "The node ID (see getpeerinfo for node IDs)"},
495  },
497  RPCExamples{HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") +
498  HelpExampleCli("disconnectnode", "\"\" 1") +
499  HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") +
500  HelpExampleRpc("disconnectnode", "\"\", 1")},
501  [&](const RPCHelpMan &self, const Config &config,
502  const JSONRPCRequest &request) -> UniValue {
503  NodeContext &node = EnsureAnyNodeContext(request.context);
504  CConnman &connman = EnsureConnman(node);
505 
506  bool success;
507  const UniValue &address_arg = request.params[0];
508  const UniValue &id_arg = request.params[1];
509 
510  if (!address_arg.isNull() && id_arg.isNull()) {
511  /* handle disconnect-by-address */
512  success = connman.DisconnectNode(address_arg.get_str());
513  } else if (!id_arg.isNull() && (address_arg.isNull() ||
514  (address_arg.isStr() &&
515  address_arg.get_str().empty()))) {
516  /* handle disconnect-by-id */
517  NodeId nodeid = (NodeId)id_arg.get_int64();
518  success = connman.DisconnectNode(nodeid);
519  } else {
520  throw JSONRPCError(
522  "Only one of address and nodeid should be provided.");
523  }
524 
525  if (!success) {
527  "Node not found in connected nodes");
528  }
529 
530  return NullUniValue;
531  },
532  };
533 }
534 
536  return RPCHelpMan{
537  "getaddednodeinfo",
538  "Returns information about the given added node, or all added nodes\n"
539  "(note that onetry addnodes are not listed here)\n",
540  {
541  {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"},
542  "If provided, return information about this specific node, "
543  "otherwise all nodes are returned."},
544  },
545  RPCResult{
547  "",
548  "",
549  {
551  "",
552  "",
553  {
554  {RPCResult::Type::STR, "addednode",
555  "The node IP address or name (as provided to addnode)"},
556  {RPCResult::Type::BOOL, "connected", "If connected"},
558  "addresses",
559  "Only when connected = true",
560  {
562  "",
563  "",
564  {
565  {RPCResult::Type::STR, "address",
566  "The bitcoin server IP and port we're "
567  "connected to"},
568  {RPCResult::Type::STR, "connected",
569  "connection, inbound or outbound"},
570  }},
571  }},
572  }},
573  }},
574  RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") +
575  HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")},
576  [&](const RPCHelpMan &self, const Config &config,
577  const JSONRPCRequest &request) -> UniValue {
578  NodeContext &node = EnsureAnyNodeContext(request.context);
579  const CConnman &connman = EnsureConnman(node);
580 
581  std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo();
582 
583  if (!request.params[0].isNull()) {
584  bool found = false;
585  for (const AddedNodeInfo &info : vInfo) {
586  if (info.strAddedNode == request.params[0].get_str()) {
587  vInfo.assign(1, info);
588  found = true;
589  break;
590  }
591  }
592  if (!found) {
594  "Error: Node has not been added.");
595  }
596  }
597 
599 
600  for (const AddedNodeInfo &info : vInfo) {
602  obj.pushKV("addednode", info.strAddedNode);
603  obj.pushKV("connected", info.fConnected);
604  UniValue addresses(UniValue::VARR);
605  if (info.fConnected) {
606  UniValue address(UniValue::VOBJ);
607  address.pushKV("address", info.resolvedAddress.ToString());
608  address.pushKV("connected",
609  info.fInbound ? "inbound" : "outbound");
610  addresses.push_back(address);
611  }
612  obj.pushKV("addresses", addresses);
613  ret.push_back(obj);
614  }
615 
616  return ret;
617  },
618  };
619 }
620 
622  return RPCHelpMan{
623  "getnettotals",
624  "Returns information about network traffic, including bytes in, "
625  "bytes out,\n"
626  "and current time.\n",
627  {},
628  RPCResult{
630  "",
631  "",
632  {
633  {RPCResult::Type::NUM, "totalbytesrecv",
634  "Total bytes received"},
635  {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"},
636  {RPCResult::Type::NUM_TIME, "timemillis",
637  "Current " + UNIX_EPOCH_TIME + " in milliseconds"},
639  "uploadtarget",
640  "",
641  {
642  {RPCResult::Type::NUM, "timeframe",
643  "Length of the measuring timeframe in seconds"},
644  {RPCResult::Type::NUM, "target", "Target in bytes"},
645  {RPCResult::Type::BOOL, "target_reached",
646  "True if target is reached"},
647  {RPCResult::Type::BOOL, "serve_historical_blocks",
648  "True if serving historical blocks"},
649  {RPCResult::Type::NUM, "bytes_left_in_cycle",
650  "Bytes left in current time cycle"},
651  {RPCResult::Type::NUM, "time_left_in_cycle",
652  "Seconds left in current time cycle"},
653  }},
654  }},
655  RPCExamples{HelpExampleCli("getnettotals", "") +
656  HelpExampleRpc("getnettotals", "")},
657  [&](const RPCHelpMan &self, const Config &config,
658  const JSONRPCRequest &request) -> UniValue {
659  NodeContext &node = EnsureAnyNodeContext(request.context);
660  const CConnman &connman = EnsureConnman(node);
661 
663  obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv());
664  obj.pushKV("totalbytessent", connman.GetTotalBytesSent());
665  obj.pushKV("timemillis", GetTimeMillis());
666 
667  UniValue outboundLimit(UniValue::VOBJ);
668  outboundLimit.pushKV(
669  "timeframe", count_seconds(connman.GetMaxOutboundTimeframe()));
670  outboundLimit.pushKV("target", connman.GetMaxOutboundTarget());
671  outboundLimit.pushKV("target_reached",
672  connman.OutboundTargetReached(false));
673  outboundLimit.pushKV("serve_historical_blocks",
674  !connman.OutboundTargetReached(true));
675  outboundLimit.pushKV("bytes_left_in_cycle",
676  connman.GetOutboundTargetBytesLeft());
677  outboundLimit.pushKV(
678  "time_left_in_cycle",
680  obj.pushKV("uploadtarget", outboundLimit);
681  return obj;
682  },
683  };
684 }
685 
687  UniValue networks(UniValue::VARR);
688  for (int n = 0; n < NET_MAX; ++n) {
689  enum Network network = static_cast<enum Network>(n);
690  if (network == NET_UNROUTABLE || network == NET_CJDNS ||
691  network == NET_INTERNAL) {
692  continue;
693  }
694  proxyType proxy;
696  GetProxy(network, proxy);
697  obj.pushKV("name", GetNetworkName(network));
698  obj.pushKV("limited", !IsReachable(network));
699  obj.pushKV("reachable", IsReachable(network));
700  obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort()
701  : std::string());
702  obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
703  networks.push_back(obj);
704  }
705  return networks;
706 }
707 
709  const auto &ticker = Currency::get().ticker;
710  return RPCHelpMan{
711  "getnetworkinfo",
712  "Returns an object containing various state info regarding P2P "
713  "networking.\n",
714  {},
715  RPCResult{
717  "",
718  "",
719  {
720  {RPCResult::Type::NUM, "version", "the server version"},
721  {RPCResult::Type::STR, "subversion",
722  "the server subversion string"},
723  {RPCResult::Type::NUM, "protocolversion",
724  "the protocol version"},
725  {RPCResult::Type::STR_HEX, "localservices",
726  "the services we offer to the network"},
728  "localservicesnames",
729  "the services we offer to the network, in human-readable form",
730  {
731  {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
732  }},
733  {RPCResult::Type::BOOL, "localrelay",
734  "true if transaction relay is requested from peers"},
735  {RPCResult::Type::NUM, "timeoffset", "the time offset"},
736  {RPCResult::Type::NUM, "connections",
737  "the total number of connections"},
738  {RPCResult::Type::NUM, "connections_in",
739  "the number of inbound connections"},
740  {RPCResult::Type::NUM, "connections_out",
741  "the number of outbound connections"},
742  {RPCResult::Type::BOOL, "networkactive",
743  "whether p2p networking is enabled"},
745  "networks",
746  "information per network",
747  {
749  "",
750  "",
751  {
752  {RPCResult::Type::STR, "name",
753  "network (" + Join(GetNetworkNames(), ", ") + ")"},
754  {RPCResult::Type::BOOL, "limited",
755  "is the network limited using -onlynet?"},
756  {RPCResult::Type::BOOL, "reachable",
757  "is the network reachable?"},
758  {RPCResult::Type::STR, "proxy",
759  "(\"host:port\") the proxy that is used for this "
760  "network, or empty if none"},
761  {RPCResult::Type::BOOL, "proxy_randomize_credentials",
762  "Whether randomized credentials are used"},
763  }},
764  }},
765  {RPCResult::Type::NUM, "relayfee",
766  "minimum relay fee for transactions in " + ticker + "/kB"},
768  "localaddresses",
769  "list of local addresses",
770  {
772  "",
773  "",
774  {
775  {RPCResult::Type::STR, "address", "network address"},
776  {RPCResult::Type::NUM, "port", "network port"},
777  {RPCResult::Type::NUM, "score", "relative score"},
778  }},
779  }},
780  {RPCResult::Type::STR, "warnings",
781  "any network and blockchain warnings"},
782  }},
783  RPCExamples{HelpExampleCli("getnetworkinfo", "") +
784  HelpExampleRpc("getnetworkinfo", "")},
785  [&](const RPCHelpMan &self, const Config &config,
786  const JSONRPCRequest &request) -> UniValue {
787  LOCK(cs_main);
789  obj.pushKV("version", CLIENT_VERSION);
790  obj.pushKV("subversion", userAgent(config));
791  obj.pushKV("protocolversion", PROTOCOL_VERSION);
792  NodeContext &node = EnsureAnyNodeContext(request.context);
793  if (node.connman) {
794  ServiceFlags services = node.connman->GetLocalServices();
795  obj.pushKV("localservices", strprintf("%016x", services));
796  obj.pushKV("localservicesnames", GetServicesNames(services));
797  }
798  if (node.peerman) {
799  obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
800  }
801  obj.pushKV("timeoffset", GetTimeOffset());
802  if (node.connman) {
803  obj.pushKV("networkactive", node.connman->GetNetworkActive());
804  obj.pushKV("connections", int(node.connman->GetNodeCount(
806  obj.pushKV("connections_in", int(node.connman->GetNodeCount(
808  obj.pushKV("connections_out", int(node.connman->GetNodeCount(
810  }
811  obj.pushKV("networks", GetNetworksInfo());
812  if (node.mempool) {
813  // This field can be deprecated, to be replaced by the
814  // getmempoolinfo fields
815  obj.pushKV("relayfee",
816  node.mempool->m_min_relay_feerate.GetFeePerK());
817  }
818  UniValue localAddresses(UniValue::VARR);
819  {
821  for (const std::pair<const CNetAddr, LocalServiceInfo> &item :
822  mapLocalHost) {
824  rec.pushKV("address", item.first.ToString());
825  rec.pushKV("port", item.second.nPort);
826  rec.pushKV("score", item.second.nScore);
827  localAddresses.push_back(rec);
828  }
829  }
830  obj.pushKV("localaddresses", localAddresses);
831  obj.pushKV("warnings", GetWarnings(false).original);
832  return obj;
833  },
834  };
835 }
836 
837 static RPCHelpMan setban() {
838  return RPCHelpMan{
839  "setban",
840  "Attempts to add or remove an IP/Subnet from the banned list.\n",
841  {
843  "The IP/Subnet (see getpeerinfo for nodes IP) with an optional "
844  "netmask (default is /32 = single IP)"},
846  "'add' to add an IP/Subnet to the list, 'remove' to remove an "
847  "IP/Subnet from the list"},
848  {"bantime", RPCArg::Type::NUM, RPCArg::Default{0},
849  "time in seconds how long (or until when if [absolute] is set) "
850  "the IP is banned (0 or empty means using the default time of 24h "
851  "which can also be overwritten by the -bantime startup argument)"},
852  {"absolute", RPCArg::Type::BOOL, RPCArg::Default{false},
853  "If set, the bantime must be an absolute timestamp expressed in " +
855  },
857  RPCExamples{
858  HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") +
859  HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") +
860  HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")},
861  [&](const RPCHelpMan &help, const Config &config,
862  const JSONRPCRequest &request) -> UniValue {
863  std::string strCommand;
864  if (!request.params[1].isNull()) {
865  strCommand = request.params[1].get_str();
866  }
867 
868  if (strCommand != "add" && strCommand != "remove") {
869  throw std::runtime_error(help.ToString());
870  }
871 
872  NodeContext &node = EnsureAnyNodeContext(request.context);
873  if (!node.banman) {
875  "Error: Ban database not loaded");
876  }
877 
878  CSubNet subNet;
879  CNetAddr netAddr;
880  bool isSubnet = false;
881 
882  if (request.params[0].get_str().find('/') != std::string::npos) {
883  isSubnet = true;
884  }
885 
886  if (!isSubnet) {
887  CNetAddr resolved;
888  LookupHost(request.params[0].get_str(), resolved, false);
889  netAddr = resolved;
890  } else {
891  LookupSubNet(request.params[0].get_str(), subNet);
892  }
893 
894  if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) {
896  "Error: Invalid IP/Subnet");
897  }
898 
899  if (strCommand == "add") {
900  if (isSubnet ? node.banman->IsBanned(subNet)
901  : node.banman->IsBanned(netAddr)) {
903  "Error: IP/Subnet already banned");
904  }
905 
906  // Use standard bantime if not specified.
907  int64_t banTime = 0;
908  if (!request.params[2].isNull()) {
909  banTime = request.params[2].get_int64();
910  }
911 
912  bool absolute = false;
913  if (request.params[3].isTrue()) {
914  absolute = true;
915  }
916 
917  if (isSubnet) {
918  node.banman->Ban(subNet, banTime, absolute);
919  if (node.connman) {
920  node.connman->DisconnectNode(subNet);
921  }
922  } else {
923  node.banman->Ban(netAddr, banTime, absolute);
924  if (node.connman) {
925  node.connman->DisconnectNode(netAddr);
926  }
927  }
928  } else if (strCommand == "remove") {
929  if (!(isSubnet ? node.banman->Unban(subNet)
930  : node.banman->Unban(netAddr))) {
931  throw JSONRPCError(
933  "Error: Unban failed. Requested address/subnet "
934  "was not previously manually banned.");
935  }
936  }
937  return NullUniValue;
938  },
939  };
940 }
941 
943  return RPCHelpMan{
944  "listbanned",
945  "List all manually banned IPs/Subnets.\n",
946  {},
948  "",
949  "",
950  {
952  "",
953  "",
954  {
955  {RPCResult::Type::STR, "address", ""},
956  {RPCResult::Type::NUM_TIME, "banned_until", ""},
957  {RPCResult::Type::NUM_TIME, "ban_created", ""},
958  {RPCResult::Type::STR, "ban_reason", ""},
959  }},
960  }},
961  RPCExamples{HelpExampleCli("listbanned", "") +
962  HelpExampleRpc("listbanned", "")},
963  [&](const RPCHelpMan &self, const Config &config,
964  const JSONRPCRequest &request) -> UniValue {
965  NodeContext &node = EnsureAnyNodeContext(request.context);
966  if (!node.banman) {
968  "Error: Ban database not loaded");
969  }
970 
971  banmap_t banMap;
972  node.banman->GetBanned(banMap);
973 
974  UniValue bannedAddresses(UniValue::VARR);
975  for (const auto &entry : banMap) {
976  const CBanEntry &banEntry = entry.second;
978  rec.pushKV("address", entry.first.ToString());
979  rec.pushKV("banned_until", banEntry.nBanUntil);
980  rec.pushKV("ban_created", banEntry.nCreateTime);
981 
982  bannedAddresses.push_back(rec);
983  }
984 
985  return bannedAddresses;
986  },
987  };
988 }
989 
991  return RPCHelpMan{
992  "clearbanned",
993  "Clear all banned IPs.\n",
994  {},
996  RPCExamples{HelpExampleCli("clearbanned", "") +
997  HelpExampleRpc("clearbanned", "")},
998  [&](const RPCHelpMan &self, const Config &config,
999  const JSONRPCRequest &request) -> UniValue {
1000  NodeContext &node = EnsureAnyNodeContext(request.context);
1001  if (!node.banman) {
1002  throw JSONRPCError(
1004  "Error: Peer-to-peer functionality missing or disabled");
1005  }
1006 
1007  node.banman->ClearBanned();
1008 
1009  return NullUniValue;
1010  },
1011  };
1012 }
1013 
1015  return RPCHelpMan{
1016  "setnetworkactive",
1017  "Disable/enable all p2p network activity.\n",
1018  {
1020  "true to enable networking, false to disable"},
1021  },
1022  RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
1023  RPCExamples{""},
1024  [&](const RPCHelpMan &self, const Config &config,
1025  const JSONRPCRequest &request) -> UniValue {
1026  NodeContext &node = EnsureAnyNodeContext(request.context);
1027  CConnman &connman = EnsureConnman(node);
1028 
1029  connman.SetNetworkActive(request.params[0].get_bool());
1030 
1031  return connman.GetNetworkActive();
1032  },
1033  };
1034 }
1035 
1037  return RPCHelpMan{
1038  "getnodeaddresses",
1039  "Return known addresses, which can potentially be used to find new "
1040  "nodes in the network.\n",
1041  {
1042  {"count", RPCArg::Type::NUM, RPCArg::Default{1},
1043  "The maximum number of addresses to return. Specify 0 to return "
1044  "all known addresses."},
1045  {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"},
1046  "Return only addresses of the specified network. Can be one of: " +
1047  Join(GetNetworkNames(), ", ") + "."},
1048  },
1050  "",
1051  "",
1052  {
1054  "",
1055  "",
1056  {
1057  {RPCResult::Type::NUM_TIME, "time",
1058  "The " + UNIX_EPOCH_TIME +
1059  " when the node was last seen"},
1060  {RPCResult::Type::NUM, "services",
1061  "The services offered by the node"},
1062  {RPCResult::Type::STR, "address",
1063  "The address of the node"},
1064  {RPCResult::Type::NUM, "port",
1065  "The port number of the node"},
1066  {RPCResult::Type::STR, "network",
1067  "The network (" + Join(GetNetworkNames(), ", ") +
1068  ") the node connected through"},
1069  }},
1070  }},
1071  RPCExamples{HelpExampleCli("getnodeaddresses", "8") +
1072  HelpExampleCli("getnodeaddresses", "4 \"i2p\"") +
1073  HelpExampleCli("-named getnodeaddresses",
1074  "network=onion count=12") +
1075  HelpExampleRpc("getnodeaddresses", "8") +
1076  HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")},
1077  [&](const RPCHelpMan &self, const Config &config,
1078  const JSONRPCRequest &request) -> UniValue {
1079  NodeContext &node = EnsureAnyNodeContext(request.context);
1080  const CConnman &connman = EnsureConnman(node);
1081 
1082  const int count{
1083  request.params[0].isNull() ? 1 : request.params[0].get_int()};
1084  if (count < 0) {
1086  "Address count out of range");
1087  }
1088 
1089  const std::optional<Network> network{
1090  request.params[1].isNull()
1091  ? std::nullopt
1092  : std::optional<Network>{
1093  ParseNetwork(request.params[1].get_str())}};
1094  if (network == NET_UNROUTABLE) {
1096  strprintf("Network not recognized: %s",
1097  request.params[1].get_str()));
1098  }
1099  // returns a shuffled list of CAddress
1100  const std::vector<CAddress> vAddr{
1101  connman.GetAddresses(count, /* max_pct */ 0, network)};
1102  UniValue ret(UniValue::VARR);
1103 
1104  for (const CAddress &addr : vAddr) {
1105  UniValue obj(UniValue::VOBJ);
1106  obj.pushKV(
1107  "time",
1108  int64_t{TicksSinceEpoch<std::chrono::seconds>(addr.nTime)});
1109  obj.pushKV("services", uint64_t(addr.nServices));
1110  obj.pushKV("address", addr.ToStringIP());
1111  obj.pushKV("port", addr.GetPort());
1112  obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
1113  ret.push_back(obj);
1114  }
1115  return ret;
1116  },
1117  };
1118 }
1119 
1121  return RPCHelpMan{
1122  "addpeeraddress",
1123  "Add the address of a potential peer to the address manager. This "
1124  "RPC is for testing only.\n",
1125  {
1127  "The IP address of the peer"},
1129  "The port of the peer"},
1130  {"tried", RPCArg::Type::BOOL, RPCArg::Default{false},
1131  "If true, attempt to add the peer to the tried addresses table"},
1132  },
1133  RPCResult{
1135  "",
1136  "",
1137  {
1138  {RPCResult::Type::BOOL, "success",
1139  "whether the peer address was successfully added to the "
1140  "address manager"},
1141  },
1142  },
1143  RPCExamples{
1144  HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true") +
1145  HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")},
1146  [&](const RPCHelpMan &self, const Config &config,
1147  const JSONRPCRequest &request) -> UniValue {
1148  NodeContext &node = EnsureAnyNodeContext(request.context);
1149  if (!node.addrman) {
1150  throw JSONRPCError(
1152  "Error: Address manager functionality missing or disabled");
1153  }
1154 
1155  const std::string &addr_string{request.params[0].get_str()};
1156  const uint16_t port{
1157  static_cast<uint16_t>(request.params[1].get_int())};
1158  const bool tried{request.params[2].isTrue()};
1159 
1160  UniValue obj(UniValue::VOBJ);
1161  CNetAddr net_addr;
1162  bool success{false};
1163 
1164  if (LookupHost(addr_string, net_addr, false)) {
1165  CAddress address{{net_addr, port}, ServiceFlags(NODE_NETWORK)};
1166  address.nTime = AdjustedTime();
1167  // The source address is set equal to the address. This is
1168  // equivalent to the peer announcing itself.
1169  if (node.addrman->Add({address}, address)) {
1170  success = true;
1171  if (tried) {
1172  // Attempt to move the address to the tried addresses
1173  // table.
1174  node.addrman->Good(address);
1175  }
1176  }
1177  }
1178 
1179  obj.pushKV("success", success);
1180  return obj;
1181  },
1182  };
1183 }
1184 
1186  // clang-format off
1187  static const CRPCCommand commands[] = {
1188  // category actor (function)
1189  // ------------------ ----------------------
1190  { "network", getconnectioncount, },
1191  { "network", ping, },
1192  { "network", getpeerinfo, },
1193  { "network", addnode, },
1194  { "network", disconnectnode, },
1195  { "network", getaddednodeinfo, },
1196  { "network", getnettotals, },
1197  { "network", getnetworkinfo, },
1198  { "network", setban, },
1199  { "network", listbanned, },
1200  { "network", clearbanned, },
1201  { "network", setnetworkactive, },
1202  { "network", getnodeaddresses, },
1203  { "hidden", addconnection, },
1204  { "hidden", addpeeraddress, },
1205  };
1206  // clang-format on
1207  for (const auto &c : commands) {
1208  t.appendCommand(c.name, &c);
1209  }
1210 }
bool isAvalancheEnabled(const ArgsManager &argsman)
Definition: avalanche.cpp:9
std::unique_ptr< avalanche::Processor > g_avalanche
Global avalanche instance.
Definition: processor.cpp:38
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:1414
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:183
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:330
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:626
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: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:111
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:126
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
Definition: net.cpp:575
std::string userAgent(const Config &config)
Definition: net.cpp:3591
bool IsReachable(enum Network net)
Definition: net.cpp:324
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:57
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
Definition: net.cpp:1185
static RPCHelpMan getnetworkinfo()
Definition: net.cpp:708
static RPCHelpMan addconnection()
Definition: net.cpp:400
static RPCHelpMan getaddednodeinfo()
Definition: net.cpp:535
static RPCHelpMan clearbanned()
Definition: net.cpp:990
static RPCHelpMan getnettotals()
Definition: net.cpp:621
static RPCHelpMan addnode()
Definition: net.cpp:338
static RPCHelpMan getnodeaddresses()
Definition: net.cpp:1036
static RPCHelpMan setban()
Definition: net.cpp:837
static UniValue GetNetworksInfo()
Definition: net.cpp:686
static RPCHelpMan ping()
Definition: net.cpp:56
static RPCHelpMan getconnectioncount()
Definition: net.cpp:38
static RPCHelpMan disconnectnode()
Definition: net.cpp:480
static RPCHelpMan listbanned()
Definition: net.cpp:942
static RPCHelpMan setnetworkactive()
Definition: net.cpp:1014
static RPCHelpMan addpeeraddress()
Definition: net.cpp:1120
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
void RPCTypeCheck(const UniValue &params, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: util.cpp:24
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:175
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
Definition: util.cpp:1107
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:192
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:20
static RPCHelpMan help()
Definition: server.cpp:180
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition: server_util.cpp:39
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:19
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:61
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:70
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:54
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
Definition: string.h:29
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:87
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
Definition: util.h:173
@ 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:38
#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:29
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:13
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