Bitcoin ABC 0.30.12
P2P Digital Currency
net.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2019 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <rpc/server.h>
6
7#include <addrman.h>
9#include <banman.h>
10#include <chainparams.h>
11#include <clientversion.h>
12#include <config.h>
13#include <net_permissions.h>
14#include <net_processing.h>
15#include <net_types.h> // For banmap_t
16#include <netbase.h>
17#include <node/context.h>
18#include <policy/settings.h>
19#include <rpc/blockchain.h>
20#include <rpc/protocol.h>
21#include <rpc/server_util.h>
22#include <rpc/util.h>
23#include <sync.h>
24#include <timedata.h>
25#include <util/strencodings.h>
26#include <util/string.h>
27#include <util/time.h>
28#include <util/translation.h>
29#include <validation.h>
30#include <version.h>
31#include <warnings.h>
32
33#include <optional>
34
35#include <univalue.h>
36
38
40 return RPCHelpMan{
41 "getconnectioncount",
42 "Returns the number of connections to other nodes.\n",
43 {},
44 RPCResult{RPCResult::Type::NUM, "", "The connection count"},
45 RPCExamples{HelpExampleCli("getconnectioncount", "") +
46 HelpExampleRpc("getconnectioncount", "")},
47 [&](const RPCHelpMan &self, const Config &config,
48 const JSONRPCRequest &request) -> UniValue {
49 NodeContext &node = EnsureAnyNodeContext(request.context);
50 const CConnman &connman = EnsureConnman(node);
51
53 },
54 };
55}
56
57static RPCHelpMan ping() {
58 return RPCHelpMan{
59 "ping",
60 "Requests that a ping be sent to all other nodes, to measure ping "
61 "time.\n"
62 "Results provided in getpeerinfo, pingtime and pingwait fields are "
63 "decimal seconds.\n"
64 "Ping command is handled in queue with all other commands, so it "
65 "measures processing backlog, not just network ping.\n",
66 {},
68 RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")},
69 [&](const RPCHelpMan &self, const Config &config,
70 const JSONRPCRequest &request) -> UniValue {
71 NodeContext &node = EnsureAnyNodeContext(request.context);
72 PeerManager &peerman = EnsurePeerman(node);
73
74 // Request that each node send a ping during next message processing
75 // pass
76 peerman.SendPings();
77 return NullUniValue;
78 },
79 };
80}
81
83 return RPCHelpMan{
84 "getpeerinfo",
85 "Returns data about each connected network node as a json array of "
86 "objects.\n",
87 {},
90 "",
91 "",
92 {{
94 "",
95 "",
96 {{
97 {RPCResult::Type::NUM, "id", "Peer index"},
98 {RPCResult::Type::STR, "addr",
99 "(host:port) The IP address and port of the peer"},
100 {RPCResult::Type::STR, "addrbind",
101 "(ip:port) Bind address of the connection to the peer"},
102 {RPCResult::Type::STR, "addrlocal",
103 "(ip:port) Local address as reported by the peer"},
104 {RPCResult::Type::NUM, "addr_processed",
105 "The total number of addresses processed, excluding those "
106 "dropped due to rate limiting"},
107 {RPCResult::Type::NUM, "addr_rate_limited",
108 "The total number of addresses dropped due to rate "
109 "limiting"},
110 {RPCResult::Type::STR, "network",
111 "Network (" +
112 Join(GetNetworkNames(/* append_unroutable */ true),
113 ", ") +
114 ")"},
115 {RPCResult::Type::NUM, "mapped_as",
116 "The AS in the BGP route to the peer used for "
117 "diversifying\n"
118 "peer selection (only available if the asmap config flag "
119 "is set)\n"},
120 {RPCResult::Type::STR_HEX, "services",
121 "The services offered"},
123 "servicesnames",
124 "the services offered, in human-readable form",
125 {{RPCResult::Type::STR, "SERVICE_NAME",
126 "the service name if it is recognised"}}},
127 {RPCResult::Type::BOOL, "relaytxes",
128 "Whether peer has asked us to relay transactions to it"},
129 {RPCResult::Type::NUM_TIME, "lastsend",
130 "The " + UNIX_EPOCH_TIME + " of the last send"},
131 {RPCResult::Type::NUM_TIME, "lastrecv",
132 "The " + UNIX_EPOCH_TIME + " of the last receive"},
133 {RPCResult::Type::NUM_TIME, "last_transaction",
134 "The " + UNIX_EPOCH_TIME +
135 " of the last valid transaction received from this "
136 "peer"},
137 {RPCResult::Type::NUM_TIME, "last_block",
138 "The " + UNIX_EPOCH_TIME +
139 " of the last block received from this peer"},
140 {RPCResult::Type::NUM, "bytessent", "The total bytes sent"},
141 {RPCResult::Type::NUM, "bytesrecv",
142 "The total bytes received"},
143 {RPCResult::Type::NUM_TIME, "conntime",
144 "The " + UNIX_EPOCH_TIME + " of the connection"},
145 {RPCResult::Type::NUM, "timeoffset",
146 "The time offset in seconds"},
147 {RPCResult::Type::NUM, "pingtime",
148 "ping time (if available)"},
149 {RPCResult::Type::NUM, "minping",
150 "minimum observed ping time (if any at all)"},
151 {RPCResult::Type::NUM, "pingwait",
152 "ping wait (if non-zero)"},
153 {RPCResult::Type::NUM, "version",
154 "The peer version, such as 70001"},
155 {RPCResult::Type::STR, "subver", "The string version"},
156 {RPCResult::Type::BOOL, "inbound",
157 "Inbound (true) or Outbound (false)"},
158 {RPCResult::Type::BOOL, "bip152_hb_to",
159 "Whether we selected peer as (compact blocks) "
160 "high-bandwidth peer"},
161 {RPCResult::Type::BOOL, "bip152_hb_from",
162 "Whether peer selected us as (compact blocks) "
163 "high-bandwidth peer"},
164 {RPCResult::Type::STR, "connection_type",
165 "Type of connection: \n" +
166 Join(CONNECTION_TYPE_DOC, ",\n") + "."},
167 {RPCResult::Type::NUM, "startingheight",
168 "The starting height (block) of the peer"},
169 {RPCResult::Type::NUM, "presynced_headers",
170 /*optional=*/true,
171 "The current height of header pre-synchronization with "
172 "this peer, or -1 if no low-work sync is in progress"},
173 {RPCResult::Type::NUM, "synced_headers",
174 "The last header we have in common with this peer"},
175 {RPCResult::Type::NUM, "synced_blocks",
176 "The last block we have in common with this peer"},
178 "inflight",
179 "",
180 {
182 "The heights of blocks we're currently asking from "
183 "this peer"},
184 }},
185 {RPCResult::Type::BOOL, "addr_relay_enabled",
186 "Whether we participate in address relay with this peer"},
187 {RPCResult::Type::NUM, "minfeefilter",
188 "The minimum fee rate for transactions this peer accepts"},
190 "bytessent_per_msg",
191 "",
192 {{RPCResult::Type::NUM, "msg",
193 "The total bytes sent aggregated by message type\n"
194 "When a message type is not listed in this json object, "
195 "the bytes sent are 0.\n"
196 "Only known message types can appear as keys in the "
197 "object."}}},
199 "bytesrecv_per_msg",
200 "",
201 {{RPCResult::Type::NUM, "msg",
202 "The total bytes received aggregated by message type\n"
203 "When a message type is not listed in this json object, "
204 "the bytes received are 0.\n"
205 "Only known message types can appear as keys in the "
206 "object and all bytes received\n"
207 "of unknown message types are listed under '" +
209 {RPCResult::Type::NUM, "availability_score",
210 "DEPRECATED: Avalanche availability score of this node "
211 "(if any). Only present if the "
212 "deprecatedrpc=node_availability_score option is enabled"},
213 }},
214 }},
215 },
216 RPCExamples{HelpExampleCli("getpeerinfo", "") +
217 HelpExampleRpc("getpeerinfo", "")},
218 [&](const RPCHelpMan &self, const Config &config,
219 const JSONRPCRequest &request) -> UniValue {
220 NodeContext &node = EnsureAnyNodeContext(request.context);
221 const CConnman &connman = EnsureConnman(node);
222 const PeerManager &peerman = EnsurePeerman(node);
223 const ArgsManager &argsman = EnsureArgsman(node);
224
225 std::vector<CNodeStats> vstats;
226 connman.GetNodeStats(vstats);
227
229
230 for (const CNodeStats &stats : vstats) {
232 CNodeStateStats statestats;
233 bool fStateStats =
234 peerman.GetNodeStateStats(stats.nodeid, statestats);
235 obj.pushKV("id", stats.nodeid);
236 obj.pushKV("addr", stats.m_addr_name);
237 if (stats.addrBind.IsValid()) {
238 obj.pushKV("addrbind", stats.addrBind.ToString());
239 }
240 if (!(stats.addrLocal.empty())) {
241 obj.pushKV("addrlocal", stats.addrLocal);
242 }
243 obj.pushKV("network", GetNetworkName(stats.m_network));
244 if (stats.m_mapped_as != 0) {
245 obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
246 }
247 ServiceFlags services{fStateStats ? statestats.their_services
249 obj.pushKV("services", strprintf("%016x", services));
250 obj.pushKV("servicesnames", GetServicesNames(services));
251 obj.pushKV("lastsend", count_seconds(stats.m_last_send));
252 obj.pushKV("lastrecv", count_seconds(stats.m_last_recv));
253 obj.pushKV("last_transaction",
254 count_seconds(stats.m_last_tx_time));
255 if (node.avalanche) {
256 obj.pushKV("last_proof",
257 count_seconds(stats.m_last_proof_time));
258 }
259 obj.pushKV("last_block",
260 count_seconds(stats.m_last_block_time));
261 obj.pushKV("bytessent", stats.nSendBytes);
262 obj.pushKV("bytesrecv", stats.nRecvBytes);
263 obj.pushKV("conntime", count_seconds(stats.m_connected));
264 obj.pushKV("timeoffset", stats.nTimeOffset);
265 if (stats.m_last_ping_time > 0us) {
266 obj.pushKV("pingtime",
267 CountSecondsDouble(stats.m_last_ping_time));
268 }
269 if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
270 obj.pushKV("minping",
271 CountSecondsDouble(stats.m_min_ping_time));
272 }
273 if (fStateStats && statestats.m_ping_wait > 0s) {
274 obj.pushKV("pingwait",
275 CountSecondsDouble(statestats.m_ping_wait));
276 }
277 obj.pushKV("version", stats.nVersion);
278 // Use the sanitized form of subver here, to avoid tricksy
279 // remote peers from corrupting or modifying the JSON output by
280 // putting special characters in their ver message.
281 obj.pushKV("subver", stats.cleanSubVer);
282 obj.pushKV("inbound", stats.fInbound);
283 obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to);
284 obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from);
285 if (fStateStats) {
286 obj.pushKV("startingheight", statestats.m_starting_height);
287 obj.pushKV("presynced_headers", statestats.presync_height);
288 obj.pushKV("synced_headers", statestats.nSyncHeight);
289 obj.pushKV("synced_blocks", statestats.nCommonHeight);
290 UniValue heights(UniValue::VARR);
291 for (const int height : statestats.vHeightInFlight) {
292 heights.push_back(height);
293 }
294 obj.pushKV("inflight", heights);
295 obj.pushKV("relaytxes", statestats.m_relay_txs);
296 obj.pushKV("minfeefilter",
297 statestats.m_fee_filter_received);
298 obj.pushKV("addr_relay_enabled",
299 statestats.m_addr_relay_enabled);
300 obj.pushKV("addr_processed", statestats.m_addr_processed);
301 obj.pushKV("addr_rate_limited",
302 statestats.m_addr_rate_limited);
303 }
304 UniValue permissions(UniValue::VARR);
305 for (const auto &permission :
306 NetPermissions::ToStrings(stats.m_permission_flags)) {
307 permissions.push_back(permission);
308 }
309 obj.pushKV("permissions", permissions);
310
311 UniValue sendPerMsgCmd(UniValue::VOBJ);
312 for (const auto &i : stats.mapSendBytesPerMsgCmd) {
313 if (i.second > 0) {
314 sendPerMsgCmd.pushKV(i.first, i.second);
315 }
316 }
317 obj.pushKV("bytessent_per_msg", sendPerMsgCmd);
318
319 UniValue recvPerMsgCmd(UniValue::VOBJ);
320 for (const auto &i : stats.mapRecvBytesPerMsgCmd) {
321 if (i.second > 0) {
322 recvPerMsgCmd.pushKV(i.first, i.second);
323 }
324 }
325 obj.pushKV("bytesrecv_per_msg", recvPerMsgCmd);
326 obj.pushKV("connection_type",
327 ConnectionTypeAsString(stats.m_conn_type));
328
329 if (IsDeprecatedRPCEnabled(argsman,
330 "node_availability_score") &&
331 stats.m_availabilityScore) {
332 obj.pushKV("availability_score",
333 *stats.m_availabilityScore);
334 }
335
336 ret.push_back(obj);
337 }
338
339 return ret;
340 },
341 };
342}
343
345 return RPCHelpMan{
346 "addnode",
347 "Attempts to add or remove a node from the addnode list.\n"
348 "Or try a connection to a node once.\n"
349 "Nodes added using addnode (or -connect) are protected from "
350 "DoS disconnection and are not required to be\n"
351 "full nodes as other outbound peers are (though such peers "
352 "will not be synced from).\n",
353 {
355 "The node (see getpeerinfo for nodes)"},
357 "'add' to add a node to the list, 'remove' to remove a "
358 "node from the list, 'onetry' to try a connection to the "
359 "node once"},
360 },
363 HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") +
364 HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")},
365 [&](const RPCHelpMan &self, const Config &config,
366 const JSONRPCRequest &request) -> UniValue {
367 std::string strCommand;
368 if (!request.params[1].isNull()) {
369 strCommand = request.params[1].get_str();
370 }
371
372 if (strCommand != "onetry" && strCommand != "add" &&
373 strCommand != "remove") {
374 throw std::runtime_error(self.ToString());
375 }
376
377 NodeContext &node = EnsureAnyNodeContext(request.context);
378 CConnman &connman = EnsureConnman(node);
379
380 std::string strNode = request.params[0].get_str();
381
382 if (strCommand == "onetry") {
383 CAddress addr;
384 connman.OpenNetworkConnection(addr, false, nullptr,
385 strNode.c_str(),
387 return NullUniValue;
388 }
389
390 if ((strCommand == "add") && (!connman.AddNode(strNode))) {
392 "Error: Node already added");
393 } else if ((strCommand == "remove") &&
394 (!connman.RemoveAddedNode(strNode))) {
395 throw JSONRPCError(
397 "Error: Node could not be removed. It has not been "
398 "added previously.");
399 }
400
401 return NullUniValue;
402 },
403 };
404}
405
407 return RPCHelpMan{
408 "addconnection",
409 "\nOpen an outbound connection to a specified node. This RPC is for "
410 "testing only.\n",
411 {
413 "The IP address and port to attempt connecting to."},
414 {"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO,
415 "Type of connection to open (\"outbound-full-relay\", "
416 "\"block-relay-only\", \"addr-fetch\", \"feeler\" or "
417 "\"avalanche\")."},
418 },
420 "",
421 "",
422 {
423 {RPCResult::Type::STR, "address",
424 "Address of newly added connection."},
425 {RPCResult::Type::STR, "connection_type",
426 "Type of connection opened."},
427 }},
429 HelpExampleCli("addconnection",
430 "\"192.168.0.6:8333\" \"outbound-full-relay\"") +
431 HelpExampleRpc("addconnection",
432 "\"192.168.0.6:8333\" \"outbound-full-relay\"")},
433 [&](const RPCHelpMan &self, const Config &config,
434 const JSONRPCRequest &request) -> UniValue {
435 if (config.GetChainParams().NetworkIDString() !=
437 throw std::runtime_error("addconnection is for regression "
438 "testing (-regtest mode) only.");
439 }
440
441 NodeContext &node = EnsureAnyNodeContext(request.context);
442
443 const std::string address = request.params[0].get_str();
444 const std::string conn_type_in{
445 TrimString(request.params[1].get_str())};
446 ConnectionType conn_type{};
447 if (conn_type_in == "outbound-full-relay") {
449 } else if (conn_type_in == "block-relay-only") {
450 conn_type = ConnectionType::BLOCK_RELAY;
451 } else if (conn_type_in == "addr-fetch") {
452 conn_type = ConnectionType::ADDR_FETCH;
453 } else if (conn_type_in == "feeler") {
454 conn_type = ConnectionType::FEELER;
455 } else if (conn_type_in == "avalanche") {
456 if (!node.avalanche) {
458 "Error: avalanche outbound requested "
459 "but avalanche is not enabled.");
460 }
462 } else {
464 }
465
466 CConnman &connman = EnsureConnman(node);
467
468 const bool success = connman.AddConnection(address, conn_type);
469 if (!success) {
471 "Error: Already at capacity for specified "
472 "connection type.");
473 }
474
476 info.pushKV("address", address);
477 info.pushKV("connection_type", conn_type_in);
478
479 return info;
480 },
481 };
482}
483
485 return RPCHelpMan{
486 "disconnectnode",
487 "Immediately disconnects from the specified peer node.\n"
488 "\nStrictly one out of 'address' and 'nodeid' can be provided to "
489 "identify the node.\n"
490 "\nTo disconnect by nodeid, either set 'address' to the empty string, "
491 "or call using the named 'nodeid' argument only.\n",
492 {
493 {"address", RPCArg::Type::STR,
494 RPCArg::DefaultHint{"fallback to nodeid"},
495 "The IP address/port of the node"},
496 {"nodeid", RPCArg::Type::NUM,
497 RPCArg::DefaultHint{"fallback to address"},
498 "The node ID (see getpeerinfo for node IDs)"},
499 },
501 RPCExamples{HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") +
502 HelpExampleCli("disconnectnode", "\"\" 1") +
503 HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") +
504 HelpExampleRpc("disconnectnode", "\"\", 1")},
505 [&](const RPCHelpMan &self, const Config &config,
506 const JSONRPCRequest &request) -> UniValue {
507 NodeContext &node = EnsureAnyNodeContext(request.context);
508 CConnman &connman = EnsureConnman(node);
509
510 bool success;
511 const UniValue &address_arg = request.params[0];
512 const UniValue &id_arg = request.params[1];
513
514 if (!address_arg.isNull() && id_arg.isNull()) {
515 /* handle disconnect-by-address */
516 success = connman.DisconnectNode(address_arg.get_str());
517 } else if (!id_arg.isNull() && (address_arg.isNull() ||
518 (address_arg.isStr() &&
519 address_arg.get_str().empty()))) {
520 /* handle disconnect-by-id */
521 NodeId nodeid = (NodeId)id_arg.getInt<int64_t>();
522 success = connman.DisconnectNode(nodeid);
523 } else {
524 throw JSONRPCError(
526 "Only one of address and nodeid should be provided.");
527 }
528
529 if (!success) {
531 "Node not found in connected nodes");
532 }
533
534 return NullUniValue;
535 },
536 };
537}
538
540 return RPCHelpMan{
541 "getaddednodeinfo",
542 "Returns information about the given added node, or all added nodes\n"
543 "(note that onetry addnodes are not listed here)\n",
544 {
545 {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"},
546 "If provided, return information about this specific node, "
547 "otherwise all nodes are returned."},
548 },
549 RPCResult{
551 "",
552 "",
553 {
555 "",
556 "",
557 {
558 {RPCResult::Type::STR, "addednode",
559 "The node IP address or name (as provided to addnode)"},
560 {RPCResult::Type::BOOL, "connected", "If connected"},
562 "addresses",
563 "Only when connected = true",
564 {
566 "",
567 "",
568 {
569 {RPCResult::Type::STR, "address",
570 "The bitcoin server IP and port we're "
571 "connected to"},
572 {RPCResult::Type::STR, "connected",
573 "connection, inbound or outbound"},
574 }},
575 }},
576 }},
577 }},
578 RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") +
579 HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")},
580 [&](const RPCHelpMan &self, const Config &config,
581 const JSONRPCRequest &request) -> UniValue {
582 NodeContext &node = EnsureAnyNodeContext(request.context);
583 const CConnman &connman = EnsureConnman(node);
584
585 std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo();
586
587 if (!request.params[0].isNull()) {
588 bool found = false;
589 for (const AddedNodeInfo &info : vInfo) {
590 if (info.strAddedNode == request.params[0].get_str()) {
591 vInfo.assign(1, info);
592 found = true;
593 break;
594 }
595 }
596 if (!found) {
598 "Error: Node has not been added.");
599 }
600 }
601
603
604 for (const AddedNodeInfo &info : vInfo) {
606 obj.pushKV("addednode", info.strAddedNode);
607 obj.pushKV("connected", info.fConnected);
608 UniValue addresses(UniValue::VARR);
609 if (info.fConnected) {
610 UniValue address(UniValue::VOBJ);
611 address.pushKV("address", info.resolvedAddress.ToString());
612 address.pushKV("connected",
613 info.fInbound ? "inbound" : "outbound");
614 addresses.push_back(address);
615 }
616 obj.pushKV("addresses", addresses);
617 ret.push_back(obj);
618 }
619
620 return ret;
621 },
622 };
623}
624
626 return RPCHelpMan{
627 "getnettotals",
628 "Returns information about network traffic, including bytes in, "
629 "bytes out,\n"
630 "and current time.\n",
631 {},
632 RPCResult{
634 "",
635 "",
636 {
637 {RPCResult::Type::NUM, "totalbytesrecv",
638 "Total bytes received"},
639 {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"},
640 {RPCResult::Type::NUM_TIME, "timemillis",
641 "Current " + UNIX_EPOCH_TIME + " in milliseconds"},
643 "uploadtarget",
644 "",
645 {
646 {RPCResult::Type::NUM, "timeframe",
647 "Length of the measuring timeframe in seconds"},
648 {RPCResult::Type::NUM, "target", "Target in bytes"},
649 {RPCResult::Type::BOOL, "target_reached",
650 "True if target is reached"},
651 {RPCResult::Type::BOOL, "serve_historical_blocks",
652 "True if serving historical blocks"},
653 {RPCResult::Type::NUM, "bytes_left_in_cycle",
654 "Bytes left in current time cycle"},
655 {RPCResult::Type::NUM, "time_left_in_cycle",
656 "Seconds left in current time cycle"},
657 }},
658 }},
659 RPCExamples{HelpExampleCli("getnettotals", "") +
660 HelpExampleRpc("getnettotals", "")},
661 [&](const RPCHelpMan &self, const Config &config,
662 const JSONRPCRequest &request) -> UniValue {
663 NodeContext &node = EnsureAnyNodeContext(request.context);
664 const CConnman &connman = EnsureConnman(node);
665
667 obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv());
668 obj.pushKV("totalbytessent", connman.GetTotalBytesSent());
669 obj.pushKV("timemillis", GetTimeMillis());
670
671 UniValue outboundLimit(UniValue::VOBJ);
672 outboundLimit.pushKV(
673 "timeframe", count_seconds(connman.GetMaxOutboundTimeframe()));
674 outboundLimit.pushKV("target", connman.GetMaxOutboundTarget());
675 outboundLimit.pushKV("target_reached",
676 connman.OutboundTargetReached(false));
677 outboundLimit.pushKV("serve_historical_blocks",
678 !connman.OutboundTargetReached(true));
679 outboundLimit.pushKV("bytes_left_in_cycle",
681 outboundLimit.pushKV(
682 "time_left_in_cycle",
684 obj.pushKV("uploadtarget", outboundLimit);
685 return obj;
686 },
687 };
688}
689
691 UniValue networks(UniValue::VARR);
692 for (int n = 0; n < NET_MAX; ++n) {
693 enum Network network = static_cast<enum Network>(n);
694 if (network == NET_UNROUTABLE || network == NET_CJDNS ||
695 network == NET_INTERNAL) {
696 continue;
697 }
698 proxyType proxy;
700 GetProxy(network, proxy);
701 obj.pushKV("name", GetNetworkName(network));
702 obj.pushKV("limited", !IsReachable(network));
703 obj.pushKV("reachable", IsReachable(network));
704 obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort()
705 : std::string());
706 obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
707 networks.push_back(obj);
708 }
709 return networks;
710}
711
713 const auto &ticker = Currency::get().ticker;
714 return RPCHelpMan{
715 "getnetworkinfo",
716 "Returns an object containing various state info regarding P2P "
717 "networking.\n",
718 {},
719 RPCResult{
721 "",
722 "",
723 {
724 {RPCResult::Type::NUM, "version", "the server version"},
725 {RPCResult::Type::STR, "subversion",
726 "the server subversion string"},
727 {RPCResult::Type::NUM, "protocolversion",
728 "the protocol version"},
729 {RPCResult::Type::STR_HEX, "localservices",
730 "the services we offer to the network"},
732 "localservicesnames",
733 "the services we offer to the network, in human-readable form",
734 {
735 {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
736 }},
737 {RPCResult::Type::BOOL, "localrelay",
738 "true if transaction relay is requested from peers"},
739 {RPCResult::Type::NUM, "timeoffset", "the time offset"},
740 {RPCResult::Type::NUM, "connections",
741 "the total number of connections"},
742 {RPCResult::Type::NUM, "connections_in",
743 "the number of inbound connections"},
744 {RPCResult::Type::NUM, "connections_out",
745 "the number of outbound connections"},
746 {RPCResult::Type::BOOL, "networkactive",
747 "whether p2p networking is enabled"},
749 "networks",
750 "information per network",
751 {
753 "",
754 "",
755 {
756 {RPCResult::Type::STR, "name",
757 "network (" + Join(GetNetworkNames(), ", ") + ")"},
758 {RPCResult::Type::BOOL, "limited",
759 "is the network limited using -onlynet?"},
760 {RPCResult::Type::BOOL, "reachable",
761 "is the network reachable?"},
762 {RPCResult::Type::STR, "proxy",
763 "(\"host:port\") the proxy that is used for this "
764 "network, or empty if none"},
765 {RPCResult::Type::BOOL, "proxy_randomize_credentials",
766 "Whether randomized credentials are used"},
767 }},
768 }},
769 {RPCResult::Type::NUM, "relayfee",
770 "minimum relay fee for transactions in " + ticker + "/kB"},
772 "localaddresses",
773 "list of local addresses",
774 {
776 "",
777 "",
778 {
779 {RPCResult::Type::STR, "address", "network address"},
780 {RPCResult::Type::NUM, "port", "network port"},
781 {RPCResult::Type::NUM, "score", "relative score"},
782 }},
783 }},
784 {RPCResult::Type::STR, "warnings",
785 "any network and blockchain warnings"},
786 }},
787 RPCExamples{HelpExampleCli("getnetworkinfo", "") +
788 HelpExampleRpc("getnetworkinfo", "")},
789 [&](const RPCHelpMan &self, const Config &config,
790 const JSONRPCRequest &request) -> UniValue {
791 LOCK(cs_main);
793 obj.pushKV("version", CLIENT_VERSION);
794 obj.pushKV("subversion", userAgent(config));
795 obj.pushKV("protocolversion", PROTOCOL_VERSION);
796 NodeContext &node = EnsureAnyNodeContext(request.context);
797 if (node.connman) {
798 ServiceFlags services = node.connman->GetLocalServices();
799 obj.pushKV("localservices", strprintf("%016x", services));
800 obj.pushKV("localservicesnames", GetServicesNames(services));
801 }
802 if (node.peerman) {
803 obj.pushKV("localrelay", !node.peerman->IgnoresIncomingTxs());
804 }
805 obj.pushKV("timeoffset", GetTimeOffset());
806 if (node.connman) {
807 obj.pushKV("networkactive", node.connman->GetNetworkActive());
808 obj.pushKV("connections", node.connman->GetNodeCount(
810 obj.pushKV("connections_in",
811 node.connman->GetNodeCount(ConnectionDirection::In));
812 obj.pushKV("connections_out", node.connman->GetNodeCount(
814 }
815 obj.pushKV("networks", GetNetworksInfo());
816 if (node.mempool) {
817 // This field can be deprecated, to be replaced by the
818 // getmempoolinfo fields
819 obj.pushKV("relayfee",
820 node.mempool->m_min_relay_feerate.GetFeePerK());
821 }
822 UniValue localAddresses(UniValue::VARR);
823 {
825 for (const std::pair<const CNetAddr, LocalServiceInfo> &item :
826 mapLocalHost) {
828 rec.pushKV("address", item.first.ToString());
829 rec.pushKV("port", item.second.nPort);
830 rec.pushKV("score", item.second.nScore);
831 localAddresses.push_back(rec);
832 }
833 }
834 obj.pushKV("localaddresses", localAddresses);
835 obj.pushKV("warnings", GetWarnings(false).original);
836 return obj;
837 },
838 };
839}
840
842 return RPCHelpMan{
843 "setban",
844 "Attempts to add or remove an IP/Subnet from the banned list.\n",
845 {
847 "The IP/Subnet (see getpeerinfo for nodes IP) with an optional "
848 "netmask (default is /32 = single IP)"},
850 "'add' to add an IP/Subnet to the list, 'remove' to remove an "
851 "IP/Subnet from the list"},
852 {"bantime", RPCArg::Type::NUM, RPCArg::Default{0},
853 "time in seconds how long (or until when if [absolute] is set) "
854 "the IP is banned (0 or empty means using the default time of 24h "
855 "which can also be overwritten by the -bantime startup argument)"},
856 {"absolute", RPCArg::Type::BOOL, RPCArg::Default{false},
857 "If set, the bantime must be an absolute timestamp expressed in " +
859 },
862 HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") +
863 HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") +
864 HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")},
865 [&](const RPCHelpMan &help, const Config &config,
866 const JSONRPCRequest &request) -> UniValue {
867 std::string strCommand;
868 if (!request.params[1].isNull()) {
869 strCommand = request.params[1].get_str();
870 }
871
872 if (strCommand != "add" && strCommand != "remove") {
873 throw std::runtime_error(help.ToString());
874 }
875
876 NodeContext &node = EnsureAnyNodeContext(request.context);
877 if (!node.banman) {
879 "Error: Ban database not loaded");
880 }
881
882 CSubNet subNet;
883 CNetAddr netAddr;
884 bool isSubnet = false;
885
886 if (request.params[0].get_str().find('/') != std::string::npos) {
887 isSubnet = true;
888 }
889
890 if (!isSubnet) {
891 CNetAddr resolved;
892 LookupHost(request.params[0].get_str(), resolved, false);
893 netAddr = resolved;
894 } else {
895 LookupSubNet(request.params[0].get_str(), subNet);
896 }
897
898 if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) {
900 "Error: Invalid IP/Subnet");
901 }
902
903 if (strCommand == "add") {
904 if (isSubnet ? node.banman->IsBanned(subNet)
905 : node.banman->IsBanned(netAddr)) {
907 "Error: IP/Subnet already banned");
908 }
909
910 // Use standard bantime if not specified.
911 int64_t banTime = 0;
912 if (!request.params[2].isNull()) {
913 banTime = request.params[2].getInt<int64_t>();
914 }
915
916 bool absolute = false;
917 if (request.params[3].isTrue()) {
918 absolute = true;
919 }
920
921 if (isSubnet) {
922 node.banman->Ban(subNet, banTime, absolute);
923 if (node.connman) {
924 node.connman->DisconnectNode(subNet);
925 }
926 } else {
927 node.banman->Ban(netAddr, banTime, absolute);
928 if (node.connman) {
929 node.connman->DisconnectNode(netAddr);
930 }
931 }
932 } else if (strCommand == "remove") {
933 if (!(isSubnet ? node.banman->Unban(subNet)
934 : node.banman->Unban(netAddr))) {
935 throw JSONRPCError(
937 "Error: Unban failed. Requested address/subnet "
938 "was not previously manually banned.");
939 }
940 }
941 return NullUniValue;
942 },
943 };
944}
945
947 return RPCHelpMan{
948 "listbanned",
949 "List all manually banned IPs/Subnets.\n",
950 {},
952 "",
953 "",
954 {
956 "",
957 "",
958 {
959 {RPCResult::Type::STR, "address", ""},
960 {RPCResult::Type::NUM_TIME, "banned_until", ""},
961 {RPCResult::Type::NUM_TIME, "ban_created", ""},
962 {RPCResult::Type::STR, "ban_reason", ""},
963 }},
964 }},
965 RPCExamples{HelpExampleCli("listbanned", "") +
966 HelpExampleRpc("listbanned", "")},
967 [&](const RPCHelpMan &self, const Config &config,
968 const JSONRPCRequest &request) -> UniValue {
969 NodeContext &node = EnsureAnyNodeContext(request.context);
970 if (!node.banman) {
972 "Error: Ban database not loaded");
973 }
974
975 banmap_t banMap;
976 node.banman->GetBanned(banMap);
977
978 UniValue bannedAddresses(UniValue::VARR);
979 for (const auto &entry : banMap) {
980 const CBanEntry &banEntry = entry.second;
982 rec.pushKV("address", entry.first.ToString());
983 rec.pushKV("banned_until", banEntry.nBanUntil);
984 rec.pushKV("ban_created", banEntry.nCreateTime);
985
986 bannedAddresses.push_back(rec);
987 }
988
989 return bannedAddresses;
990 },
991 };
992}
993
995 return RPCHelpMan{
996 "clearbanned",
997 "Clear all banned IPs.\n",
998 {},
1000 RPCExamples{HelpExampleCli("clearbanned", "") +
1001 HelpExampleRpc("clearbanned", "")},
1002 [&](const RPCHelpMan &self, const Config &config,
1003 const JSONRPCRequest &request) -> UniValue {
1004 NodeContext &node = EnsureAnyNodeContext(request.context);
1005 if (!node.banman) {
1006 throw JSONRPCError(
1008 "Error: Peer-to-peer functionality missing or disabled");
1009 }
1010
1011 node.banman->ClearBanned();
1012
1013 return NullUniValue;
1014 },
1015 };
1016}
1017
1019 return RPCHelpMan{
1020 "setnetworkactive",
1021 "Disable/enable all p2p network activity.\n",
1022 {
1024 "true to enable networking, false to disable"},
1025 },
1026 RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
1027 RPCExamples{""},
1028 [&](const RPCHelpMan &self, const Config &config,
1029 const JSONRPCRequest &request) -> UniValue {
1030 NodeContext &node = EnsureAnyNodeContext(request.context);
1031 CConnman &connman = EnsureConnman(node);
1032
1033 connman.SetNetworkActive(request.params[0].get_bool());
1034
1035 return connman.GetNetworkActive();
1036 },
1037 };
1038}
1039
1041 return RPCHelpMan{
1042 "getnodeaddresses",
1043 "Return known addresses, which can potentially be used to find new "
1044 "nodes in the network.\n",
1045 {
1046 {"count", RPCArg::Type::NUM, RPCArg::Default{1},
1047 "The maximum number of addresses to return. Specify 0 to return "
1048 "all known addresses."},
1049 {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"},
1050 "Return only addresses of the specified network. Can be one of: " +
1051 Join(GetNetworkNames(), ", ") + "."},
1052 },
1054 "",
1055 "",
1056 {
1058 "",
1059 "",
1060 {
1062 "The " + UNIX_EPOCH_TIME +
1063 " when the node was last seen"},
1064 {RPCResult::Type::NUM, "services",
1065 "The services offered by the node"},
1066 {RPCResult::Type::STR, "address",
1067 "The address of the node"},
1068 {RPCResult::Type::NUM, "port",
1069 "The port number of the node"},
1070 {RPCResult::Type::STR, "network",
1071 "The network (" + Join(GetNetworkNames(), ", ") +
1072 ") the node connected through"},
1073 }},
1074 }},
1075 RPCExamples{HelpExampleCli("getnodeaddresses", "8") +
1076 HelpExampleCli("getnodeaddresses", "4 \"i2p\"") +
1077 HelpExampleCli("-named getnodeaddresses",
1078 "network=onion count=12") +
1079 HelpExampleRpc("getnodeaddresses", "8") +
1080 HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")},
1081 [&](const RPCHelpMan &self, const Config &config,
1082 const JSONRPCRequest &request) -> UniValue {
1083 NodeContext &node = EnsureAnyNodeContext(request.context);
1084 const CConnman &connman = EnsureConnman(node);
1085
1086 const int count{request.params[0].isNull()
1087 ? 1
1088 : request.params[0].getInt<int>()};
1089 if (count < 0) {
1091 "Address count out of range");
1092 }
1093
1094 const std::optional<Network> network{
1095 request.params[1].isNull()
1096 ? std::nullopt
1097 : std::optional<Network>{
1098 ParseNetwork(request.params[1].get_str())}};
1099 if (network == NET_UNROUTABLE) {
1101 strprintf("Network not recognized: %s",
1102 request.params[1].get_str()));
1103 }
1104 // returns a shuffled list of CAddress
1105 const std::vector<CAddress> vAddr{
1106 connman.GetAddresses(count, /* max_pct */ 0, network)};
1108
1109 for (const CAddress &addr : vAddr) {
1111 obj.pushKV(
1112 "time",
1113 int64_t{TicksSinceEpoch<std::chrono::seconds>(addr.nTime)});
1114 obj.pushKV("services", uint64_t(addr.nServices));
1115 obj.pushKV("address", addr.ToStringIP());
1116 obj.pushKV("port", addr.GetPort());
1117 obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
1118 ret.push_back(obj);
1119 }
1120 return ret;
1121 },
1122 };
1123}
1124
1126 return RPCHelpMan{
1127 "addpeeraddress",
1128 "Add the address of a potential peer to the address manager. This "
1129 "RPC is for testing only.\n",
1130 {
1132 "The IP address of the peer"},
1134 "The port of the peer"},
1135 {"tried", RPCArg::Type::BOOL, RPCArg::Default{false},
1136 "If true, attempt to add the peer to the tried addresses table"},
1137 },
1138 RPCResult{
1140 "",
1141 "",
1142 {
1143 {RPCResult::Type::BOOL, "success",
1144 "whether the peer address was successfully added to the "
1145 "address manager"},
1146 },
1147 },
1149 HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true") +
1150 HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")},
1151 [&](const RPCHelpMan &self, const Config &config,
1152 const JSONRPCRequest &request) -> UniValue {
1153 NodeContext &node = EnsureAnyNodeContext(request.context);
1154 if (!node.addrman) {
1155 throw JSONRPCError(
1157 "Error: Address manager functionality missing or disabled");
1158 }
1159
1160 const std::string &addr_string{request.params[0].get_str()};
1161 const uint16_t port{
1162 static_cast<uint16_t>(request.params[1].getInt<int>())};
1163 const bool tried{request.params[2].isTrue()};
1164
1166 CNetAddr net_addr;
1167 bool success{false};
1168
1169 if (LookupHost(addr_string, net_addr, false)) {
1170 CAddress address{{net_addr, port}, ServiceFlags(NODE_NETWORK)};
1171 address.nTime = Now<NodeSeconds>();
1172 // The source address is set equal to the address. This is
1173 // equivalent to the peer announcing itself.
1174 if (node.addrman->Add({address}, address)) {
1175 success = true;
1176 if (tried) {
1177 // Attempt to move the address to the tried addresses
1178 // table.
1179 node.addrman->Good(address);
1180 }
1181 }
1182 }
1183
1184 obj.pushKV("success", success);
1185 return obj;
1186 },
1187 };
1188}
1189
1191 return RPCHelpMan{
1192 "sendmsgtopeer",
1193 "Send a p2p message to a peer specified by id.\n"
1194 "The message type and body must be provided, the message header will "
1195 "be generated.\n"
1196 "This RPC is for testing only.",
1197 {
1199 "The peer to send the message to."},
1201 strprintf("The message type (maximum length %i)",
1204 "The serialized message body to send, in hex, without a message "
1205 "header"},
1206 },
1207 RPCResult{RPCResult::Type::OBJ, "", "", std::vector<RPCResult>{}},
1208 RPCExamples{HelpExampleCli("sendmsgtopeer", "0 \"addr\" \"ffffff\"") +
1209 HelpExampleRpc("sendmsgtopeer", "0 \"addr\" \"ffffff\"")},
1210 [&](const RPCHelpMan &self, const Config &config,
1211 const JSONRPCRequest &request) -> UniValue {
1212 const NodeId peer_id{request.params[0].getInt<int64_t>()};
1213 const std::string &msg_type{request.params[1].get_str()};
1214 if (msg_type.size() > CMessageHeader::COMMAND_SIZE) {
1215 throw JSONRPCError(
1217 strprintf("Error: msg_type too long, max length is %i",
1219 }
1220 auto msg{TryParseHex<uint8_t>(request.params[2].get_str())};
1221 if (!msg.has_value()) {
1223 "Error parsing input for msg");
1224 }
1225
1226 NodeContext &node = EnsureAnyNodeContext(request.context);
1227 CConnman &connman = EnsureConnman(node);
1228
1229 CSerializedNetMsg msg_ser;
1230 msg_ser.data = msg.value();
1231 msg_ser.m_type = msg_type;
1232
1233 bool success = connman.ForNode(peer_id, [&](CNode *node) {
1234 connman.PushMessage(node, std::move(msg_ser));
1235 return true;
1236 });
1237
1238 if (!success) {
1240 "Error: Could not send message to peer");
1241 }
1242
1244 return ret;
1245 },
1246 };
1247}
1248
1250 // clang-format off
1251 static const CRPCCommand commands[] = {
1252 // category actor (function)
1253 // ------------------ ----------------------
1254 { "network", getconnectioncount, },
1255 { "network", ping, },
1256 { "network", getpeerinfo, },
1257 { "network", addnode, },
1258 { "network", disconnectnode, },
1259 { "network", getaddednodeinfo, },
1260 { "network", getnettotals, },
1261 { "network", getnetworkinfo, },
1262 { "network", setban, },
1263 { "network", listbanned, },
1264 { "network", clearbanned, },
1265 { "network", setnetworkactive, },
1266 { "network", getnodeaddresses, },
1267 { "hidden", addconnection, },
1268 { "hidden", addpeeraddress, },
1269 { "hidden", sendmsgtopeer },
1270 };
1271 // clang-format on
1272 for (const auto &c : commands) {
1273 t.appendCommand(c.name, &c);
1274 }
1275}
A CService with information about it as peer.
Definition: protocol.h:442
Definition: addrdb.h:30
int64_t nCreateTime
Definition: addrdb.h:34
int64_t nBanUntil
Definition: addrdb.h:35
static const std::string REGTEST
Definition: net.h:856
std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const
returns the time in second left in the current max outbound cycle in case of no limit,...
Definition: net.cpp:3218
bool OutboundTargetReached(bool historicalBlockServingLimit) const
check if the outbound target is reached.
Definition: net.cpp:3234
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3403
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1415
bool RemoveAddedNode(const std::string &node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:3090
bool GetNetworkActive() const
Definition: net.h:948
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:3257
std::chrono::seconds GetMaxOutboundTimeframe() const
Definition: net.cpp:3214
bool DisconnectNode(const std::string &node)
Definition: net.cpp:3145
uint64_t GetMaxOutboundTarget() const
Definition: net.cpp:3209
size_t GetNodeCount(ConnectionDirection) const
Definition: net.cpp:3102
void GetNodeStats(std::vector< CNodeStats > &vstats) const
Definition: net.cpp:3120
std::vector< AddedNodeInfo > GetAddedNodeInfo() const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:2335
uint64_t GetTotalBytesRecv() const
Definition: net.cpp:3268
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:3012
void SetNetworkActive(bool active)
Definition: net.cpp:2695
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2424
bool AddNode(const std::string &node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
Definition: net.cpp:3078
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3357
uint64_t GetTotalBytesSent() const
Definition: net.cpp:3272
static constexpr size_t COMMAND_SIZE
Definition: protocol.h:37
Network address.
Definition: netaddress.h:121
bool IsValid() const
Definition: netaddress.cpp:477
Information about a peer.
Definition: net.h:460
RPC command dispatcher.
Definition: server.h:194
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:327
std::string ToStringIPPort() const
bool IsValid() const
Definition: config.h:19
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
virtual void SendPings()=0
Send ping message to all peers.
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) const =0
Get statistics from node state.
std::string ToString() const
Definition: util.cpp:664
void push_back(UniValue val)
Definition: univalue.cpp:96
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:31
@ VARR
Definition: univalue.h:32
bool isNull() const
Definition: univalue.h:104
bool isStr() const
Definition: univalue.h:108
Int getInt() const
Definition: univalue.h:157
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:115
bool IsValid() const
Definition: netbase.h:58
CService proxy
Definition: netbase.h:60
bool randomize_credentials
Definition: netbase.h:61
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:38
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
static path absolute(const path &p)
Definition: fs.h:96
Definition: init.h:28
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:112
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:127
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
Definition: net.cpp:599
std::string userAgent(const Config &config)
Definition: net.cpp:3455
bool IsReachable(enum Network net)
Definition: net.cpp:325
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.h:135
ConnectionType
Different types of connections to a peer.
Definition: net.h:148
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly inputted via the addnode RPC,...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
@ AVALANCHE_OUTBOUND
Special case of connection to a full relay outbound with avalanche service enabled.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
Network
A network type.
Definition: netaddress.h:44
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:62
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:69
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:47
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:66
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:114
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:715
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:781
enum Network ParseNetwork(const std::string &net_in)
Definition: netbase.cpp:92
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:191
std::vector< std::string > GetNetworkNames(bool append_unroutable)
Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE.
Definition: netbase.cpp:137
int64_t NodeId
Definition: nodeid.h:10
ServiceFlags
nServices flags.
Definition: protocol.h:335
@ NODE_NONE
Definition: protocol.h:338
@ NODE_NETWORK
Definition: protocol.h:342
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:58
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
Definition: net.cpp:1249
static RPCHelpMan getnetworkinfo()
Definition: net.cpp:712
static RPCHelpMan addconnection()
Definition: net.cpp:406
static RPCHelpMan getaddednodeinfo()
Definition: net.cpp:539
static RPCHelpMan clearbanned()
Definition: net.cpp:994
static RPCHelpMan getnettotals()
Definition: net.cpp:625
static RPCHelpMan addnode()
Definition: net.cpp:344
static RPCHelpMan getnodeaddresses()
Definition: net.cpp:1040
static RPCHelpMan setban()
Definition: net.cpp:841
static UniValue GetNetworksInfo()
Definition: net.cpp:690
static RPCHelpMan ping()
Definition: net.cpp:57
static RPCHelpMan getconnectioncount()
Definition: net.cpp:39
static RPCHelpMan disconnectnode()
Definition: net.cpp:484
static RPCHelpMan listbanned()
Definition: net.cpp:946
static RPCHelpMan setnetworkactive()
Definition: net.cpp:1018
static RPCHelpMan addpeeraddress()
Definition: net.cpp:1125
static RPCHelpMan getpeerinfo()
Definition: net.cpp:82
static RPCHelpMan sendmsgtopeer()
Definition: net.cpp:1190
@ RPC_CLIENT_NODE_NOT_CONNECTED
Node to disconnect not found in connected nodes.
Definition: protocol.h:77
@ RPC_CLIENT_INVALID_IP_OR_SUBNET
Invalid IP/Subnet.
Definition: protocol.h:79
@ RPC_MISC_ERROR
General application defined errors std::exception thrown in command handling.
Definition: protocol.h:38
@ RPC_CLIENT_NODE_ALREADY_ADDED
Node is already added.
Definition: protocol.h:73
@ RPC_INVALID_PARAMS
Definition: protocol.h:30
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition: protocol.h:46
@ RPC_DATABASE_ERROR
Database error.
Definition: protocol.h:48
@ RPC_CLIENT_NODE_NOT_ADDED
Node has not been added before.
Definition: protocol.h:75
@ RPC_CLIENT_NODE_CAPACITY_REACHED
Max number of outbound or block-relay connections already open.
Definition: protocol.h:83
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition: protocol.h:81
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:150
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
Definition: util.cpp:1337
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:167
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:22
bool IsDeprecatedRPCEnabled(const ArgsManager &args, const std::string &method)
Definition: server.cpp:407
static RPCHelpMan help()
Definition: server.cpp:182
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:21
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:72
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition: server_util.cpp:41
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:63
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:63
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Definition: string.h:38
std::chrono::microseconds m_ping_wait
Amount m_fee_filter_received
std::vector< int > vHeightInFlight
uint64_t m_addr_rate_limited
uint64_t m_addr_processed
int64_t presync_height
ServiceFlags their_services
POD that contains various stats about a node.
Definition: net.h:287
std::vector< uint8_t > data
Definition: net.h:131
std::string m_type
Definition: net.h:132
static const Currency & get()
Definition: amount.cpp:18
std::string ticker
Definition: amount.h:150
@ STR_HEX
Special type that is a STR with only hex chars.
std::string DefaultHint
Hint for default value.
Definition: util.h:195
@ NO
Required arg.
@ NUM_TIME
Special numeric to denote unix epoch time.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43
#define LOCK(cs)
Definition: sync.h:306
static int count
Definition: tests.c:31
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:101
constexpr int64_t count_seconds(std::chrono::seconds t)
Definition: time.h:55
double CountSecondsDouble(SecondsDouble t)
Helper to count the seconds in any std::chrono::duration type.
Definition: time.h:72
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are:
Definition: timedata.cpp:30
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
const UniValue NullUniValue
Definition: univalue.cpp:16
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11
bilingual_str GetWarnings(bool verbose)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:41