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