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