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 
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  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR});
436  const std::string address = request.params[0].get_str();
437  const std::string conn_type_in{
438  TrimString(request.params[1].get_str())};
439  ConnectionType conn_type{};
440  if (conn_type_in == "outbound-full-relay") {
442  } else if (conn_type_in == "block-relay-only") {
443  conn_type = ConnectionType::BLOCK_RELAY;
444  } else if (conn_type_in == "addr-fetch") {
445  conn_type = ConnectionType::ADDR_FETCH;
446  } else if (conn_type_in == "feeler") {
447  conn_type = ConnectionType::FEELER;
448  } else if (conn_type_in == "avalanche") {
451  "Error: avalanche outbound requested "
452  "but avalanche is not enabled.");
453  }
455  } else {
457  }
458 
459  NodeContext &node = EnsureAnyNodeContext(request.context);
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.get_int64();
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", int(node.connman->GetNodeCount(
804  obj.pushKV("connections_in", int(node.connman->GetNodeCount(
806  obj.pushKV("connections_out", int(node.connman->GetNodeCount(
808  }
809  obj.pushKV("networks", GetNetworksInfo());
810  obj.pushKV("relayfee", ::minRelayTxFee.GetFeePerK());
811  UniValue localAddresses(UniValue::VARR);
812  {
814  for (const std::pair<const CNetAddr, LocalServiceInfo> &item :
815  mapLocalHost) {
817  rec.pushKV("address", item.first.ToString());
818  rec.pushKV("port", item.second.nPort);
819  rec.pushKV("score", item.second.nScore);
820  localAddresses.push_back(rec);
821  }
822  }
823  obj.pushKV("localaddresses", localAddresses);
824  obj.pushKV("warnings", GetWarnings(false).original);
825  return obj;
826  },
827  };
828 }
829 
830 static RPCHelpMan setban() {
831  return RPCHelpMan{
832  "setban",
833  "Attempts to add or remove an IP/Subnet from the banned list.\n",
834  {
836  "The IP/Subnet (see getpeerinfo for nodes IP) with an optional "
837  "netmask (default is /32 = single IP)"},
839  "'add' to add an IP/Subnet to the list, 'remove' to remove an "
840  "IP/Subnet from the list"},
841  {"bantime", RPCArg::Type::NUM, RPCArg::Default{0},
842  "time in seconds how long (or until when if [absolute] is set) "
843  "the IP is banned (0 or empty means using the default time of 24h "
844  "which can also be overwritten by the -bantime startup argument)"},
845  {"absolute", RPCArg::Type::BOOL, RPCArg::Default{false},
846  "If set, the bantime must be an absolute timestamp expressed in " +
848  },
850  RPCExamples{
851  HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") +
852  HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") +
853  HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")},
854  [&](const RPCHelpMan &help, const Config &config,
855  const JSONRPCRequest &request) -> UniValue {
856  std::string strCommand;
857  if (!request.params[1].isNull()) {
858  strCommand = request.params[1].get_str();
859  }
860 
861  if (strCommand != "add" && strCommand != "remove") {
862  throw std::runtime_error(help.ToString());
863  }
864 
865  NodeContext &node = EnsureAnyNodeContext(request.context);
866  if (!node.banman) {
868  "Error: Ban database not loaded");
869  }
870 
871  CSubNet subNet;
872  CNetAddr netAddr;
873  bool isSubnet = false;
874 
875  if (request.params[0].get_str().find('/') != std::string::npos) {
876  isSubnet = true;
877  }
878 
879  if (!isSubnet) {
880  CNetAddr resolved;
881  LookupHost(request.params[0].get_str(), resolved, false);
882  netAddr = resolved;
883  } else {
884  LookupSubNet(request.params[0].get_str(), subNet);
885  }
886 
887  if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) {
889  "Error: Invalid IP/Subnet");
890  }
891 
892  if (strCommand == "add") {
893  if (isSubnet ? node.banman->IsBanned(subNet)
894  : node.banman->IsBanned(netAddr)) {
896  "Error: IP/Subnet already banned");
897  }
898 
899  // Use standard bantime if not specified.
900  int64_t banTime = 0;
901  if (!request.params[2].isNull()) {
902  banTime = request.params[2].get_int64();
903  }
904 
905  bool absolute = false;
906  if (request.params[3].isTrue()) {
907  absolute = true;
908  }
909 
910  if (isSubnet) {
911  node.banman->Ban(subNet, banTime, absolute);
912  if (node.connman) {
913  node.connman->DisconnectNode(subNet);
914  }
915  } else {
916  node.banman->Ban(netAddr, banTime, absolute);
917  if (node.connman) {
918  node.connman->DisconnectNode(netAddr);
919  }
920  }
921  } else if (strCommand == "remove") {
922  if (!(isSubnet ? node.banman->Unban(subNet)
923  : node.banman->Unban(netAddr))) {
924  throw JSONRPCError(
926  "Error: Unban failed. Requested address/subnet "
927  "was not previously manually banned.");
928  }
929  }
930  return NullUniValue;
931  },
932  };
933 }
934 
936  return RPCHelpMan{
937  "listbanned",
938  "List all manually banned IPs/Subnets.\n",
939  {},
941  "",
942  "",
943  {
945  "",
946  "",
947  {
948  {RPCResult::Type::STR, "address", ""},
949  {RPCResult::Type::NUM_TIME, "banned_until", ""},
950  {RPCResult::Type::NUM_TIME, "ban_created", ""},
951  {RPCResult::Type::STR, "ban_reason", ""},
952  }},
953  }},
954  RPCExamples{HelpExampleCli("listbanned", "") +
955  HelpExampleRpc("listbanned", "")},
956  [&](const RPCHelpMan &self, const Config &config,
957  const JSONRPCRequest &request) -> UniValue {
958  NodeContext &node = EnsureAnyNodeContext(request.context);
959  if (!node.banman) {
961  "Error: Ban database not loaded");
962  }
963 
964  banmap_t banMap;
965  node.banman->GetBanned(banMap);
966 
967  UniValue bannedAddresses(UniValue::VARR);
968  for (const auto &entry : banMap) {
969  const CBanEntry &banEntry = entry.second;
971  rec.pushKV("address", entry.first.ToString());
972  rec.pushKV("banned_until", banEntry.nBanUntil);
973  rec.pushKV("ban_created", banEntry.nCreateTime);
974 
975  bannedAddresses.push_back(rec);
976  }
977 
978  return bannedAddresses;
979  },
980  };
981 }
982 
984  return RPCHelpMan{
985  "clearbanned",
986  "Clear all banned IPs.\n",
987  {},
989  RPCExamples{HelpExampleCli("clearbanned", "") +
990  HelpExampleRpc("clearbanned", "")},
991  [&](const RPCHelpMan &self, const Config &config,
992  const JSONRPCRequest &request) -> UniValue {
993  NodeContext &node = EnsureAnyNodeContext(request.context);
994  if (!node.banman) {
995  throw JSONRPCError(
997  "Error: Peer-to-peer functionality missing or disabled");
998  }
999 
1000  node.banman->ClearBanned();
1001 
1002  return NullUniValue;
1003  },
1004  };
1005 }
1006 
1008  return RPCHelpMan{
1009  "setnetworkactive",
1010  "Disable/enable all p2p network activity.\n",
1011  {
1013  "true to enable networking, false to disable"},
1014  },
1015  RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
1016  RPCExamples{""},
1017  [&](const RPCHelpMan &self, const Config &config,
1018  const JSONRPCRequest &request) -> UniValue {
1019  NodeContext &node = EnsureAnyNodeContext(request.context);
1020  CConnman &connman = EnsureConnman(node);
1021 
1022  connman.SetNetworkActive(request.params[0].get_bool());
1023 
1024  return connman.GetNetworkActive();
1025  },
1026  };
1027 }
1028 
1030  return RPCHelpMan{
1031  "getnodeaddresses",
1032  "Return known addresses, which can potentially be used to find new "
1033  "nodes in the network.\n",
1034  {
1035  {"count", RPCArg::Type::NUM, RPCArg::Default{1},
1036  "The maximum number of addresses to return. Specify 0 to return "
1037  "all known addresses."},
1038  {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"},
1039  "Return only addresses of the specified network. Can be one of: " +
1040  Join(GetNetworkNames(), ", ") + "."},
1041  },
1043  "",
1044  "",
1045  {
1047  "",
1048  "",
1049  {
1050  {RPCResult::Type::NUM_TIME, "time",
1051  "The " + UNIX_EPOCH_TIME +
1052  " when the node was last seen"},
1053  {RPCResult::Type::NUM, "services",
1054  "The services offered by the node"},
1055  {RPCResult::Type::STR, "address",
1056  "The address of the node"},
1057  {RPCResult::Type::NUM, "port",
1058  "The port number of the node"},
1059  {RPCResult::Type::STR, "network",
1060  "The network (" + Join(GetNetworkNames(), ", ") +
1061  ") the node connected through"},
1062  }},
1063  }},
1064  RPCExamples{HelpExampleCli("getnodeaddresses", "8") +
1065  HelpExampleCli("getnodeaddresses", "4 \"i2p\"") +
1066  HelpExampleCli("-named getnodeaddresses",
1067  "network=onion count=12") +
1068  HelpExampleRpc("getnodeaddresses", "8") +
1069  HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")},
1070  [&](const RPCHelpMan &self, const Config &config,
1071  const JSONRPCRequest &request) -> UniValue {
1072  NodeContext &node = EnsureAnyNodeContext(request.context);
1073  const CConnman &connman = EnsureConnman(node);
1074 
1075  const int count{
1076  request.params[0].isNull() ? 1 : request.params[0].get_int()};
1077  if (count < 0) {
1079  "Address count out of range");
1080  }
1081 
1082  const std::optional<Network> network{
1083  request.params[1].isNull()
1084  ? std::nullopt
1085  : std::optional<Network>{
1086  ParseNetwork(request.params[1].get_str())}};
1087  if (network == NET_UNROUTABLE) {
1089  strprintf("Network not recognized: %s",
1090  request.params[1].get_str()));
1091  }
1092  // returns a shuffled list of CAddress
1093  const std::vector<CAddress> vAddr{
1094  connman.GetAddresses(count, /* max_pct */ 0, network)};
1095  UniValue ret(UniValue::VARR);
1096 
1097  for (const CAddress &addr : vAddr) {
1098  UniValue obj(UniValue::VOBJ);
1099  obj.pushKV(
1100  "time",
1101  int64_t{TicksSinceEpoch<std::chrono::seconds>(addr.nTime)});
1102  obj.pushKV("services", uint64_t(addr.nServices));
1103  obj.pushKV("address", addr.ToStringIP());
1104  obj.pushKV("port", addr.GetPort());
1105  obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
1106  ret.push_back(obj);
1107  }
1108  return ret;
1109  },
1110  };
1111 }
1112 
1114  return RPCHelpMan{
1115  "addpeeraddress",
1116  "Add the address of a potential peer to the address manager. This "
1117  "RPC is for testing only.\n",
1118  {
1120  "The IP address of the peer"},
1122  "The port of the peer"},
1123  {"tried", RPCArg::Type::BOOL, RPCArg::Default{false},
1124  "If true, attempt to add the peer to the tried addresses table"},
1125  },
1126  RPCResult{
1128  "",
1129  "",
1130  {
1131  {RPCResult::Type::BOOL, "success",
1132  "whether the peer address was successfully added to the "
1133  "address manager"},
1134  },
1135  },
1136  RPCExamples{
1137  HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true") +
1138  HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")},
1139  [&](const RPCHelpMan &self, const Config &config,
1140  const JSONRPCRequest &request) -> UniValue {
1141  NodeContext &node = EnsureAnyNodeContext(request.context);
1142  if (!node.addrman) {
1143  throw JSONRPCError(
1145  "Error: Address manager functionality missing or disabled");
1146  }
1147 
1148  const std::string &addr_string{request.params[0].get_str()};
1149  const uint16_t port{
1150  static_cast<uint16_t>(request.params[1].get_int())};
1151  const bool tried{request.params[2].isTrue()};
1152 
1153  UniValue obj(UniValue::VOBJ);
1154  CNetAddr net_addr;
1155  bool success{false};
1156 
1157  if (LookupHost(addr_string, net_addr, false)) {
1158  CAddress address{{net_addr, port}, ServiceFlags(NODE_NETWORK)};
1159  address.nTime = AdjustedTime();
1160  // The source address is set equal to the address. This is
1161  // equivalent to the peer announcing itself.
1162  if (node.addrman->Add({address}, address)) {
1163  success = true;
1164  if (tried) {
1165  // Attempt to move the address to the tried addresses
1166  // table.
1167  node.addrman->Good(address);
1168  }
1169  }
1170  }
1171 
1172  obj.pushKV("success", success);
1173  return obj;
1174  },
1175  };
1176 }
1177 
1179  // clang-format off
1180  static const CRPCCommand commands[] = {
1181  // category actor (function)
1182  // ------------------ ----------------------
1183  { "network", getconnectioncount, },
1184  { "network", ping, },
1185  { "network", getpeerinfo, },
1186  { "network", addnode, },
1187  { "network", disconnectnode, },
1188  { "network", getaddednodeinfo, },
1189  { "network", getnettotals, },
1190  { "network", getnetworkinfo, },
1191  { "network", setban, },
1192  { "network", listbanned, },
1193  { "network", clearbanned, },
1194  { "network", setnetworkactive, },
1195  { "network", getnodeaddresses, },
1196  { "hidden", addconnection, },
1197  { "hidden", addpeeraddress, },
1198  };
1199  // clang-format on
1200  for (const auto &c : commands) {
1201  t.appendCommand(c.name, &c);
1202  }
1203 }
bool isAvalancheEnabled(const ArgsManager &argsman)
Definition: avalanche.cpp:9
std::unique_ptr< avalanche::Processor > g_avalanche
Global avalanche instance.
Definition: processor.cpp:38
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:111
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
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
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
static path absolute(const path &p)
Definition: fs.h:95
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
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
Definition: settings.cpp:12
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)
Definition: net.cpp:1178
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:983
static RPCHelpMan getnettotals()
Definition: net.cpp:619
static RPCHelpMan addnode()
Definition: net.cpp:338
static RPCHelpMan getnodeaddresses()
Definition: net.cpp:1029
static RPCHelpMan setban()
Definition: net.cpp:830
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:935
static RPCHelpMan setnetworkactive()
Definition: net.cpp:1007
static RPCHelpMan addpeeraddress()
Definition: net.cpp:1113
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
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:19
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:50
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:59
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
ArgsManager gArgs
Definition: system.cpp:79
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:54
double CountSecondsDouble(SecondsDouble t)
Helper to count the seconds in any std::chrono::duration type.
Definition: time.h:71
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