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