Bitcoin Core  24.99.0
P2P Digital Currency
net.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2022 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 <banman.h>
9 #include <chainparams.h>
10 #include <clientversion.h>
11 #include <core_io.h>
12 #include <net_permissions.h>
13 #include <net_processing.h>
14 #include <net_types.h> // For banmap_t
15 #include <netbase.h>
16 #include <node/context.h>
17 #include <policy/settings.h>
18 #include <rpc/blockchain.h>
19 #include <rpc/protocol.h>
20 #include <rpc/server_util.h>
21 #include <rpc/util.h>
22 #include <sync.h>
23 #include <timedata.h>
24 #include <util/strencodings.h>
25 #include <util/string.h>
26 #include <util/time.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 
38 const std::vector<std::string> CONNECTION_TYPE_DOC{
39  "outbound-full-relay (default automatic connections)",
40  "block-relay-only (does not relay transactions or addresses)",
41  "inbound (initiated by the peer)",
42  "manual (added via addnode RPC or -addnode/-connect configuration options)",
43  "addr-fetch (short-lived automatic connection for soliciting addresses)",
44  "feeler (short-lived automatic connection for testing addresses)"
45 };
46 
48 {
49  return RPCHelpMan{"getconnectioncount",
50  "\nReturns the number of connections to other nodes.\n",
51  {},
52  RPCResult{
53  RPCResult::Type::NUM, "", "The connection count"
54  },
56  HelpExampleCli("getconnectioncount", "")
57  + HelpExampleRpc("getconnectioncount", "")
58  },
59  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
60 {
61  NodeContext& node = EnsureAnyNodeContext(request.context);
62  const CConnman& connman = EnsureConnman(node);
63 
65 },
66  };
67 }
68 
69 static RPCHelpMan ping()
70 {
71  return RPCHelpMan{"ping",
72  "\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
73  "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
74  "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n",
75  {},
78  HelpExampleCli("ping", "")
79  + HelpExampleRpc("ping", "")
80  },
81  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
82 {
83  NodeContext& node = EnsureAnyNodeContext(request.context);
84  PeerManager& peerman = EnsurePeerman(node);
85 
86  // Request that each node send a ping during next message processing pass
87  peerman.SendPings();
88  return UniValue::VNULL;
89 },
90  };
91 }
92 
94 {
95  return RPCHelpMan{
96  "getpeerinfo",
97  "Returns data about each connected network peer as a json array of objects.",
98  {},
99  RPCResult{
100  RPCResult::Type::ARR, "", "",
101  {
102  {RPCResult::Type::OBJ, "", "",
103  {
104  {
105  {RPCResult::Type::NUM, "id", "Peer index"},
106  {RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"},
107  {RPCResult::Type::STR, "addrbind", /*optional=*/true, "(ip:port) Bind address of the connection to the peer"},
108  {RPCResult::Type::STR, "addrlocal", /*optional=*/true, "(ip:port) Local address as reported by the peer"},
109  {RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(/*append_unroutable=*/true), ", ") + ")"},
110  {RPCResult::Type::NUM, "mapped_as", /*optional=*/true, "The AS in the BGP route to the peer used for diversifying\n"
111  "peer selection (only available if the asmap config flag is set)"},
112  {RPCResult::Type::STR_HEX, "services", "The services offered"},
113  {RPCResult::Type::ARR, "servicesnames", "the services offered, in human-readable form",
114  {
115  {RPCResult::Type::STR, "SERVICE_NAME", "the service name if it is recognised"}
116  }},
117  {RPCResult::Type::BOOL, "relaytxes", "Whether we relay transactions to this peer"},
118  {RPCResult::Type::NUM_TIME, "lastsend", "The " + UNIX_EPOCH_TIME + " of the last send"},
119  {RPCResult::Type::NUM_TIME, "lastrecv", "The " + UNIX_EPOCH_TIME + " of the last receive"},
120  {RPCResult::Type::NUM_TIME, "last_transaction", "The " + UNIX_EPOCH_TIME + " of the last valid transaction received from this peer"},
121  {RPCResult::Type::NUM_TIME, "last_block", "The " + UNIX_EPOCH_TIME + " of the last block received from this peer"},
122  {RPCResult::Type::NUM, "bytessent", "The total bytes sent"},
123  {RPCResult::Type::NUM, "bytesrecv", "The total bytes received"},
124  {RPCResult::Type::NUM_TIME, "conntime", "The " + UNIX_EPOCH_TIME + " of the connection"},
125  {RPCResult::Type::NUM, "timeoffset", "The time offset in seconds"},
126  {RPCResult::Type::NUM, "pingtime", /*optional=*/true, "The last ping time in milliseconds (ms), if any"},
127  {RPCResult::Type::NUM, "minping", /*optional=*/true, "The minimum observed ping time in milliseconds (ms), if any"},
128  {RPCResult::Type::NUM, "pingwait", /*optional=*/true, "The duration in milliseconds (ms) of an outstanding ping (if non-zero)"},
129  {RPCResult::Type::NUM, "version", "The peer version, such as 70001"},
130  {RPCResult::Type::STR, "subver", "The string version"},
131  {RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
132  {RPCResult::Type::BOOL, "bip152_hb_to", "Whether we selected peer as (compact blocks) high-bandwidth peer"},
133  {RPCResult::Type::BOOL, "bip152_hb_from", "Whether peer selected us as (compact blocks) high-bandwidth peer"},
134  {RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
135  {RPCResult::Type::NUM, "presynced_headers", "The current height of header pre-synchronization with this peer, or -1 if no low-work sync is in progress"},
136  {RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
137  {RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"},
138  {RPCResult::Type::ARR, "inflight", "",
139  {
140  {RPCResult::Type::NUM, "n", "The heights of blocks we're currently asking from this peer"},
141  }},
142  {RPCResult::Type::BOOL, "addr_relay_enabled", "Whether we participate in address relay with this peer"},
143  {RPCResult::Type::NUM, "addr_processed", "The total number of addresses processed, excluding those dropped due to rate limiting"},
144  {RPCResult::Type::NUM, "addr_rate_limited", "The total number of addresses dropped due to rate limiting"},
145  {RPCResult::Type::ARR, "permissions", "Any special permissions that have been granted to this peer",
146  {
147  {RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"},
148  }},
149  {RPCResult::Type::NUM, "minfeefilter", "The minimum fee rate for transactions this peer accepts"},
150  {RPCResult::Type::OBJ_DYN, "bytessent_per_msg", "",
151  {
152  {RPCResult::Type::NUM, "msg", "The total bytes sent aggregated by message type\n"
153  "When a message type is not listed in this json object, the bytes sent are 0.\n"
154  "Only known message types can appear as keys in the object."}
155  }},
156  {RPCResult::Type::OBJ_DYN, "bytesrecv_per_msg", "",
157  {
158  {RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n"
159  "When a message type is not listed in this json object, the bytes received are 0.\n"
160  "Only known message types can appear as keys in the object and all bytes received\n"
161  "of unknown message types are listed under '"+NET_MESSAGE_TYPE_OTHER+"'."}
162  }},
163  {RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
164  "Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
165  "best capture connection behaviors."},
166  }},
167  }},
168  },
169  RPCExamples{
170  HelpExampleCli("getpeerinfo", "")
171  + HelpExampleRpc("getpeerinfo", "")
172  },
173  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
174 {
175  NodeContext& node = EnsureAnyNodeContext(request.context);
176  const CConnman& connman = EnsureConnman(node);
177  const PeerManager& peerman = EnsurePeerman(node);
178 
179  std::vector<CNodeStats> vstats;
180  connman.GetNodeStats(vstats);
181 
183 
184  for (const CNodeStats& stats : vstats) {
186  CNodeStateStats statestats;
187  bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats);
188  // GetNodeStateStats() requires the existence of a CNodeState and a Peer object
189  // to succeed for this peer. These are created at connection initialisation and
190  // exist for the duration of the connection - except if there is a race where the
191  // peer got disconnected in between the GetNodeStats() and the GetNodeStateStats()
192  // calls. In this case, the peer doesn't need to be reported here.
193  if (!fStateStats) {
194  continue;
195  }
196  obj.pushKV("id", stats.nodeid);
197  obj.pushKV("addr", stats.m_addr_name);
198  if (stats.addrBind.IsValid()) {
199  obj.pushKV("addrbind", stats.addrBind.ToString());
200  }
201  if (!(stats.addrLocal.empty())) {
202  obj.pushKV("addrlocal", stats.addrLocal);
203  }
204  obj.pushKV("network", GetNetworkName(stats.m_network));
205  if (stats.m_mapped_as != 0) {
206  obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
207  }
208  ServiceFlags services{statestats.their_services};
209  obj.pushKV("services", strprintf("%016x", services));
210  obj.pushKV("servicesnames", GetServicesNames(services));
211  obj.pushKV("relaytxes", statestats.m_relay_txs);
212  obj.pushKV("lastsend", count_seconds(stats.m_last_send));
213  obj.pushKV("lastrecv", count_seconds(stats.m_last_recv));
214  obj.pushKV("last_transaction", count_seconds(stats.m_last_tx_time));
215  obj.pushKV("last_block", count_seconds(stats.m_last_block_time));
216  obj.pushKV("bytessent", stats.nSendBytes);
217  obj.pushKV("bytesrecv", stats.nRecvBytes);
218  obj.pushKV("conntime", count_seconds(stats.m_connected));
219  obj.pushKV("timeoffset", stats.nTimeOffset);
220  if (stats.m_last_ping_time > 0us) {
221  obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time));
222  }
223  if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
224  obj.pushKV("minping", Ticks<SecondsDouble>(stats.m_min_ping_time));
225  }
226  if (statestats.m_ping_wait > 0s) {
227  obj.pushKV("pingwait", Ticks<SecondsDouble>(statestats.m_ping_wait));
228  }
229  obj.pushKV("version", stats.nVersion);
230  // Use the sanitized form of subver here, to avoid tricksy remote peers from
231  // corrupting or modifying the JSON output by putting special characters in
232  // their ver message.
233  obj.pushKV("subver", stats.cleanSubVer);
234  obj.pushKV("inbound", stats.fInbound);
235  obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to);
236  obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from);
237  obj.pushKV("startingheight", statestats.m_starting_height);
238  obj.pushKV("presynced_headers", statestats.presync_height);
239  obj.pushKV("synced_headers", statestats.nSyncHeight);
240  obj.pushKV("synced_blocks", statestats.nCommonHeight);
241  UniValue heights(UniValue::VARR);
242  for (const int height : statestats.vHeightInFlight) {
243  heights.push_back(height);
244  }
245  obj.pushKV("inflight", heights);
246  obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled);
247  obj.pushKV("addr_processed", statestats.m_addr_processed);
248  obj.pushKV("addr_rate_limited", statestats.m_addr_rate_limited);
249  UniValue permissions(UniValue::VARR);
250  for (const auto& permission : NetPermissions::ToStrings(stats.m_permission_flags)) {
251  permissions.push_back(permission);
252  }
253  obj.pushKV("permissions", permissions);
254  obj.pushKV("minfeefilter", ValueFromAmount(statestats.m_fee_filter_received));
255 
256  UniValue sendPerMsgType(UniValue::VOBJ);
257  for (const auto& i : stats.mapSendBytesPerMsgType) {
258  if (i.second > 0)
259  sendPerMsgType.pushKV(i.first, i.second);
260  }
261  obj.pushKV("bytessent_per_msg", sendPerMsgType);
262 
263  UniValue recvPerMsgType(UniValue::VOBJ);
264  for (const auto& i : stats.mapRecvBytesPerMsgType) {
265  if (i.second > 0)
266  recvPerMsgType.pushKV(i.first, i.second);
267  }
268  obj.pushKV("bytesrecv_per_msg", recvPerMsgType);
269  obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
270 
271  ret.push_back(obj);
272  }
273 
274  return ret;
275 },
276  };
277 }
278 
280 {
281  return RPCHelpMan{"addnode",
282  "\nAttempts to add or remove a node from the addnode list.\n"
283  "Or try a connection to a node once.\n"
284  "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n"
285  "full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n" +
286  strprintf("Addnode connections are limited to %u at a time", MAX_ADDNODE_CONNECTIONS) +
287  " and are counted separately from the -maxconnections limit.\n",
288  {
289  {"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The node (see getpeerinfo for nodes)"},
290  {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once"},
291  },
293  RPCExamples{
294  HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"")
295  + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")
296  },
297  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
298 {
299  std::string strCommand;
300  if (!request.params[1].isNull())
301  strCommand = request.params[1].get_str();
302  if (strCommand != "onetry" && strCommand != "add" && strCommand != "remove") {
303  throw std::runtime_error(
304  self.ToString());
305  }
306 
307  NodeContext& node = EnsureAnyNodeContext(request.context);
308  CConnman& connman = EnsureConnman(node);
309 
310  std::string strNode = request.params[0].get_str();
311 
312  if (strCommand == "onetry")
313  {
314  CAddress addr;
315  connman.OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), ConnectionType::MANUAL);
316  return UniValue::VNULL;
317  }
318 
319  if (strCommand == "add")
320  {
321  if (!connman.AddNode(strNode)) {
322  throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
323  }
324  }
325  else if(strCommand == "remove")
326  {
327  if (!connman.RemoveAddedNode(strNode)) {
328  throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
329  }
330  }
331 
332  return UniValue::VNULL;
333 },
334  };
335 }
336 
338 {
339  return RPCHelpMan{"addconnection",
340  "\nOpen an outbound connection to a specified node. This RPC is for testing only.\n",
341  {
342  {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
343  {"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
344  },
345  RPCResult{
346  RPCResult::Type::OBJ, "", "",
347  {
348  { RPCResult::Type::STR, "address", "Address of newly added connection." },
349  { RPCResult::Type::STR, "connection_type", "Type of connection opened." },
350  }},
351  RPCExamples{
352  HelpExampleCli("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\"")
353  + HelpExampleRpc("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\"")
354  },
355  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
356 {
358  throw std::runtime_error("addconnection is for regression testing (-regtest mode) only.");
359  }
360 
361  const std::string address = request.params[0].get_str();
362  const std::string conn_type_in{TrimString(request.params[1].get_str())};
363  ConnectionType conn_type{};
364  if (conn_type_in == "outbound-full-relay") {
366  } else if (conn_type_in == "block-relay-only") {
367  conn_type = ConnectionType::BLOCK_RELAY;
368  } else if (conn_type_in == "addr-fetch") {
369  conn_type = ConnectionType::ADDR_FETCH;
370  } else if (conn_type_in == "feeler") {
371  conn_type = ConnectionType::FEELER;
372  } else {
374  }
375 
376  NodeContext& node = EnsureAnyNodeContext(request.context);
377  CConnman& connman = EnsureConnman(node);
378 
379  const bool success = connman.AddConnection(address, conn_type);
380  if (!success) {
381  throw JSONRPCError(RPC_CLIENT_NODE_CAPACITY_REACHED, "Error: Already at capacity for specified connection type.");
382  }
383 
384  UniValue info(UniValue::VOBJ);
385  info.pushKV("address", address);
386  info.pushKV("connection_type", conn_type_in);
387 
388  return info;
389 },
390  };
391 }
392 
394 {
395  return RPCHelpMan{"disconnectnode",
396  "\nImmediately disconnects from the specified peer node.\n"
397  "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n"
398  "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n",
399  {
400  {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"},
401  {"nodeid", RPCArg::Type::NUM, RPCArg::DefaultHint{"fallback to address"}, "The node ID (see getpeerinfo for node IDs)"},
402  },
404  RPCExamples{
405  HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"")
406  + HelpExampleCli("disconnectnode", "\"\" 1")
407  + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"")
408  + HelpExampleRpc("disconnectnode", "\"\", 1")
409  },
410  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
411 {
412  NodeContext& node = EnsureAnyNodeContext(request.context);
413  CConnman& connman = EnsureConnman(node);
414 
415  bool success;
416  const UniValue &address_arg = request.params[0];
417  const UniValue &id_arg = request.params[1];
418 
419  if (!address_arg.isNull() && id_arg.isNull()) {
420  /* handle disconnect-by-address */
421  success = connman.DisconnectNode(address_arg.get_str());
422  } else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) {
423  /* handle disconnect-by-id */
424  NodeId nodeid = (NodeId) id_arg.getInt<int64_t>();
425  success = connman.DisconnectNode(nodeid);
426  } else {
427  throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
428  }
429 
430  if (!success) {
431  throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
432  }
433 
434  return UniValue::VNULL;
435 },
436  };
437 }
438 
440 {
441  return RPCHelpMan{"getaddednodeinfo",
442  "\nReturns information about the given added node, or all added nodes\n"
443  "(note that onetry addnodes are not listed here)\n",
444  {
445  {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"}, "If provided, return information about this specific node, otherwise all nodes are returned."},
446  },
447  RPCResult{
448  RPCResult::Type::ARR, "", "",
449  {
450  {RPCResult::Type::OBJ, "", "",
451  {
452  {RPCResult::Type::STR, "addednode", "The node IP address or name (as provided to addnode)"},
453  {RPCResult::Type::BOOL, "connected", "If connected"},
454  {RPCResult::Type::ARR, "addresses", "Only when connected = true",
455  {
456  {RPCResult::Type::OBJ, "", "",
457  {
458  {RPCResult::Type::STR, "address", "The bitcoin server IP and port we're connected to"},
459  {RPCResult::Type::STR, "connected", "connection, inbound or outbound"},
460  }},
461  }},
462  }},
463  }
464  },
465  RPCExamples{
466  HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"")
467  + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")
468  },
469  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
470 {
471  NodeContext& node = EnsureAnyNodeContext(request.context);
472  const CConnman& connman = EnsureConnman(node);
473 
474  std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo();
475 
476  if (!request.params[0].isNull()) {
477  bool found = false;
478  for (const AddedNodeInfo& info : vInfo) {
479  if (info.strAddedNode == request.params[0].get_str()) {
480  vInfo.assign(1, info);
481  found = true;
482  break;
483  }
484  }
485  if (!found) {
486  throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
487  }
488  }
489 
491 
492  for (const AddedNodeInfo& info : vInfo) {
494  obj.pushKV("addednode", info.strAddedNode);
495  obj.pushKV("connected", info.fConnected);
496  UniValue addresses(UniValue::VARR);
497  if (info.fConnected) {
498  UniValue address(UniValue::VOBJ);
499  address.pushKV("address", info.resolvedAddress.ToString());
500  address.pushKV("connected", info.fInbound ? "inbound" : "outbound");
501  addresses.push_back(address);
502  }
503  obj.pushKV("addresses", addresses);
504  ret.push_back(obj);
505  }
506 
507  return ret;
508 },
509  };
510 }
511 
513 {
514  return RPCHelpMan{"getnettotals",
515  "\nReturns information about network traffic, including bytes in, bytes out,\n"
516  "and current time.\n",
517  {},
518  RPCResult{
519  RPCResult::Type::OBJ, "", "",
520  {
521  {RPCResult::Type::NUM, "totalbytesrecv", "Total bytes received"},
522  {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"},
523  {RPCResult::Type::NUM_TIME, "timemillis", "Current " + UNIX_EPOCH_TIME + " in milliseconds"},
524  {RPCResult::Type::OBJ, "uploadtarget", "",
525  {
526  {RPCResult::Type::NUM, "timeframe", "Length of the measuring timeframe in seconds"},
527  {RPCResult::Type::NUM, "target", "Target in bytes"},
528  {RPCResult::Type::BOOL, "target_reached", "True if target is reached"},
529  {RPCResult::Type::BOOL, "serve_historical_blocks", "True if serving historical blocks"},
530  {RPCResult::Type::NUM, "bytes_left_in_cycle", "Bytes left in current time cycle"},
531  {RPCResult::Type::NUM, "time_left_in_cycle", "Seconds left in current time cycle"},
532  }},
533  }
534  },
535  RPCExamples{
536  HelpExampleCli("getnettotals", "")
537  + HelpExampleRpc("getnettotals", "")
538  },
539  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
540 {
541  NodeContext& node = EnsureAnyNodeContext(request.context);
542  const CConnman& connman = EnsureConnman(node);
543 
545  obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv());
546  obj.pushKV("totalbytessent", connman.GetTotalBytesSent());
547  obj.pushKV("timemillis", GetTimeMillis());
548 
549  UniValue outboundLimit(UniValue::VOBJ);
550  outboundLimit.pushKV("timeframe", count_seconds(connman.GetMaxOutboundTimeframe()));
551  outboundLimit.pushKV("target", connman.GetMaxOutboundTarget());
552  outboundLimit.pushKV("target_reached", connman.OutboundTargetReached(false));
553  outboundLimit.pushKV("serve_historical_blocks", !connman.OutboundTargetReached(true));
554  outboundLimit.pushKV("bytes_left_in_cycle", connman.GetOutboundTargetBytesLeft());
555  outboundLimit.pushKV("time_left_in_cycle", count_seconds(connman.GetMaxOutboundTimeLeftInCycle()));
556  obj.pushKV("uploadtarget", outboundLimit);
557  return obj;
558 },
559  };
560 }
561 
563 {
564  UniValue networks(UniValue::VARR);
565  for (int n = 0; n < NET_MAX; ++n) {
566  enum Network network = static_cast<enum Network>(n);
567  if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
568  Proxy proxy;
570  GetProxy(network, proxy);
571  obj.pushKV("name", GetNetworkName(network));
572  obj.pushKV("limited", !IsReachable(network));
573  obj.pushKV("reachable", IsReachable(network));
574  obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string());
575  obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
576  networks.push_back(obj);
577  }
578  return networks;
579 }
580 
582 {
583  return RPCHelpMan{"getnetworkinfo",
584  "Returns an object containing various state info regarding P2P networking.\n",
585  {},
586  RPCResult{
587  RPCResult::Type::OBJ, "", "",
588  {
589  {RPCResult::Type::NUM, "version", "the server version"},
590  {RPCResult::Type::STR, "subversion", "the server subversion string"},
591  {RPCResult::Type::NUM, "protocolversion", "the protocol version"},
592  {RPCResult::Type::STR_HEX, "localservices", "the services we offer to the network"},
593  {RPCResult::Type::ARR, "localservicesnames", "the services we offer to the network, in human-readable form",
594  {
595  {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
596  }},
597  {RPCResult::Type::BOOL, "localrelay", "true if transaction relay is requested from peers"},
598  {RPCResult::Type::NUM, "timeoffset", "the time offset"},
599  {RPCResult::Type::NUM, "connections", "the total number of connections"},
600  {RPCResult::Type::NUM, "connections_in", "the number of inbound connections"},
601  {RPCResult::Type::NUM, "connections_out", "the number of outbound connections"},
602  {RPCResult::Type::BOOL, "networkactive", "whether p2p networking is enabled"},
603  {RPCResult::Type::ARR, "networks", "information per network",
604  {
605  {RPCResult::Type::OBJ, "", "",
606  {
607  {RPCResult::Type::STR, "name", "network (" + Join(GetNetworkNames(), ", ") + ")"},
608  {RPCResult::Type::BOOL, "limited", "is the network limited using -onlynet?"},
609  {RPCResult::Type::BOOL, "reachable", "is the network reachable?"},
610  {RPCResult::Type::STR, "proxy", "(\"host:port\") the proxy that is used for this network, or empty if none"},
611  {RPCResult::Type::BOOL, "proxy_randomize_credentials", "Whether randomized credentials are used"},
612  }},
613  }},
614  {RPCResult::Type::NUM, "relayfee", "minimum relay fee rate for transactions in " + CURRENCY_UNIT + "/kvB"},
615  {RPCResult::Type::NUM, "incrementalfee", "minimum fee rate increment for mempool limiting or replacement in " + CURRENCY_UNIT + "/kvB"},
616  {RPCResult::Type::ARR, "localaddresses", "list of local addresses",
617  {
618  {RPCResult::Type::OBJ, "", "",
619  {
620  {RPCResult::Type::STR, "address", "network address"},
621  {RPCResult::Type::NUM, "port", "network port"},
622  {RPCResult::Type::NUM, "score", "relative score"},
623  }},
624  }},
625  {RPCResult::Type::STR, "warnings", "any network and blockchain warnings"},
626  }
627  },
628  RPCExamples{
629  HelpExampleCli("getnetworkinfo", "")
630  + HelpExampleRpc("getnetworkinfo", "")
631  },
632  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
633 {
634  LOCK(cs_main);
636  obj.pushKV("version", CLIENT_VERSION);
637  obj.pushKV("subversion", strSubVersion);
638  obj.pushKV("protocolversion",PROTOCOL_VERSION);
639  NodeContext& node = EnsureAnyNodeContext(request.context);
640  if (node.connman) {
641  ServiceFlags services = node.connman->GetLocalServices();
642  obj.pushKV("localservices", strprintf("%016x", services));
643  obj.pushKV("localservicesnames", GetServicesNames(services));
644  }
645  if (node.peerman) {
646  obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
647  }
648  obj.pushKV("timeoffset", GetTimeOffset());
649  if (node.connman) {
650  obj.pushKV("networkactive", node.connman->GetNetworkActive());
651  obj.pushKV("connections", node.connman->GetNodeCount(ConnectionDirection::Both));
652  obj.pushKV("connections_in", node.connman->GetNodeCount(ConnectionDirection::In));
653  obj.pushKV("connections_out", node.connman->GetNodeCount(ConnectionDirection::Out));
654  }
655  obj.pushKV("networks", GetNetworksInfo());
656  if (node.mempool) {
657  // Those fields can be deprecated, to be replaced by the getmempoolinfo fields
658  obj.pushKV("relayfee", ValueFromAmount(node.mempool->m_min_relay_feerate.GetFeePerK()));
659  obj.pushKV("incrementalfee", ValueFromAmount(node.mempool->m_incremental_relay_feerate.GetFeePerK()));
660  }
661  UniValue localAddresses(UniValue::VARR);
662  {
664  for (const std::pair<const CNetAddr, LocalServiceInfo> &item : mapLocalHost)
665  {
667  rec.pushKV("address", item.first.ToString());
668  rec.pushKV("port", item.second.nPort);
669  rec.pushKV("score", item.second.nScore);
670  localAddresses.push_back(rec);
671  }
672  }
673  obj.pushKV("localaddresses", localAddresses);
674  obj.pushKV("warnings", GetWarnings(false).original);
675  return obj;
676 },
677  };
678 }
679 
681 {
682  return RPCHelpMan{"setban",
683  "\nAttempts to add or remove an IP/Subnet from the banned list.\n",
684  {
685  {"subnet", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)"},
686  {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list"},
687  {"bantime", RPCArg::Type::NUM, RPCArg::Default{0}, "time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)"},
688  {"absolute", RPCArg::Type::BOOL, RPCArg::Default{false}, "If set, the bantime must be an absolute timestamp expressed in " + UNIX_EPOCH_TIME},
689  },
691  RPCExamples{
692  HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400")
693  + HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"")
694  + HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")
695  },
696  [&](const RPCHelpMan& help, const JSONRPCRequest& request) -> UniValue
697 {
698  std::string strCommand;
699  if (!request.params[1].isNull())
700  strCommand = request.params[1].get_str();
701  if (strCommand != "add" && strCommand != "remove") {
702  throw std::runtime_error(help.ToString());
703  }
704  NodeContext& node = EnsureAnyNodeContext(request.context);
705  if (!node.banman) {
706  throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
707  }
708 
709  CSubNet subNet;
710  CNetAddr netAddr;
711  bool isSubnet = false;
712 
713  if (request.params[0].get_str().find('/') != std::string::npos)
714  isSubnet = true;
715 
716  if (!isSubnet) {
717  CNetAddr resolved;
718  LookupHost(request.params[0].get_str(), resolved, false);
719  netAddr = resolved;
720  }
721  else
722  LookupSubNet(request.params[0].get_str(), subNet);
723 
724  if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) )
725  throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Invalid IP/Subnet");
726 
727  if (strCommand == "add")
728  {
729  if (isSubnet ? node.banman->IsBanned(subNet) : node.banman->IsBanned(netAddr)) {
730  throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
731  }
732 
733  int64_t banTime = 0; //use standard bantime if not specified
734  if (!request.params[2].isNull())
735  banTime = request.params[2].getInt<int64_t>();
736 
737  const bool absolute{request.params[3].isNull() ? false : request.params[3].get_bool()};
738 
739  if (absolute && banTime < GetTime()) {
740  throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Absolute timestamp is in the past");
741  }
742 
743  if (isSubnet) {
744  node.banman->Ban(subNet, banTime, absolute);
745  if (node.connman) {
746  node.connman->DisconnectNode(subNet);
747  }
748  } else {
749  node.banman->Ban(netAddr, banTime, absolute);
750  if (node.connman) {
751  node.connman->DisconnectNode(netAddr);
752  }
753  }
754  }
755  else if(strCommand == "remove")
756  {
757  if (!( isSubnet ? node.banman->Unban(subNet) : node.banman->Unban(netAddr) )) {
758  throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned.");
759  }
760  }
761  return UniValue::VNULL;
762 },
763  };
764 }
765 
767 {
768  return RPCHelpMan{"listbanned",
769  "\nList all manually banned IPs/Subnets.\n",
770  {},
772  {
773  {RPCResult::Type::OBJ, "", "",
774  {
775  {RPCResult::Type::STR, "address", "The IP/Subnet of the banned node"},
776  {RPCResult::Type::NUM_TIME, "ban_created", "The " + UNIX_EPOCH_TIME + " the ban was created"},
777  {RPCResult::Type::NUM_TIME, "banned_until", "The " + UNIX_EPOCH_TIME + " the ban expires"},
778  {RPCResult::Type::NUM_TIME, "ban_duration", "The ban duration, in seconds"},
779  {RPCResult::Type::NUM_TIME, "time_remaining", "The time remaining until the ban expires, in seconds"},
780  }},
781  }},
782  RPCExamples{
783  HelpExampleCli("listbanned", "")
784  + HelpExampleRpc("listbanned", "")
785  },
786  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
787 {
788  NodeContext& node = EnsureAnyNodeContext(request.context);
789  if(!node.banman) {
790  throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
791  }
792 
793  banmap_t banMap;
794  node.banman->GetBanned(banMap);
795  const int64_t current_time{GetTime()};
796 
797  UniValue bannedAddresses(UniValue::VARR);
798  for (const auto& entry : banMap)
799  {
800  const CBanEntry& banEntry = entry.second;
802  rec.pushKV("address", entry.first.ToString());
803  rec.pushKV("ban_created", banEntry.nCreateTime);
804  rec.pushKV("banned_until", banEntry.nBanUntil);
805  rec.pushKV("ban_duration", (banEntry.nBanUntil - banEntry.nCreateTime));
806  rec.pushKV("time_remaining", (banEntry.nBanUntil - current_time));
807 
808  bannedAddresses.push_back(rec);
809  }
810 
811  return bannedAddresses;
812 },
813  };
814 }
815 
817 {
818  return RPCHelpMan{"clearbanned",
819  "\nClear all banned IPs.\n",
820  {},
822  RPCExamples{
823  HelpExampleCli("clearbanned", "")
824  + HelpExampleRpc("clearbanned", "")
825  },
826  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
827 {
828  NodeContext& node = EnsureAnyNodeContext(request.context);
829  if (!node.banman) {
830  throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
831  }
832 
833  node.banman->ClearBanned();
834 
835  return UniValue::VNULL;
836 },
837  };
838 }
839 
841 {
842  return RPCHelpMan{"setnetworkactive",
843  "\nDisable/enable all p2p network activity.\n",
844  {
845  {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable networking, false to disable"},
846  },
847  RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
848  RPCExamples{""},
849  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
850 {
851  NodeContext& node = EnsureAnyNodeContext(request.context);
852  CConnman& connman = EnsureConnman(node);
853 
854  connman.SetNetworkActive(request.params[0].get_bool());
855 
856  return connman.GetNetworkActive();
857 },
858  };
859 }
860 
862 {
863  return RPCHelpMan{"getnodeaddresses",
864  "Return known addresses, after filtering for quality and recency.\n"
865  "These can potentially be used to find new peers in the network.\n"
866  "The total number of addresses known to the node may be higher.",
867  {
868  {"count", RPCArg::Type::NUM, RPCArg::Default{1}, "The maximum number of addresses to return. Specify 0 to return all known addresses."},
869  {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"}, "Return only addresses of the specified network. Can be one of: " + Join(GetNetworkNames(), ", ") + "."},
870  },
871  RPCResult{
872  RPCResult::Type::ARR, "", "",
873  {
874  {RPCResult::Type::OBJ, "", "",
875  {
876  {RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " when the node was last seen"},
877  {RPCResult::Type::NUM, "services", "The services offered by the node"},
878  {RPCResult::Type::STR, "address", "The address of the node"},
879  {RPCResult::Type::NUM, "port", "The port number of the node"},
880  {RPCResult::Type::STR, "network", "The network (" + Join(GetNetworkNames(), ", ") + ") the node connected through"},
881  }},
882  }
883  },
884  RPCExamples{
885  HelpExampleCli("getnodeaddresses", "8")
886  + HelpExampleCli("getnodeaddresses", "4 \"i2p\"")
887  + HelpExampleCli("-named getnodeaddresses", "network=onion count=12")
888  + HelpExampleRpc("getnodeaddresses", "8")
889  + HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")
890  },
891  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
892 {
893  NodeContext& node = EnsureAnyNodeContext(request.context);
894  const CConnman& connman = EnsureConnman(node);
895 
896  const int count{request.params[0].isNull() ? 1 : request.params[0].getInt<int>()};
897  if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
898 
899  const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}};
900  if (network == NET_UNROUTABLE) {
901  throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Network not recognized: %s", request.params[1].get_str()));
902  }
903 
904  // returns a shuffled list of CAddress
905  const std::vector<CAddress> vAddr{connman.GetAddresses(count, /*max_pct=*/0, network)};
907 
908  for (const CAddress& addr : vAddr) {
910  obj.pushKV("time", int64_t{TicksSinceEpoch<std::chrono::seconds>(addr.nTime)});
911  obj.pushKV("services", (uint64_t)addr.nServices);
912  obj.pushKV("address", addr.ToStringIP());
913  obj.pushKV("port", addr.GetPort());
914  obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
915  ret.push_back(obj);
916  }
917  return ret;
918 },
919  };
920 }
921 
923 {
924  return RPCHelpMan{"addpeeraddress",
925  "\nAdd the address of a potential peer to the address manager. This RPC is for testing only.\n",
926  {
927  {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"},
928  {"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"},
929  {"tried", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, attempt to add the peer to the tried addresses table"},
930  },
931  RPCResult{
932  RPCResult::Type::OBJ, "", "",
933  {
934  {RPCResult::Type::BOOL, "success", "whether the peer address was successfully added to the address manager"},
935  },
936  },
937  RPCExamples{
938  HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true")
939  + HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")
940  },
941  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
942 {
943  NodeContext& node = EnsureAnyNodeContext(request.context);
944  if (!node.addrman) {
945  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
946  }
947 
948  const std::string& addr_string{request.params[0].get_str()};
949  const auto port{request.params[1].getInt<uint16_t>()};
950  const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()};
951 
953  CNetAddr net_addr;
954  bool success{false};
955 
956  if (LookupHost(addr_string, net_addr, false)) {
957  CService service{net_addr, port};
959  address.nTime = Now<NodeSeconds>();
960  // The source address is set equal to the address. This is equivalent to the peer
961  // announcing itself.
962  if (node.addrman->Add({address}, address)) {
963  success = true;
964  if (tried) {
965  // Attempt to move the address to the tried addresses table.
966  node.addrman->Good(address);
967  }
968  }
969  }
970 
971  obj.pushKV("success", success);
972  return obj;
973 },
974  };
975 }
976 
978 {
979  static const CRPCCommand commands[]{
980  {"network", &getconnectioncount},
981  {"network", &ping},
982  {"network", &getpeerinfo},
983  {"network", &addnode},
984  {"network", &disconnectnode},
985  {"network", &getaddednodeinfo},
986  {"network", &getnettotals},
987  {"network", &getnetworkinfo},
988  {"network", &setban},
989  {"network", &listbanned},
990  {"network", &clearbanned},
991  {"network", &setnetworkactive},
992  {"network", &getnodeaddresses},
993  {"hidden", &addconnection},
994  {"hidden", &addpeeraddress},
995  };
996  for (const auto& c : commands) {
997  t.appendCommand(c.name, &c);
998  }
999 }
int ret
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
Definition: protocol.h:361
Definition: net_types.h:15
int64_t nCreateTime
Definition: net_types.h:19
int64_t nBanUntil
Definition: net_types.h:20
static const std::string REGTEST
std::string NetworkIDString() const
Return the network string.
Definition: chainparams.h:112
Definition: net.h:665
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1048
bool RemoveAddedNode(const std::string &node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:2538
bool GetNetworkActive() const
Definition: net.h:743
bool OutboundTargetReached(bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
check if the outbound target is reached if param historicalBlockServingLimit is set true,...
Definition: net.cpp:2678
uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
Definition: net.cpp:2644
std::chrono::seconds GetMaxOutboundTimeframe() const
Definition: net.cpp:2651
bool DisconnectNode(const std::string &node)
Definition: net.cpp:2578
size_t GetNodeCount(ConnectionDirection) const
Definition: net.cpp:2550
void GetNodeStats(std::vector< CNodeStats > &vstats) const
Definition: net.cpp:2566
std::vector< AddedNodeInfo > GetAddedNodeInfo() const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:1875
uint64_t GetTotalBytesRecv() const
Definition: net.cpp:2709
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:2472
void SetNetworkActive(bool active)
Definition: net.cpp:2194
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:1958
std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
Definition: net.cpp:2656
bool AddNode(const std::string &node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:2527
uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
Definition: net.cpp:2714
uint64_t GetOutboundTargetBytesLeft() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
response the bytes left in the current max outbound cycle in case of no limit, it will always respons...
Definition: net.cpp:2699
Network address.
Definition: netaddress.h:120
bool IsValid() const
Definition: netaddress.cpp:445
RPC command dispatcher.
Definition: server.h:126
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:523
std::string ToStringIPPort() const
Definition: netaddress.cpp:924
bool IsValid() const
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.
Definition: netbase.h:49
bool IsValid() const
Definition: netbase.h:54
bool randomize_credentials
Definition: netbase.h:57
CService proxy
Definition: netbase.h:56
std::string ToString() const
Definition: util.cpp:617
void push_back(UniValue val)
Definition: univalue.cpp:104
const std::string & get_str() const
@ VNULL
Definition: univalue.h:20
@ VOBJ
Definition: univalue.h:20
@ VARR
Definition: univalue.h:20
bool isNull() const
Definition: univalue.h:75
bool isStr() const
Definition: univalue.h:79
Int getInt() const
Definition: univalue.h:138
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:33
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
ConnectionType
Different types of connections to a peer.
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
@ 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.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
UniValue ValueFromAmount(const CAmount amount)
Definition: core_write.cpp:26
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
const std::string CURRENCY_UNIT
Definition: feerate.h:17
static path absolute(const path &p)
Definition: fs.h:81
Definition: init.h:25
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:120
const std::string NET_MESSAGE_TYPE_OTHER
Definition: net.cpp:107
CService MaybeFlipIPv6toCJDNS(const CService &service)
If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is re...
Definition: net.cpp:275
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:117
bool IsReachable(enum Network net)
Definition: net.cpp:333
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:68
int64_t NodeId
Definition: net.h:92
const std::vector< std::string > NET_PERMISSIONS_DOC
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:41
Network
A network type.
Definition: netaddress.h:44
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:68
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:46
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:65
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:105
enum Network ParseNetwork(const std::string &net_in)
Definition: netbase.cpp:87
bool LookupSubNet(const std::string &subnet_str, CSubNet &subnet_out)
Parse and resolve a specified subnet string into the appropriate internal representation.
Definition: netbase.cpp:684
bool GetProxy(enum Network net, Proxy &proxyInfoOut)
Definition: netbase.cpp:622
std::vector< std::string > GetNetworkNames(bool append_unroutable)
Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE.
Definition: netbase.cpp:121
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:170
ServiceFlags
nServices flags
Definition: protocol.h:273
@ NODE_WITNESS
Definition: protocol.h:286
@ NODE_NETWORK
Definition: protocol.h:279
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:56
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.cpp:38
void RegisterNetRPCCommands(CRPCTable &t)
Definition: net.cpp:977
static RPCHelpMan getnetworkinfo()
Definition: net.cpp:581
static RPCHelpMan addconnection()
Definition: net.cpp:337
static RPCHelpMan getaddednodeinfo()
Definition: net.cpp:439
static RPCHelpMan clearbanned()
Definition: net.cpp:816
static RPCHelpMan getnettotals()
Definition: net.cpp:512
static RPCHelpMan addnode()
Definition: net.cpp:279
static RPCHelpMan getnodeaddresses()
Definition: net.cpp:861
static RPCHelpMan setban()
Definition: net.cpp:680
static UniValue GetNetworksInfo()
Definition: net.cpp:562
static RPCHelpMan ping()
Definition: net.cpp:69
static RPCHelpMan getconnectioncount()
Definition: net.cpp:47
static RPCHelpMan disconnectnode()
Definition: net.cpp:393
static RPCHelpMan listbanned()
Definition: net.cpp:766
static RPCHelpMan setnetworkactive()
Definition: net.cpp:840
static RPCHelpMan addpeeraddress()
Definition: net.cpp:922
static RPCHelpMan getpeerinfo()
Definition: net.cpp:93
@ RPC_CLIENT_NODE_NOT_CONNECTED
Node to disconnect not found in connected nodes.
Definition: protocol.h:62
@ RPC_CLIENT_INVALID_IP_OR_SUBNET
Invalid IP/Subnet.
Definition: protocol.h:63
@ RPC_CLIENT_NODE_ALREADY_ADDED
Node is already added.
Definition: protocol.h:60
@ RPC_INVALID_PARAMS
Definition: protocol.h:32
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition: protocol.h:43
@ RPC_DATABASE_ERROR
Database error.
Definition: protocol.h:44
@ RPC_CLIENT_NODE_NOT_ADDED
Node has not been added before.
Definition: protocol.h:61
@ RPC_CLIENT_NODE_CAPACITY_REACHED
Max number of outbound or block-relay connections already open.
Definition: protocol.h:65
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition: protocol.h:64
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:139
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
Definition: util.cpp:1166
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:157
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:21
static RPCHelpMan help()
Definition: server.cpp:134
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:20
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:81
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:89
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Definition: string.h:41
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:109
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition: string.h:68
std::chrono::microseconds m_ping_wait
std::vector< int > vHeightInFlight
CAmount m_fee_filter_received
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
int64_t presync_height
ServiceFlags their_services
std::string DefaultHint
Hint for default value.
Definition: util.h:162
@ NO
Required arg.
@ NUM_TIME
Special numeric to denote unix epoch time.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43
#define LOCK(cs)
Definition: sync.h:258
static int count
Definition: tests.c:34
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:105
int64_t GetTime()
Definition: time.cpp:115
constexpr int64_t count_seconds(std::chrono::seconds t)
Definition: time.h:54
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
Definition: timedata.cpp:29
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1165
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
bilingual_str GetWarnings(bool verbose)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:31