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