LCOV - code coverage report
Current view: top level - src/rpc - net.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 97.8 % 835 817
Test Date: 2026-01-10 05:14:10 Functions: 100.0 % 41 41
Branches: 50.5 % 3126 1579

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2009-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <rpc/server.h>
       6                 :             : 
       7                 :             : #include <addrman.h>
       8                 :             : #include <addrman_impl.h>
       9                 :             : #include <banman.h>
      10                 :             : #include <chainparams.h>
      11                 :             : #include <clientversion.h>
      12                 :             : #include <core_io.h>
      13                 :             : #include <net_permissions.h>
      14                 :             : #include <net_processing.h>
      15                 :             : #include <net_types.h>
      16                 :             : #include <netbase.h>
      17                 :             : #include <node/context.h>
      18                 :             : #include <node/protocol_version.h>
      19                 :             : #include <node/warnings.h>
      20                 :             : #include <policy/settings.h>
      21                 :             : #include <protocol.h>
      22                 :             : #include <rpc/blockchain.h>
      23                 :             : #include <rpc/protocol.h>
      24                 :             : #include <rpc/server_util.h>
      25                 :             : #include <rpc/util.h>
      26                 :             : #include <sync.h>
      27                 :             : #include <univalue.h>
      28                 :             : #include <util/chaintype.h>
      29                 :             : #include <util/strencodings.h>
      30                 :             : #include <util/string.h>
      31                 :             : #include <util/time.h>
      32                 :             : #include <util/translation.h>
      33                 :             : #include <validation.h>
      34                 :             : 
      35                 :             : #include <chrono>
      36                 :             : #include <optional>
      37                 :             : #include <stdexcept>
      38                 :             : #include <string>
      39                 :             : #include <string_view>
      40                 :             : #include <vector>
      41                 :             : 
      42                 :             : using node::NodeContext;
      43                 :             : using util::Join;
      44                 :             : 
      45                 :             : const std::vector<std::string> CONNECTION_TYPE_DOC{
      46                 :             :         "outbound-full-relay (default automatic connections)",
      47                 :             :         "block-relay-only (does not relay transactions or addresses)",
      48                 :             :         "inbound (initiated by the peer)",
      49                 :             :         "manual (added via addnode RPC or -addnode/-connect configuration options)",
      50                 :             :         "addr-fetch (short-lived automatic connection for soliciting addresses)",
      51                 :             :         "feeler (short-lived automatic connection for testing addresses)"
      52                 :             : };
      53                 :             : 
      54                 :             : const std::vector<std::string> TRANSPORT_TYPE_DOC{
      55                 :             :     "detecting (peer could be v1 or v2)",
      56                 :             :     "v1 (plaintext transport protocol)",
      57                 :             :     "v2 (BIP324 encrypted transport protocol)"
      58                 :             : };
      59                 :             : 
      60                 :        2375 : static RPCHelpMan getconnectioncount()
      61                 :             : {
      62                 :        2375 :     return RPCHelpMan{
      63                 :        2375 :         "getconnectioncount",
      64         [ +  - ]:        4750 :         "Returns the number of connections to other nodes.\n",
      65                 :             :                 {},
      66         [ +  - ]:        4750 :                 RPCResult{
      67         [ +  - ]:        4750 :                     RPCResult::Type::NUM, "", "The connection count"
      68         [ +  - ]:        4750 :                 },
      69                 :        2375 :                 RPCExamples{
      70   [ +  -  +  -  :        4750 :                     HelpExampleCli("getconnectioncount", "")
                   +  - ]
      71   [ +  -  +  -  :        9500 :             + HelpExampleRpc("getconnectioncount", "")
             +  -  +  - ]
      72         [ +  - ]:        2375 :                 },
      73                 :        2375 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      74                 :             : {
      75                 :           6 :     NodeContext& node = EnsureAnyNodeContext(request.context);
      76                 :           6 :     const CConnman& connman = EnsureConnman(node);
      77                 :             : 
      78                 :           6 :     return connman.GetNodeCount(ConnectionDirection::Both);
      79                 :             : },
      80   [ +  -  +  - ]:        9500 :     };
      81                 :             : }
      82                 :             : 
      83                 :        2372 : static RPCHelpMan ping()
      84                 :             : {
      85                 :        2372 :     return RPCHelpMan{
      86                 :        2372 :         "ping",
      87         [ +  - ]:        4744 :         "Requests that a ping be sent to all other nodes, to measure ping time.\n"
      88                 :             :                 "Results are provided in getpeerinfo.\n"
      89                 :             :                 "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n",
      90                 :             :                 {},
      91   [ +  -  +  -  :        4744 :                 RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
      92                 :        2372 :                 RPCExamples{
      93   [ +  -  +  -  :        4744 :                     HelpExampleCli("ping", "")
                   +  - ]
      94   [ +  -  +  -  :        9488 :             + HelpExampleRpc("ping", "")
             +  -  +  - ]
      95         [ +  - ]:        2372 :                 },
      96                 :        2372 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      97                 :             : {
      98                 :           3 :     NodeContext& node = EnsureAnyNodeContext(request.context);
      99                 :           3 :     PeerManager& peerman = EnsurePeerman(node);
     100                 :             : 
     101                 :             :     // Request that each node send a ping during next message processing pass
     102                 :           3 :     peerman.SendPings();
     103                 :           3 :     return UniValue::VNULL;
     104                 :             : },
     105   [ +  -  +  - ]:        9488 :     };
     106                 :             : }
     107                 :             : 
     108                 :             : /** Returns, given services flags, a list of humanly readable (known) network services */
     109                 :       13936 : static UniValue GetServicesNames(ServiceFlags services)
     110                 :             : {
     111                 :       13936 :     UniValue servicesNames(UniValue::VARR);
     112                 :             : 
     113   [ +  -  +  + ]:       50134 :     for (const auto& flag : serviceFlagsToStr(services)) {
     114   [ +  -  +  - ]:       36198 :         servicesNames.push_back(flag);
     115                 :       13936 :     }
     116                 :             : 
     117                 :       13936 :     return servicesNames;
     118                 :           0 : }
     119                 :             : 
     120                 :        8511 : static RPCHelpMan getpeerinfo()
     121                 :             : {
     122                 :        8511 :     return RPCHelpMan{
     123                 :        8511 :         "getpeerinfo",
     124         [ +  - ]:       17022 :         "Returns data about each connected network peer as a json array of objects.",
     125                 :             :         {},
     126         [ +  - ]:       17022 :         RPCResult{
     127         [ +  - ]:       17022 :             RPCResult::Type::ARR, "", "",
     128                 :             :             {
     129   [ +  -  +  - ]:       17022 :                 {RPCResult::Type::OBJ, "", "",
     130                 :             :                 {
     131                 :             :                     {
     132   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "id", "Peer index"},
     133   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::STR, "addr", "(host:port) The IP address/hostname optionally followed by :port of the peer"},
     134   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::STR, "addrbind", /*optional=*/true, "(ip:port) Bind address of the connection to the peer"},
     135   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::STR, "addrlocal", /*optional=*/true, "(ip:port) Local address as reported by the peer"},
     136   [ +  -  +  -  :       17022 :                     {RPCResult::Type::STR, "network", "Network (" + Join(GetNetworkNames(/*append_unroutable=*/true), ", ") + ")"},
             +  -  +  - ]
     137   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "mapped_as", /*optional=*/true, "Mapped AS (Autonomous System) number at the end of the BGP route to the peer, used for diversifying\n"
     138                 :             :                                                         "peer selection (only displayed if the -asmap config option is set)"},
     139   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::STR_HEX, "services", "The services offered"},
     140   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::ARR, "servicesnames", "the services offered, in human-readable form",
     141                 :             :                     {
     142   [ +  -  +  - ]:       17022 :                         {RPCResult::Type::STR, "SERVICE_NAME", "the service name if it is recognised"}
     143                 :             :                     }},
     144   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::BOOL, "relaytxes", "Whether we relay transactions to this peer"},
     145   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "last_inv_sequence", "Mempool sequence number of this peer's last INV"},
     146   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "inv_to_send", "How many txs we have queued to announce to this peer"},
     147   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM_TIME, "lastsend", "The " + UNIX_EPOCH_TIME + " of the last send"},
     148   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM_TIME, "lastrecv", "The " + UNIX_EPOCH_TIME + " of the last receive"},
     149   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM_TIME, "last_transaction", "The " + UNIX_EPOCH_TIME + " of the last valid transaction received from this peer"},
     150   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM_TIME, "last_block", "The " + UNIX_EPOCH_TIME + " of the last block received from this peer"},
     151   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "bytessent", "The total bytes sent"},
     152   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "bytesrecv", "The total bytes received"},
     153   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM_TIME, "conntime", "The " + UNIX_EPOCH_TIME + " of the connection"},
     154   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "timeoffset", "The time offset in seconds"},
     155   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "pingtime", /*optional=*/true, "The last ping time in seconds, if any"},
     156   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "minping", /*optional=*/true, "The minimum observed ping time in seconds, if any"},
     157   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "pingwait", /*optional=*/true, "The duration in seconds of an outstanding ping (if non-zero)"},
     158   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "version", "The peer version, such as 70001"},
     159   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::STR, "subver", "The string version"},
     160   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
     161   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::BOOL, "bip152_hb_to", "Whether we selected peer as (compact blocks) high-bandwidth peer"},
     162   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::BOOL, "bip152_hb_from", "Whether peer selected us as (compact blocks) high-bandwidth peer"},
     163   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "startingheight", /*optional=*/true, "(DEPRECATED, returned only if config option -deprecatedrpc=startingheight is passed) The starting height (block) of the peer"},
     164   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "presynced_headers", "The current height of header pre-synchronization with this peer, or -1 if no low-work sync is in progress"},
     165   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
     166   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"},
     167   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::ARR, "inflight", "",
     168                 :             :                     {
     169   [ +  -  +  - ]:       17022 :                         {RPCResult::Type::NUM, "n", "The heights of blocks we're currently asking from this peer"},
     170                 :             :                     }},
     171   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::BOOL, "addr_relay_enabled", "Whether we participate in address relay with this peer"},
     172   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "addr_processed", "The total number of addresses processed, excluding those dropped due to rate limiting"},
     173   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "addr_rate_limited", "The total number of addresses dropped due to rate limiting"},
     174   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::ARR, "permissions", "Any special permissions that have been granted to this peer",
     175                 :             :                     {
     176   [ +  -  +  - ]:       17022 :                         {RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"},
     177                 :             :                     }},
     178   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::NUM, "minfeefilter", "The minimum fee rate for transactions this peer accepts"},
     179   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::OBJ_DYN, "bytessent_per_msg", "",
     180                 :             :                     {
     181   [ +  -  +  - ]:       17022 :                         {RPCResult::Type::NUM, "msg", "The total bytes sent aggregated by message type\n"
     182                 :             :                                                       "When a message type is not listed in this json object, the bytes sent are 0.\n"
     183                 :             :                                                       "Only known message types can appear as keys in the object."}
     184                 :             :                     }},
     185   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::OBJ_DYN, "bytesrecv_per_msg", "",
     186                 :             :                     {
     187         [ +  - ]:       17022 :                         {RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n"
     188                 :             :                                                       "When a message type is not listed in this json object, the bytes received are 0.\n"
     189                 :             :                                                       "Only known message types can appear as keys in the object and all bytes received\n"
     190         [ +  - ]:       17022 :                                                       "of unknown message types are listed under '"+NET_MESSAGE_TYPE_OTHER+"'."}
     191                 :             :                     }},
     192   [ +  -  +  -  :       17022 :                     {RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
                   +  - ]
     193                 :             :                                                               "Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
     194                 :        8511 :                                                               "best capture connection behaviors."},
     195   [ +  -  +  -  :       17022 :                     {RPCResult::Type::STR, "transport_protocol_type", "Type of transport protocol: \n" + Join(TRANSPORT_TYPE_DOC, ",\n") + ".\n"},
                   +  - ]
     196   [ +  -  +  - ]:       17022 :                     {RPCResult::Type::STR, "session_id", "The session ID for this connection, or \"\" if there is none (\"v2\" transport protocol only).\n"},
     197                 :             :                 }},
     198                 :             :             }},
     199   [ +  -  +  -  :      825567 :         },
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  -  -  -  -  
          -  -  -  -  -  
             -  -  -  -  
                      - ]
     200                 :        8511 :         RPCExamples{
     201   [ +  -  +  -  :       17022 :             HelpExampleCli("getpeerinfo", "")
                   +  - ]
     202   [ +  -  +  -  :       34044 :             + HelpExampleRpc("getpeerinfo", "")
             +  -  +  - ]
     203         [ +  - ]:        8511 :         },
     204                 :        8511 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     205                 :             : {
     206                 :        6140 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     207                 :        6140 :     const CConnman& connman = EnsureConnman(node);
     208                 :        6140 :     const PeerManager& peerman = EnsurePeerman(node);
     209                 :             : 
     210                 :        6140 :     std::vector<CNodeStats> vstats;
     211         [ +  - ]:        6140 :     connman.GetNodeStats(vstats);
     212                 :             : 
     213                 :        6140 :     UniValue ret(UniValue::VARR);
     214                 :             : 
     215         [ +  + ]:       19105 :     for (const CNodeStats& stats : vstats) {
     216                 :       12965 :         UniValue obj(UniValue::VOBJ);
     217         [ +  - ]:       12965 :         CNodeStateStats statestats;
     218         [ +  - ]:       12965 :         bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats);
     219                 :             :         // GetNodeStateStats() requires the existence of a CNodeState and a Peer object
     220                 :             :         // to succeed for this peer. These are created at connection initialisation and
     221                 :             :         // exist for the duration of the connection - except if there is a race where the
     222                 :             :         // peer got disconnected in between the GetNodeStats() and the GetNodeStateStats()
     223                 :             :         // calls. In this case, the peer doesn't need to be reported here.
     224         [ +  + ]:       12965 :         if (!fStateStats) {
     225                 :           7 :             continue;
     226                 :             :         }
     227   [ +  -  +  -  :       25916 :         obj.pushKV("id", stats.nodeid);
                   +  - ]
     228   [ +  -  +  -  :       25916 :         obj.pushKV("addr", stats.m_addr_name);
                   +  - ]
     229   [ +  -  +  + ]:       12958 :         if (stats.addrBind.IsValid()) {
     230   [ +  -  +  -  :       25910 :             obj.pushKV("addrbind", stats.addrBind.ToStringAddrPort());
             +  -  +  - ]
     231                 :             :         }
     232         [ +  + ]:       12958 :         if (!(stats.addrLocal.empty())) {
     233   [ +  -  +  -  :        9120 :             obj.pushKV("addrlocal", stats.addrLocal);
                   +  - ]
     234                 :             :         }
     235   [ +  -  +  -  :       25916 :         obj.pushKV("network", GetNetworkName(stats.m_network));
             +  -  +  - ]
     236         [ -  + ]:       12958 :         if (stats.m_mapped_as != 0) {
     237   [ #  #  #  #  :           0 :             obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
                   #  # ]
     238                 :             :         }
     239                 :       12958 :         ServiceFlags services{statestats.their_services};
     240   [ +  -  +  -  :       25916 :         obj.pushKV("services", strprintf("%016x", services));
             +  -  +  - ]
     241   [ +  -  +  -  :       25916 :         obj.pushKV("servicesnames", GetServicesNames(services));
                   +  - ]
     242   [ +  -  +  -  :       25916 :         obj.pushKV("relaytxes", statestats.m_relay_txs);
                   +  - ]
     243   [ +  -  +  -  :       25916 :         obj.pushKV("last_inv_sequence", statestats.m_last_inv_seq);
                   +  - ]
     244   [ +  -  +  -  :       25916 :         obj.pushKV("inv_to_send", statestats.m_inv_to_send);
                   +  - ]
     245   [ +  -  +  -  :       25916 :         obj.pushKV("lastsend", count_seconds(stats.m_last_send));
                   +  - ]
     246   [ +  -  +  -  :       25916 :         obj.pushKV("lastrecv", count_seconds(stats.m_last_recv));
                   +  - ]
     247   [ +  -  +  -  :       25916 :         obj.pushKV("last_transaction", count_seconds(stats.m_last_tx_time));
                   +  - ]
     248   [ +  -  +  -  :       25916 :         obj.pushKV("last_block", count_seconds(stats.m_last_block_time));
                   +  - ]
     249   [ +  -  +  -  :       25916 :         obj.pushKV("bytessent", stats.nSendBytes);
                   +  - ]
     250   [ +  -  +  -  :       25916 :         obj.pushKV("bytesrecv", stats.nRecvBytes);
                   +  - ]
     251   [ +  -  +  -  :       25916 :         obj.pushKV("conntime", count_seconds(stats.m_connected));
                   +  - ]
     252   [ +  -  +  -  :       25916 :         obj.pushKV("timeoffset", Ticks<std::chrono::seconds>(statestats.time_offset));
                   +  - ]
     253         [ +  + ]:       12958 :         if (stats.m_last_ping_time > 0us) {
     254   [ +  -  +  -  :       18406 :             obj.pushKV("pingtime", Ticks<SecondsDouble>(stats.m_last_ping_time));
                   +  - ]
     255                 :             :         }
     256         [ +  + ]:       12958 :         if (stats.m_min_ping_time < std::chrono::microseconds::max()) {
     257   [ +  -  +  -  :       24358 :             obj.pushKV("minping", Ticks<SecondsDouble>(stats.m_min_ping_time));
                   +  - ]
     258                 :             :         }
     259         [ +  + ]:       12958 :         if (statestats.m_ping_wait > 0s) {
     260   [ +  -  +  -  :         102 :             obj.pushKV("pingwait", Ticks<SecondsDouble>(statestats.m_ping_wait));
                   +  - ]
     261                 :             :         }
     262   [ +  -  +  -  :       25916 :         obj.pushKV("version", stats.nVersion);
                   +  - ]
     263                 :             :         // Use the sanitized form of subver here, to avoid tricksy remote peers from
     264                 :             :         // corrupting or modifying the JSON output by putting special characters in
     265                 :             :         // their ver message.
     266   [ +  -  +  -  :       25916 :         obj.pushKV("subver", stats.cleanSubVer);
                   +  - ]
     267   [ +  -  +  -  :       25916 :         obj.pushKV("inbound", stats.fInbound);
                   +  - ]
     268   [ +  -  +  -  :       25916 :         obj.pushKV("bip152_hb_to", stats.m_bip152_highbandwidth_to);
                   +  - ]
     269   [ +  -  +  -  :       25916 :         obj.pushKV("bip152_hb_from", stats.m_bip152_highbandwidth_from);
                   +  - ]
     270   [ +  -  +  -  :       12958 :         if (IsDeprecatedRPCEnabled("startingheight")) {
                   +  + ]
     271   [ +  -  +  -  :         232 :             obj.pushKV("startingheight", statestats.m_starting_height);
                   +  - ]
     272                 :             :         }
     273   [ +  -  +  -  :       25916 :         obj.pushKV("presynced_headers", statestats.presync_height);
                   +  - ]
     274   [ +  -  +  -  :       25916 :         obj.pushKV("synced_headers", statestats.nSyncHeight);
                   +  - ]
     275   [ +  -  +  -  :       25916 :         obj.pushKV("synced_blocks", statestats.nCommonHeight);
                   +  - ]
     276                 :       12958 :         UniValue heights(UniValue::VARR);
     277         [ +  + ]:       17420 :         for (const int height : statestats.vHeightInFlight) {
     278   [ +  -  +  - ]:        4462 :             heights.push_back(height);
     279                 :             :         }
     280   [ +  -  +  - ]:       25916 :         obj.pushKV("inflight", std::move(heights));
     281   [ +  -  +  -  :       25916 :         obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled);
                   +  - ]
     282   [ +  -  +  -  :       25916 :         obj.pushKV("addr_processed", statestats.m_addr_processed);
                   +  - ]
     283   [ +  -  +  -  :       25916 :         obj.pushKV("addr_rate_limited", statestats.m_addr_rate_limited);
                   +  - ]
     284                 :       12958 :         UniValue permissions(UniValue::VARR);
     285   [ +  -  +  + ]:       17370 :         for (const auto& permission : NetPermissions::ToStrings(stats.m_permission_flags)) {
     286   [ +  -  +  - ]:        4412 :             permissions.push_back(permission);
     287                 :       12958 :         }
     288   [ +  -  +  - ]:       25916 :         obj.pushKV("permissions", std::move(permissions));
     289   [ +  -  +  -  :       25916 :         obj.pushKV("minfeefilter", ValueFromAmount(statestats.m_fee_filter_received));
                   +  - ]
     290                 :             : 
     291                 :       12958 :         UniValue sendPerMsgType(UniValue::VOBJ);
     292         [ +  + ]:      153376 :         for (const auto& i : stats.mapSendBytesPerMsgType) {
     293         [ +  - ]:      140418 :             if (i.second > 0)
     294   [ +  -  -  +  :      421254 :                 sendPerMsgType.pushKV(i.first, i.second);
                   +  - ]
     295                 :             :         }
     296   [ +  -  +  - ]:       25916 :         obj.pushKV("bytessent_per_msg", std::move(sendPerMsgType));
     297                 :             : 
     298                 :       12958 :         UniValue recvPerMsgType(UniValue::VOBJ);
     299         [ +  + ]:      479446 :         for (const auto& i : stats.mapRecvBytesPerMsgType) {
     300         [ +  + ]:      466488 :             if (i.second > 0)
     301   [ +  -  -  +  :      371514 :                 recvPerMsgType.pushKV(i.first, i.second);
                   +  - ]
     302                 :             :         }
     303   [ +  -  +  - ]:       25916 :         obj.pushKV("bytesrecv_per_msg", std::move(recvPerMsgType));
     304   [ +  -  +  -  :       25916 :         obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type));
             +  -  +  - ]
     305   [ +  -  +  -  :       25916 :         obj.pushKV("transport_protocol_type", TransportTypeAsString(stats.m_transport_type));
             +  -  +  - ]
     306   [ +  -  +  -  :       25916 :         obj.pushKV("session_id", stats.m_session_id);
                   +  - ]
     307                 :             : 
     308         [ +  - ]:       12958 :         ret.push_back(std::move(obj));
     309                 :       12965 :     }
     310                 :             : 
     311                 :        6140 :     return ret;
     312                 :        6140 : },
     313   [ +  -  +  - ]:       34044 :     };
     314   [ +  -  +  -  :      408528 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  - ]
     315                 :             : 
     316                 :        2833 : static RPCHelpMan addnode()
     317                 :             : {
     318                 :        2833 :     return RPCHelpMan{
     319                 :        2833 :         "addnode",
     320                 :             :         "Attempts to add or remove a node from the addnode list.\n"
     321                 :             :                 "Or try a connection to a node once.\n"
     322                 :             :                 "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n"
     323                 :        2833 :                 "full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n" +
     324   [ +  -  +  - ]:        8499 :                 strprintf("Addnode connections are limited to %u at a time", MAX_ADDNODE_CONNECTIONS) +
     325                 :        2833 :                 " and are counted separately from the -maxconnections limit.\n",
     326                 :             :                 {
     327   [ +  -  +  - ]:        5666 :                     {"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address/hostname optionally followed by :port of the peer to connect to"},
     328   [ +  -  +  - ]:        5666 :                     {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once"},
     329   [ +  -  +  -  :        8499 :                     {"v2transport", RPCArg::Type::BOOL, RPCArg::DefaultHint{"set by -v2transport"}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
                   +  - ]
     330                 :             :                 },
     331   [ +  -  +  -  :        5666 :                 RPCResult{RPCResult::Type::NONE, "", ""},
             +  -  +  - ]
     332                 :        2833 :                 RPCExamples{
     333   [ +  -  +  -  :        5666 :                     HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\" true")
                   +  - ]
     334   [ +  -  +  -  :       11332 :             + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\" true")
             +  -  +  - ]
     335         [ +  - ]:        2833 :                 },
     336                 :        3297 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     337                 :             : {
     338                 :         464 :     const auto command{self.Arg<std::string_view>("command")};
     339   [ +  +  +  +  :         464 :     if (command != "onetry" && command != "add" && command != "remove") {
                   +  + ]
     340                 :           2 :         throw std::runtime_error(
     341   [ +  -  +  - ]:           4 :             self.ToString());
     342                 :             :     }
     343                 :             : 
     344                 :         462 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     345                 :         462 :     CConnman& connman = EnsureConnman(node);
     346                 :             : 
     347                 :         462 :     const auto node_arg{self.Arg<std::string_view>("node")};
     348                 :         462 :     bool node_v2transport = connman.GetLocalServices() & NODE_P2P_V2;
     349         [ +  + ]:         462 :     bool use_v2transport = self.MaybeArg<bool>("v2transport").value_or(node_v2transport);
     350                 :             : 
     351   [ +  +  +  + ]:         462 :     if (use_v2transport && !node_v2transport) {
     352   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");
     353                 :             :     }
     354                 :             : 
     355         [ +  + ]:         461 :     if (command == "onetry")
     356                 :             :     {
     357                 :         449 :         CAddress addr;
     358   [ +  -  +  -  :         898 :         connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grant_outbound=*/{}, std::string{node_arg}.c_str(), ConnectionType::MANUAL, use_v2transport);
                   -  + ]
     359                 :         449 :         return UniValue::VNULL;
     360                 :         449 :     }
     361                 :             : 
     362         [ +  + ]:          12 :     if (command == "add")
     363                 :             :     {
     364         [ +  + ]:           8 :         if (!connman.AddNode({std::string{node_arg}, use_v2transport})) {
     365   [ +  -  +  - ]:           8 :             throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
     366                 :             :         }
     367                 :             :     }
     368         [ +  - ]:           4 :     else if (command == "remove")
     369                 :             :     {
     370         [ +  + ]:           4 :         if (!connman.RemoveAddedNode(node_arg)) {
     371   [ +  -  +  - ]:           4 :             throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
     372                 :             :         }
     373                 :             :     }
     374                 :             : 
     375                 :           6 :     return UniValue::VNULL;
     376         [ +  - ]:           8 : },
     377   [ +  -  +  -  :       19831 :     };
             +  +  -  - ]
     378   [ +  -  +  -  :       16998 : }
             +  -  -  - ]
     379                 :             : 
     380                 :        2510 : static RPCHelpMan addconnection()
     381                 :             : {
     382                 :        2510 :     return RPCHelpMan{
     383                 :        2510 :         "addconnection",
     384         [ +  - ]:        5020 :         "Open an outbound connection to a specified node. This RPC is for testing only.\n",
     385                 :             :         {
     386   [ +  -  +  - ]:        5020 :             {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
     387   [ +  -  +  - ]:        5020 :             {"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
     388   [ +  -  +  - ]:        5020 :             {"v2transport", RPCArg::Type::BOOL, RPCArg::Optional::NO, "Attempt to connect using BIP324 v2 transport protocol"},
     389                 :             :         },
     390         [ +  - ]:        5020 :         RPCResult{
     391   [ +  -  +  - ]:        5020 :             RPCResult::Type::OBJ, "", "",
     392                 :             :             {
     393   [ +  -  +  - ]:        5020 :                 { RPCResult::Type::STR, "address", "Address of newly added connection." },
     394   [ +  -  +  - ]:        5020 :                 { RPCResult::Type::STR, "connection_type", "Type of connection opened." },
     395   [ +  -  +  -  :       12550 :             }},
             +  +  -  - ]
     396                 :        2510 :         RPCExamples{
     397   [ +  -  +  -  :        5020 :             HelpExampleCli("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\" true")
                   +  - ]
     398   [ +  -  +  -  :       10040 :             + HelpExampleRpc("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\" true")
             +  -  +  - ]
     399         [ +  - ]:        2510 :         },
     400                 :        2510 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     401                 :             : {
     402         [ -  + ]:         150 :     if (Params().GetChainType() != ChainType::REGTEST) {
     403         [ #  # ]:           0 :         throw std::runtime_error("addconnection is for regression testing (-regtest mode) only.");
     404                 :             :     }
     405                 :             : 
     406         [ -  + ]:         150 :     const std::string address = request.params[0].get_str();
     407   [ +  -  +  - ]:         150 :     auto conn_type_in{util::TrimStringView(self.Arg<std::string_view>("connection_type"))};
     408                 :         150 :     ConnectionType conn_type{};
     409         [ +  + ]:         150 :     if (conn_type_in == "outbound-full-relay") {
     410                 :             :         conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
     411         [ +  + ]:          54 :     } else if (conn_type_in == "block-relay-only") {
     412                 :             :         conn_type = ConnectionType::BLOCK_RELAY;
     413         [ +  + ]:          19 :     } else if (conn_type_in == "addr-fetch") {
     414                 :             :         conn_type = ConnectionType::ADDR_FETCH;
     415         [ -  + ]:           4 :     } else if (conn_type_in == "feeler") {
     416                 :             :         conn_type = ConnectionType::FEELER;
     417                 :             :     } else {
     418   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
     419                 :             :     }
     420         [ +  - ]:         150 :     bool use_v2transport{self.Arg<bool>("v2transport")};
     421                 :             : 
     422         [ +  - ]:         150 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     423         [ +  - ]:         150 :     CConnman& connman = EnsureConnman(node);
     424                 :             : 
     425   [ +  +  +  -  :         150 :     if (use_v2transport && !(connman.GetLocalServices() & NODE_P2P_V2)) {
                   -  + ]
     426   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Adding v2transport connections requires -v2transport init flag to be set.");
     427                 :             :     }
     428                 :             : 
     429         [ +  - ]:         150 :     const bool success = connman.AddConnection(address, conn_type, use_v2transport);
     430         [ -  + ]:         150 :     if (!success) {
     431   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_CLIENT_NODE_CAPACITY_REACHED, "Error: Already at capacity for specified connection type.");
     432                 :             :     }
     433                 :             : 
     434                 :         150 :     UniValue info(UniValue::VOBJ);
     435   [ +  -  +  -  :         300 :     info.pushKV("address", address);
                   +  - ]
     436   [ +  -  +  -  :         300 :     info.pushKV("connection_type", conn_type_in);
                   +  - ]
     437                 :             : 
     438                 :         150 :     return info;
     439                 :         150 : },
     440   [ +  -  +  -  :       17570 :     };
             +  +  -  - ]
     441   [ +  -  +  -  :       20080 : }
          +  -  +  -  +  
             -  -  -  -  
                      - ]
     442                 :             : 
     443                 :        2496 : static RPCHelpMan disconnectnode()
     444                 :             : {
     445                 :        2496 :     return RPCHelpMan{
     446                 :        2496 :         "disconnectnode",
     447         [ +  - ]:        4992 :         "Immediately disconnects from the specified peer node.\n"
     448                 :             :                 "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n"
     449                 :             :                 "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n",
     450                 :             :                 {
     451   [ +  -  +  -  :        7488 :                     {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"},
                   +  - ]
     452   [ +  -  +  -  :        7488 :                     {"nodeid", RPCArg::Type::NUM, RPCArg::DefaultHint{"fallback to address"}, "The node ID (see getpeerinfo for node IDs)"},
                   +  - ]
     453                 :             :                 },
     454   [ +  -  +  -  :        4992 :                 RPCResult{RPCResult::Type::NONE, "", ""},
             +  -  +  - ]
     455                 :        2496 :                 RPCExamples{
     456   [ +  -  +  -  :        4992 :                     HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"")
                   +  - ]
     457   [ +  -  +  -  :        9984 :             + HelpExampleCli("disconnectnode", "\"\" 1")
             +  -  +  - ]
     458   [ +  -  +  -  :        9984 :             + HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"")
             +  -  +  - ]
     459   [ +  -  +  -  :        9984 :             + HelpExampleRpc("disconnectnode", "\"\", 1")
             +  -  +  - ]
     460         [ +  - ]:        2496 :                 },
     461                 :        2496 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     462                 :             : {
     463                 :         127 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     464                 :         127 :     CConnman& connman = EnsureConnman(node);
     465                 :             : 
     466                 :         127 :     bool success;
     467                 :         127 :     auto address{self.MaybeArg<std::string_view>("address")};
     468                 :         127 :     auto node_id{self.MaybeArg<int64_t>("nodeid")};
     469                 :             : 
     470   [ +  +  +  + ]:         127 :     if (address && !node_id) {
     471                 :             :         /* handle disconnect-by-address */
     472                 :           4 :         success = connman.DisconnectNode(*address);
     473   [ +  -  +  +  :         123 :     } else if (node_id && (!address || address->empty())) {
                   -  + ]
     474                 :             :         /* handle disconnect-by-id */
     475                 :         121 :         success = connman.DisconnectNode(*node_id);
     476                 :             :     } else {
     477   [ +  -  +  - ]:           4 :         throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
     478                 :             :     }
     479                 :             : 
     480         [ +  + ]:         125 :     if (!success) {
     481   [ +  -  +  - ]:           4 :         throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
     482                 :             :     }
     483                 :             : 
     484                 :         123 :     return UniValue::VNULL;
     485                 :             : },
     486   [ +  -  +  -  :       14976 :     };
             +  +  -  - ]
     487   [ +  -  +  -  :        9984 : }
                   -  - ]
     488                 :             : 
     489                 :        2381 : static RPCHelpMan getaddednodeinfo()
     490                 :             : {
     491                 :        2381 :     return RPCHelpMan{
     492                 :        2381 :         "getaddednodeinfo",
     493         [ +  - ]:        4762 :         "Returns information about the given added node, or all added nodes\n"
     494                 :             :                 "(note that onetry addnodes are not listed here)\n",
     495                 :             :                 {
     496   [ +  -  +  -  :        7143 :                     {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"}, "If provided, return information about this specific node, otherwise all nodes are returned."},
                   +  - ]
     497                 :             :                 },
     498         [ +  - ]:        4762 :                 RPCResult{
     499   [ +  -  +  - ]:        4762 :                     RPCResult::Type::ARR, "", "",
     500                 :             :                     {
     501   [ +  -  +  - ]:        4762 :                         {RPCResult::Type::OBJ, "", "",
     502                 :             :                         {
     503   [ +  -  +  - ]:        4762 :                             {RPCResult::Type::STR, "addednode", "The node IP address or name (as provided to addnode)"},
     504   [ +  -  +  - ]:        4762 :                             {RPCResult::Type::BOOL, "connected", "If connected"},
     505   [ +  -  +  - ]:        4762 :                             {RPCResult::Type::ARR, "addresses", "Only when connected = true",
     506                 :             :                             {
     507   [ +  -  +  - ]:        4762 :                                 {RPCResult::Type::OBJ, "", "",
     508                 :             :                                 {
     509   [ +  -  +  - ]:        4762 :                                     {RPCResult::Type::STR, "address", "The bitcoin server IP and port we're connected to"},
     510   [ +  -  +  - ]:        4762 :                                     {RPCResult::Type::STR, "connected", "connection, inbound or outbound"},
     511                 :             :                                 }},
     512                 :             :                             }},
     513                 :             :                         }},
     514                 :             :                     }
     515   [ +  -  +  -  :       35715 :                 },
          +  -  +  -  +  
          -  +  +  +  +  
          +  +  +  +  -  
          -  -  -  -  -  
                   -  - ]
     516                 :        2381 :                 RPCExamples{
     517   [ +  -  +  -  :        4762 :                     HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"")
                   +  - ]
     518   [ +  -  +  -  :        9524 :             + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")
             +  -  +  - ]
     519         [ +  - ]:        2381 :                 },
     520                 :        2381 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     521                 :             : {
     522                 :          12 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     523                 :          12 :     const CConnman& connman = EnsureConnman(node);
     524                 :             : 
     525                 :          12 :     std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo(/*include_connected=*/true);
     526                 :             : 
     527   [ +  -  +  + ]:          12 :     if (auto node{self.MaybeArg<std::string_view>("node")}) {
     528                 :           4 :         bool found = false;
     529         [ +  + ]:           6 :         for (const AddedNodeInfo& info : vInfo) {
     530   [ -  +  +  + ]:           4 :             if (info.m_params.m_added_node == *node) {
     531         [ +  - ]:           2 :                 vInfo.assign(1, info);
     532                 :             :                 found = true;
     533                 :             :                 break;
     534                 :             :             }
     535                 :             :         }
     536                 :           2 :         if (!found) {
     537   [ +  -  +  - ]:           4 :             throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
     538                 :             :         }
     539                 :             :     }
     540                 :             : 
     541                 :          10 :     UniValue ret(UniValue::VARR);
     542                 :             : 
     543         [ +  + ]:          20 :     for (const AddedNodeInfo& info : vInfo) {
     544                 :          10 :         UniValue obj(UniValue::VOBJ);
     545   [ +  -  +  -  :          20 :         obj.pushKV("addednode", info.m_params.m_added_node);
                   +  - ]
     546   [ +  -  +  -  :          20 :         obj.pushKV("connected", info.fConnected);
                   +  - ]
     547                 :          10 :         UniValue addresses(UniValue::VARR);
     548         [ -  + ]:          10 :         if (info.fConnected) {
     549                 :           0 :             UniValue address(UniValue::VOBJ);
     550   [ #  #  #  #  :           0 :             address.pushKV("address", info.resolvedAddress.ToStringAddrPort());
             #  #  #  # ]
     551   [ #  #  #  #  :           0 :             address.pushKV("connected", info.fInbound ? "inbound" : "outbound");
             #  #  #  # ]
     552         [ #  # ]:           0 :             addresses.push_back(std::move(address));
     553                 :           0 :         }
     554   [ +  -  +  - ]:          20 :         obj.pushKV("addresses", std::move(addresses));
     555         [ +  - ]:          10 :         ret.push_back(std::move(obj));
     556                 :          10 :     }
     557                 :             : 
     558                 :          10 :     return ret;
     559                 :          12 : },
     560   [ +  -  +  -  :       11905 :     };
             +  +  -  - ]
     561   [ +  -  +  -  :       21429 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  -  -  
                      - ]
     562                 :             : 
     563                 :        2387 : static RPCHelpMan getnettotals()
     564                 :             : {
     565                 :        2387 :     return RPCHelpMan{"getnettotals",
     566         [ +  - ]:        4774 :         "Returns information about network traffic, including bytes in, bytes out,\n"
     567                 :             :         "and current system time.",
     568                 :             :         {},
     569         [ +  - ]:        4774 :                 RPCResult{
     570         [ +  - ]:        4774 :                    RPCResult::Type::OBJ, "", "",
     571                 :             :                    {
     572   [ +  -  +  - ]:        4774 :                        {RPCResult::Type::NUM, "totalbytesrecv", "Total bytes received"},
     573   [ +  -  +  - ]:        4774 :                        {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"},
     574   [ +  -  +  - ]:        4774 :                        {RPCResult::Type::NUM_TIME, "timemillis", "Current system " + UNIX_EPOCH_TIME + " in milliseconds"},
     575   [ +  -  +  - ]:        4774 :                        {RPCResult::Type::OBJ, "uploadtarget", "",
     576                 :             :                        {
     577   [ +  -  +  - ]:        4774 :                            {RPCResult::Type::NUM, "timeframe", "Length of the measuring timeframe in seconds"},
     578   [ +  -  +  - ]:        4774 :                            {RPCResult::Type::NUM, "target", "Target in bytes"},
     579   [ +  -  +  - ]:        4774 :                            {RPCResult::Type::BOOL, "target_reached", "True if target is reached"},
     580   [ +  -  +  - ]:        4774 :                            {RPCResult::Type::BOOL, "serve_historical_blocks", "True if serving historical blocks"},
     581   [ +  -  +  - ]:        4774 :                            {RPCResult::Type::NUM, "bytes_left_in_cycle", "Bytes left in current time cycle"},
     582   [ +  -  +  - ]:        4774 :                            {RPCResult::Type::NUM, "time_left_in_cycle", "Seconds left in current time cycle"},
     583                 :             :                         }},
     584                 :             :                     }
     585   [ +  -  +  -  :       50127 :                 },
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     586                 :        2387 :                 RPCExamples{
     587   [ +  -  +  -  :        4774 :                     HelpExampleCli("getnettotals", "")
                   +  - ]
     588   [ +  -  +  -  :        9548 :             + HelpExampleRpc("getnettotals", "")
             +  -  +  - ]
     589         [ +  - ]:        2387 :                 },
     590                 :        2387 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     591                 :             : {
     592                 :          18 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     593                 :          18 :     const CConnman& connman = EnsureConnman(node);
     594                 :             : 
     595                 :          18 :     UniValue obj(UniValue::VOBJ);
     596   [ +  -  +  -  :          36 :     obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv());
             +  -  +  - ]
     597   [ +  -  +  -  :          36 :     obj.pushKV("totalbytessent", connman.GetTotalBytesSent());
             +  -  +  - ]
     598   [ +  -  +  -  :          36 :     obj.pushKV("timemillis", TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()));
                   +  - ]
     599                 :             : 
     600                 :          18 :     UniValue outboundLimit(UniValue::VOBJ);
     601   [ +  -  +  -  :          36 :     outboundLimit.pushKV("timeframe", count_seconds(connman.GetMaxOutboundTimeframe()));
             +  -  +  - ]
     602   [ +  -  +  -  :          36 :     outboundLimit.pushKV("target", connman.GetMaxOutboundTarget());
             +  -  +  - ]
     603   [ +  -  +  -  :          36 :     outboundLimit.pushKV("target_reached", connman.OutboundTargetReached(false));
             +  -  +  - ]
     604   [ +  -  +  -  :          36 :     outboundLimit.pushKV("serve_historical_blocks", !connman.OutboundTargetReached(true));
             +  -  +  - ]
     605   [ +  -  +  -  :          36 :     outboundLimit.pushKV("bytes_left_in_cycle", connman.GetOutboundTargetBytesLeft());
             +  -  +  - ]
     606   [ +  -  +  -  :          36 :     outboundLimit.pushKV("time_left_in_cycle", count_seconds(connman.GetMaxOutboundTimeLeftInCycle()));
             +  -  +  - ]
     607   [ +  -  +  - ]:          36 :     obj.pushKV("uploadtarget", std::move(outboundLimit));
     608                 :          18 :     return obj;
     609                 :          18 : },
     610   [ +  -  +  - ]:        9548 :     };
     611   [ +  -  +  -  :       23870 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  -  -  -  
                      - ]
     612                 :             : 
     613                 :         978 : static UniValue GetNetworksInfo()
     614                 :             : {
     615                 :         978 :     UniValue networks(UniValue::VARR);
     616         [ +  + ]:        7824 :     for (int n = 0; n < NET_MAX; ++n) {
     617                 :        6846 :         enum Network network = static_cast<enum Network>(n);
     618         [ +  + ]:        6846 :         if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
     619         [ +  - ]:        4890 :         Proxy proxy;
     620                 :        4890 :         UniValue obj(UniValue::VOBJ);
     621         [ +  - ]:        4890 :         GetProxy(network, proxy);
     622   [ +  -  +  -  :        9780 :         obj.pushKV("name", GetNetworkName(network));
             +  -  +  - ]
     623   [ +  -  +  -  :        9780 :         obj.pushKV("limited", !g_reachable_nets.Contains(network));
             +  -  +  - ]
     624   [ +  -  +  -  :        9780 :         obj.pushKV("reachable", g_reachable_nets.Contains(network));
             +  -  +  - ]
     625   [ +  -  +  +  :        9780 :         obj.pushKV("proxy", proxy.IsValid() ? proxy.ToString() : std::string());
          +  -  +  -  +  
                -  +  - ]
     626   [ +  -  +  -  :        9780 :         obj.pushKV("proxy_randomize_credentials", proxy.m_tor_stream_isolation);
                   +  - ]
     627         [ +  - ]:        4890 :         networks.push_back(std::move(obj));
     628                 :        9780 :     }
     629                 :         978 :     return networks;
     630                 :           0 : }
     631                 :             : 
     632                 :        3349 : static RPCHelpMan getnetworkinfo()
     633                 :             : {
     634                 :        3349 :     return RPCHelpMan{"getnetworkinfo",
     635         [ +  - ]:        6698 :                 "Returns an object containing various state info regarding P2P networking.\n",
     636                 :             :                 {},
     637         [ +  - ]:        6698 :                 RPCResult{
     638         [ +  - ]:        6698 :                     RPCResult::Type::OBJ, "", "",
     639                 :             :                     {
     640   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "version", "the server version"},
     641   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::STR, "subversion", "the server subversion string"},
     642   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "protocolversion", "the protocol version"},
     643   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::STR_HEX, "localservices", "the services we offer to the network"},
     644   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::ARR, "localservicesnames", "the services we offer to the network, in human-readable form",
     645                 :             :                         {
     646   [ +  -  +  - ]:        6698 :                             {RPCResult::Type::STR, "SERVICE_NAME", "the service name"},
     647                 :             :                         }},
     648   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::BOOL, "localrelay", "true if transaction relay is requested from peers"},
     649   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "timeoffset", "the time offset"},
     650   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "connections", "the total number of connections"},
     651   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "connections_in", "the number of inbound connections"},
     652   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "connections_out", "the number of outbound connections"},
     653   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::BOOL, "networkactive", "whether p2p networking is enabled"},
     654   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::ARR, "networks", "information per network",
     655                 :             :                         {
     656   [ +  -  +  - ]:        6698 :                             {RPCResult::Type::OBJ, "", "",
     657                 :             :                             {
     658   [ +  -  +  -  :        6698 :                                 {RPCResult::Type::STR, "name", "network (" + Join(GetNetworkNames(), ", ") + ")"},
             +  -  +  - ]
     659   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::BOOL, "limited", "is the network limited using -onlynet?"},
     660   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::BOOL, "reachable", "is the network reachable?"},
     661   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::STR, "proxy", "(\"host:port\") the proxy that is used for this network, or empty if none"},
     662   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::BOOL, "proxy_randomize_credentials", "Whether randomized credentials are used"},
     663                 :             :                             }},
     664                 :             :                         }},
     665   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "relayfee", "minimum relay fee rate for transactions in " + CURRENCY_UNIT + "/kvB"},
     666   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::NUM, "incrementalfee", "minimum fee rate increment for mempool limiting or replacement in " + CURRENCY_UNIT + "/kvB"},
     667   [ +  -  +  - ]:        6698 :                         {RPCResult::Type::ARR, "localaddresses", "list of local addresses",
     668                 :             :                         {
     669   [ +  -  +  - ]:        6698 :                             {RPCResult::Type::OBJ, "", "",
     670                 :             :                             {
     671   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::STR, "address", "network address"},
     672   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::NUM, "port", "network port"},
     673   [ +  -  +  - ]:        6698 :                                 {RPCResult::Type::NUM, "score", "relative score"},
     674                 :             :                             }},
     675                 :             :                         }},
     676   [ +  -  +  -  :        3349 :                         (IsDeprecatedRPCEnabled("warnings") ?
                   -  + ]
     677   [ -  -  -  -  :        3349 :                             RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
          -  +  -  +  -  
          +  -  -  -  -  
                   -  - ]
     678   [ +  -  +  -  :       13396 :                             RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",
          +  -  +  -  -  
                -  -  - ]
     679                 :             :                             {
     680   [ +  -  +  -  :       13396 :                                 {RPCResult::Type::STR, "", "warning"},
          +  -  +  -  -  
                -  -  - ]
     681                 :             :                             }
     682   [ +  -  +  -  :       13396 :                             }
          +  -  +  +  +  
          -  -  -  -  -  
             -  -  -  - ]
     683                 :             :                         ),
     684                 :             :                     }
     685   [ +  -  +  -  :      184195 :                 },
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  -  -  -  
          -  -  -  -  -  
             -  -  -  - ]
     686                 :        3349 :                 RPCExamples{
     687   [ +  -  +  -  :        6698 :                     HelpExampleCli("getnetworkinfo", "")
                   +  - ]
     688   [ +  -  +  -  :       13396 :             + HelpExampleRpc("getnetworkinfo", "")
             +  -  +  - ]
     689         [ +  - ]:        3349 :                 },
     690                 :        3349 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     691                 :             : {
     692                 :         978 :     LOCK(cs_main);
     693                 :         978 :     UniValue obj(UniValue::VOBJ);
     694   [ +  -  +  -  :        1956 :     obj.pushKV("version",       CLIENT_VERSION);
                   +  - ]
     695   [ +  -  +  -  :        1956 :     obj.pushKV("subversion",    strSubVersion);
                   +  - ]
     696   [ +  -  +  -  :        1956 :     obj.pushKV("protocolversion",PROTOCOL_VERSION);
                   +  - ]
     697         [ +  - ]:         978 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     698         [ +  - ]:         978 :     if (node.connman) {
     699         [ +  - ]:         978 :         ServiceFlags services = node.connman->GetLocalServices();
     700   [ +  -  +  -  :        1956 :         obj.pushKV("localservices", strprintf("%016x", services));
             +  -  +  - ]
     701   [ +  -  +  -  :        1956 :         obj.pushKV("localservicesnames", GetServicesNames(services));
                   +  - ]
     702                 :             :     }
     703         [ +  - ]:         978 :     if (node.peerman) {
     704         [ +  - ]:         978 :         auto peerman_info{node.peerman->GetInfo()};
     705   [ +  -  +  -  :        1956 :         obj.pushKV("localrelay", !peerman_info.ignores_incoming_txs);
                   +  - ]
     706   [ +  -  +  -  :        1956 :         obj.pushKV("timeoffset", Ticks<std::chrono::seconds>(peerman_info.median_outbound_time_offset));
                   +  - ]
     707                 :             :     }
     708         [ +  - ]:         978 :     if (node.connman) {
     709   [ +  -  +  -  :        1956 :         obj.pushKV("networkactive", node.connman->GetNetworkActive());
                   +  - ]
     710   [ +  -  +  -  :        1956 :         obj.pushKV("connections", node.connman->GetNodeCount(ConnectionDirection::Both));
             +  -  +  - ]
     711   [ +  -  +  -  :        1956 :         obj.pushKV("connections_in", node.connman->GetNodeCount(ConnectionDirection::In));
             +  -  +  - ]
     712   [ +  -  +  -  :        1956 :         obj.pushKV("connections_out", node.connman->GetNodeCount(ConnectionDirection::Out));
             +  -  +  - ]
     713                 :             :     }
     714   [ +  -  +  -  :        1956 :     obj.pushKV("networks",      GetNetworksInfo());
                   +  - ]
     715         [ +  - ]:         978 :     if (node.mempool) {
     716                 :             :         // Those fields can be deprecated, to be replaced by the getmempoolinfo fields
     717   [ +  -  +  -  :        1956 :         obj.pushKV("relayfee", ValueFromAmount(node.mempool->m_opts.min_relay_feerate.GetFeePerK()));
                   +  - ]
     718   [ +  -  +  -  :        1956 :         obj.pushKV("incrementalfee", ValueFromAmount(node.mempool->m_opts.incremental_relay_feerate.GetFeePerK()));
                   +  - ]
     719                 :             :     }
     720                 :         978 :     UniValue localAddresses(UniValue::VARR);
     721                 :         978 :     {
     722         [ +  - ]:         978 :         LOCK(g_maplocalhost_mutex);
     723         [ +  + ]:         982 :         for (const std::pair<const CNetAddr, LocalServiceInfo> &item : mapLocalHost)
     724                 :             :         {
     725                 :           4 :             UniValue rec(UniValue::VOBJ);
     726   [ +  -  +  -  :           8 :             rec.pushKV("address", item.first.ToStringAddr());
             +  -  +  - ]
     727   [ +  -  +  -  :           8 :             rec.pushKV("port", item.second.nPort);
                   +  - ]
     728   [ +  -  +  -  :           8 :             rec.pushKV("score", item.second.nScore);
                   +  - ]
     729         [ +  - ]:           4 :             localAddresses.push_back(std::move(rec));
     730                 :           4 :         }
     731                 :           0 :     }
     732   [ +  -  +  - ]:        1956 :     obj.pushKV("localaddresses", std::move(localAddresses));
     733   [ +  -  +  -  :        1956 :     obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));
          +  -  +  -  +  
                -  +  - ]
     734                 :        1956 :     return obj;
     735         [ +  - ]:        1956 : },
     736   [ +  -  +  - ]:       13396 :     };
     737   [ +  -  +  -  :       93772 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  -  
          +  -  +  -  -  
             -  -  -  -  
                      - ]
     738                 :             : 
     739                 :        2418 : static RPCHelpMan setban()
     740                 :             : {
     741                 :        2418 :     return RPCHelpMan{
     742                 :        2418 :         "setban",
     743         [ +  - ]:        4836 :         "Attempts to add or remove an IP/Subnet from the banned list.\n",
     744                 :             :                 {
     745   [ +  -  +  - ]:        4836 :                     {"subnet", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)"},
     746   [ +  -  +  - ]:        4836 :                     {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list"},
     747   [ +  -  +  -  :        7254 :                     {"bantime", RPCArg::Type::NUM, RPCArg::Default{0}, "time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)"},
                   +  - ]
     748   [ +  -  +  -  :        7254 :                     {"absolute", RPCArg::Type::BOOL, RPCArg::Default{false}, "If set, the bantime must be an absolute timestamp expressed in " + UNIX_EPOCH_TIME},
                   +  - ]
     749                 :             :                 },
     750   [ +  -  +  -  :        4836 :                 RPCResult{RPCResult::Type::NONE, "", ""},
             +  -  +  - ]
     751                 :        2418 :                 RPCExamples{
     752   [ +  -  +  -  :        4836 :                     HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400")
                   +  - ]
     753   [ +  -  +  -  :        9672 :                             + HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"")
             +  -  +  - ]
     754   [ +  -  +  -  :        9672 :                             + HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")
             +  -  +  - ]
     755         [ +  - ]:        2418 :                 },
     756                 :        2418 :         [&](const RPCHelpMan& help, const JSONRPCRequest& request) -> UniValue
     757                 :             : {
     758                 :          48 :     auto command{help.Arg<std::string_view>("command")};
     759   [ +  +  -  + ]:          48 :     if (command != "add" && command != "remove") {
     760   [ #  #  #  # ]:           0 :         throw std::runtime_error(help.ToString());
     761                 :             :     }
     762                 :          48 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     763                 :          48 :     BanMan& banman = EnsureBanman(node);
     764                 :             : 
     765                 :          48 :     CSubNet subNet;
     766         [ +  - ]:          48 :     CNetAddr netAddr;
     767   [ +  -  +  - ]:          48 :     std::string subnet_arg{help.Arg<std::string_view>("subnet")};
     768                 :          48 :     const bool isSubnet{subnet_arg.find('/') != subnet_arg.npos};
     769                 :             : 
     770         [ +  + ]:          48 :     if (!isSubnet) {
     771   [ +  -  +  - ]:          30 :         const std::optional<CNetAddr> addr{LookupHost(subnet_arg, false)};
     772         [ +  + ]:          30 :         if (addr.has_value()) {
     773   [ +  -  +  - ]:          29 :             netAddr = static_cast<CNetAddr>(MaybeFlipIPv6toCJDNS(CService{addr.value(), /*port=*/0}));
     774                 :             :         }
     775                 :          30 :     } else {
     776         [ +  - ]:          18 :         subNet = LookupSubNet(subnet_arg);
     777                 :             :     }
     778                 :             : 
     779   [ +  +  +  -  :          48 :     if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) ) {
             +  -  +  + ]
     780   [ +  -  +  - ]:           6 :         throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Invalid IP/Subnet");
     781                 :             :     }
     782                 :             : 
     783         [ +  + ]:          45 :     if (command == "add") {
     784   [ +  +  +  -  :          35 :         if (isSubnet ? banman.IsBanned(subNet) : banman.IsBanned(netAddr)) {
             +  -  +  + ]
     785   [ +  -  +  - ]:           8 :             throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
     786                 :             :         }
     787                 :             : 
     788                 :          31 :         int64_t banTime = 0; //use standard bantime if not specified
     789   [ +  -  +  + ]:          31 :         if (!request.params[2].isNull())
     790   [ +  -  +  - ]:          10 :             banTime = request.params[2].getInt<int64_t>();
     791                 :             : 
     792   [ +  -  +  +  :          31 :         const bool absolute{request.params[3].isNull() ? false : request.params[3].get_bool()};
             +  -  +  - ]
     793                 :             : 
     794   [ +  -  +  -  :           5 :         if (absolute && banTime < GetTime()) {
                   +  + ]
     795   [ +  -  +  - ]:           4 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Absolute timestamp is in the past");
     796                 :             :         }
     797                 :             : 
     798         [ +  + ]:          29 :         if (isSubnet) {
     799         [ +  - ]:          13 :             banman.Ban(subNet, banTime, absolute);
     800         [ +  - ]:          13 :             if (node.connman) {
     801         [ +  - ]:          13 :                 node.connman->DisconnectNode(subNet);
     802                 :             :             }
     803                 :             :         } else {
     804         [ +  - ]:          16 :             banman.Ban(netAddr, banTime, absolute);
     805         [ +  - ]:          16 :             if (node.connman) {
     806         [ +  - ]:          16 :                 node.connman->DisconnectNode(netAddr);
     807                 :             :             }
     808                 :             :         }
     809         [ +  - ]:          10 :     } else if(command == "remove") {
     810   [ +  +  +  -  :          10 :         if (!( isSubnet ? banman.Unban(subNet) : banman.Unban(netAddr) )) {
             +  -  +  + ]
     811   [ +  -  +  - ]:           4 :             throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned.");
     812                 :             :         }
     813                 :             :     }
     814                 :          37 :     return UniValue::VNULL;
     815                 :          59 : },
     816   [ +  -  +  -  :       19344 :     };
             +  +  -  - ]
     817   [ +  -  +  -  :       19344 : }
          +  -  +  -  -  
                      - ]
     818                 :             : 
     819                 :        2416 : static RPCHelpMan listbanned()
     820                 :             : {
     821                 :        2416 :     return RPCHelpMan{
     822                 :        2416 :         "listbanned",
     823         [ +  - ]:        4832 :         "List all manually banned IPs/Subnets.\n",
     824                 :             :                 {},
     825   [ +  -  +  - ]:        9664 :         RPCResult{RPCResult::Type::ARR, "", "",
     826                 :             :             {
     827   [ +  -  +  - ]:        4832 :                 {RPCResult::Type::OBJ, "", "",
     828                 :             :                     {
     829   [ +  -  +  - ]:        4832 :                         {RPCResult::Type::STR, "address", "The IP/Subnet of the banned node"},
     830   [ +  -  +  - ]:        4832 :                         {RPCResult::Type::NUM_TIME, "ban_created", "The " + UNIX_EPOCH_TIME + " the ban was created"},
     831   [ +  -  +  - ]:        4832 :                         {RPCResult::Type::NUM_TIME, "banned_until", "The " + UNIX_EPOCH_TIME + " the ban expires"},
     832   [ +  -  +  - ]:        4832 :                         {RPCResult::Type::NUM_TIME, "ban_duration", "The ban duration, in seconds"},
     833   [ +  -  +  - ]:        4832 :                         {RPCResult::Type::NUM_TIME, "time_remaining", "The time remaining until the ban expires, in seconds"},
     834                 :             :                     }},
     835   [ +  -  +  -  :       31408 :             }},
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     836                 :        2416 :                 RPCExamples{
     837   [ +  -  +  -  :        4832 :                     HelpExampleCli("listbanned", "")
                   +  - ]
     838   [ +  -  +  -  :        9664 :                             + HelpExampleRpc("listbanned", "")
             +  -  +  - ]
     839         [ +  - ]:        2416 :                 },
     840                 :        2416 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     841                 :             : {
     842                 :          47 :     BanMan& banman = EnsureAnyBanman(request.context);
     843                 :             : 
     844         [ +  - ]:          47 :     banmap_t banMap;
     845         [ +  - ]:          47 :     banman.GetBanned(banMap);
     846         [ +  - ]:          47 :     const int64_t current_time{GetTime()};
     847                 :             : 
     848                 :          47 :     UniValue bannedAddresses(UniValue::VARR);
     849         [ +  + ]:         107 :     for (const auto& entry : banMap)
     850                 :             :     {
     851                 :          60 :         const CBanEntry& banEntry = entry.second;
     852                 :          60 :         UniValue rec(UniValue::VOBJ);
     853   [ +  -  +  -  :         120 :         rec.pushKV("address", entry.first.ToString());
             +  -  +  - ]
     854   [ +  -  +  -  :         120 :         rec.pushKV("ban_created", banEntry.nCreateTime);
                   +  - ]
     855   [ +  -  +  -  :         120 :         rec.pushKV("banned_until", banEntry.nBanUntil);
                   +  - ]
     856   [ +  -  +  -  :         120 :         rec.pushKV("ban_duration", (banEntry.nBanUntil - banEntry.nCreateTime));
                   +  - ]
     857   [ +  -  +  -  :         120 :         rec.pushKV("time_remaining", (banEntry.nBanUntil - current_time));
                   +  - ]
     858                 :             : 
     859         [ +  - ]:          60 :         bannedAddresses.push_back(std::move(rec));
     860                 :          60 :     }
     861                 :             : 
     862                 :          47 :     return bannedAddresses;
     863                 :          47 : },
     864   [ +  -  +  - ]:        9664 :     };
     865   [ +  -  +  -  :       14496 : }
          +  -  +  -  +  
             -  +  -  -  
                      - ]
     866                 :             : 
     867                 :        2380 : static RPCHelpMan clearbanned()
     868                 :             : {
     869                 :        2380 :     return RPCHelpMan{
     870                 :        2380 :         "clearbanned",
     871         [ +  - ]:        4760 :         "Clear all banned IPs.\n",
     872                 :             :                 {},
     873   [ +  -  +  -  :        4760 :                 RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
     874                 :        2380 :                 RPCExamples{
     875   [ +  -  +  -  :        4760 :                     HelpExampleCli("clearbanned", "")
                   +  - ]
     876   [ +  -  +  -  :        9520 :                             + HelpExampleRpc("clearbanned", "")
             +  -  +  - ]
     877         [ +  - ]:        2380 :                 },
     878                 :        2380 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     879                 :             : {
     880                 :          11 :     BanMan& banman = EnsureAnyBanman(request.context);
     881                 :             : 
     882                 :          11 :     banman.ClearBanned();
     883                 :             : 
     884                 :          11 :     return UniValue::VNULL;
     885                 :             : },
     886   [ +  -  +  - ]:        9520 :     };
     887                 :             : }
     888                 :             : 
     889                 :        2382 : static RPCHelpMan setnetworkactive()
     890                 :             : {
     891                 :        2382 :     return RPCHelpMan{
     892                 :        2382 :         "setnetworkactive",
     893         [ +  - ]:        4764 :         "Disable/enable all p2p network activity.\n",
     894                 :             :                 {
     895   [ +  -  +  - ]:        4764 :                     {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable networking, false to disable"},
     896                 :             :                 },
     897   [ +  -  +  -  :        4764 :                 RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
             +  -  +  - ]
     898   [ +  -  +  - ]:        7146 :                 RPCExamples{""},
     899                 :        2382 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     900                 :             : {
     901                 :          13 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     902                 :          13 :     CConnman& connman = EnsureConnman(node);
     903                 :             : 
     904                 :          13 :     connman.SetNetworkActive(request.params[0].get_bool());
     905                 :             : 
     906                 :          13 :     return connman.GetNetworkActive();
     907                 :             : },
     908   [ +  -  +  -  :       11910 :     };
             +  +  -  - ]
     909         [ +  - ]:        4764 : }
     910                 :             : 
     911                 :        2406 : static RPCHelpMan getnodeaddresses()
     912                 :             : {
     913                 :        2406 :     return RPCHelpMan{"getnodeaddresses",
     914         [ +  - ]:        4812 :                 "Return known addresses, after filtering for quality and recency.\n"
     915                 :             :                 "These can potentially be used to find new peers in the network.\n"
     916                 :             :                 "The total number of addresses known to the node may be higher.",
     917                 :             :                 {
     918   [ +  -  +  -  :        7218 :                     {"count", RPCArg::Type::NUM, RPCArg::Default{1}, "The maximum number of addresses to return. Specify 0 to return all known addresses."},
                   +  - ]
     919   [ +  -  +  -  :        7218 :                     {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"}, "Return only addresses of the specified network. Can be one of: " + Join(GetNetworkNames(), ", ") + "."},
          +  -  +  -  +  
                      - ]
     920                 :             :                 },
     921         [ +  - ]:        4812 :                 RPCResult{
     922   [ +  -  +  - ]:        4812 :                     RPCResult::Type::ARR, "", "",
     923                 :             :                     {
     924   [ +  -  +  - ]:        4812 :                         {RPCResult::Type::OBJ, "", "",
     925                 :             :                         {
     926   [ +  -  +  - ]:        4812 :                             {RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " when the node was last seen"},
     927   [ +  -  +  - ]:        4812 :                             {RPCResult::Type::NUM, "services", "The services offered by the node"},
     928   [ +  -  +  - ]:        4812 :                             {RPCResult::Type::STR, "address", "The address of the node"},
     929   [ +  -  +  - ]:        4812 :                             {RPCResult::Type::NUM, "port", "The port number of the node"},
     930   [ +  -  +  -  :        4812 :                             {RPCResult::Type::STR, "network", "The network (" + Join(GetNetworkNames(), ", ") + ") the node connected through"},
             +  -  +  - ]
     931                 :             :                         }},
     932                 :             :                     }
     933   [ +  -  +  -  :       31278 :                 },
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     934                 :        2406 :                 RPCExamples{
     935   [ +  -  +  -  :        4812 :                     HelpExampleCli("getnodeaddresses", "8")
                   +  - ]
     936   [ +  -  +  -  :        9624 :                     + HelpExampleCli("getnodeaddresses", "4 \"i2p\"")
             +  -  +  - ]
     937   [ +  -  +  -  :        9624 :                     + HelpExampleCli("-named getnodeaddresses", "network=onion count=12")
             +  -  +  - ]
     938   [ +  -  +  -  :        9624 :                     + HelpExampleRpc("getnodeaddresses", "8")
             +  -  +  - ]
     939   [ +  -  +  -  :        9624 :                     + HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")
             +  -  +  - ]
     940         [ +  - ]:        2406 :                 },
     941                 :        2406 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     942                 :             : {
     943                 :          37 :     NodeContext& node = EnsureAnyNodeContext(request.context);
     944                 :          37 :     const CConnman& connman = EnsureConnman(node);
     945                 :             : 
     946         [ +  + ]:          37 :     const int count{request.params[0].isNull() ? 1 : request.params[0].getInt<int>()};
     947   [ +  +  +  -  :          33 :     if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
                   +  - ]
     948                 :             : 
     949         [ +  + ]:          35 :     const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}};
     950         [ +  + ]:          35 :     if (network == NET_UNROUTABLE) {
     951   [ +  -  +  -  :           4 :         throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Network not recognized: %s", request.params[1].get_str()));
             +  -  +  - ]
     952                 :             :     }
     953                 :             : 
     954                 :             :     // returns a shuffled list of CAddress
     955                 :          33 :     const std::vector<CAddress> vAddr{connman.GetAddressesUnsafe(count, /*max_pct=*/0, network)};
     956                 :          33 :     UniValue ret(UniValue::VARR);
     957                 :             : 
     958         [ +  + ]:       27635 :     for (const CAddress& addr : vAddr) {
     959                 :       27602 :         UniValue obj(UniValue::VOBJ);
     960   [ +  -  +  -  :       55204 :         obj.pushKV("time", int64_t{TicksSinceEpoch<std::chrono::seconds>(addr.nTime)});
                   +  - ]
     961   [ +  -  +  -  :       55204 :         obj.pushKV("services", static_cast<std::underlying_type_t<decltype(addr.nServices)>>(addr.nServices));
                   +  - ]
     962   [ +  -  +  -  :       55204 :         obj.pushKV("address", addr.ToStringAddr());
             +  -  +  - ]
     963   [ +  -  +  -  :       55204 :         obj.pushKV("port", addr.GetPort());
             +  -  +  - ]
     964   [ +  -  +  -  :       55204 :         obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
          +  -  +  -  +  
                      - ]
     965         [ +  - ]:       27602 :         ret.push_back(std::move(obj));
     966                 :       27602 :     }
     967                 :          33 :     return ret;
     968                 :          33 : },
     969   [ +  -  +  -  :       14436 :     };
             +  +  -  - ]
     970   [ +  -  +  -  :       24060 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  -  -  
                      - ]
     971                 :             : 
     972                 :       34594 : static RPCHelpMan addpeeraddress()
     973                 :             : {
     974                 :       34594 :     return RPCHelpMan{"addpeeraddress",
     975         [ +  - ]:       69188 :         "Add the address of a potential peer to an address manager table. This RPC is for testing only.",
     976                 :             :         {
     977   [ +  -  +  - ]:       69188 :             {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"},
     978   [ +  -  +  - ]:       69188 :             {"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"},
     979   [ +  -  +  -  :      103782 :             {"tried", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, attempt to add the peer to the tried addresses table"},
                   +  - ]
     980                 :             :         },
     981         [ +  - ]:       69188 :         RPCResult{
     982   [ +  -  +  - ]:       69188 :             RPCResult::Type::OBJ, "", "",
     983                 :             :             {
     984   [ +  -  +  - ]:       69188 :                 {RPCResult::Type::BOOL, "success", "whether the peer address was successfully added to the address manager table"},
     985   [ +  -  +  - ]:       69188 :                 {RPCResult::Type::STR, "error", /*optional=*/true, "error description, if the address could not be added"},
     986                 :             :             },
     987   [ +  -  +  -  :      172970 :         },
             +  +  -  - ]
     988                 :       34594 :         RPCExamples{
     989   [ +  -  +  -  :       69188 :             HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true")
                   +  - ]
     990   [ +  -  +  -  :      138376 :     + HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")
             +  -  +  - ]
     991         [ +  - ]:       34594 :         },
     992                 :       34594 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     993                 :             : {
     994                 :       32230 :     AddrMan& addrman = EnsureAnyAddrman(request.context);
     995                 :             : 
     996                 :       32230 :     const std::string& addr_string{request.params[0].get_str()};
     997                 :       32230 :     const auto port{request.params[1].getInt<uint16_t>()};
     998         [ +  + ]:       32226 :     const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()};
     999                 :             : 
    1000                 :       32226 :     UniValue obj(UniValue::VOBJ);
    1001   [ +  -  +  - ]:       32226 :     std::optional<CNetAddr> net_addr{LookupHost(addr_string, false)};
    1002         [ +  + ]:       32226 :     if (!net_addr.has_value()) {
    1003   [ +  -  +  - ]:           8 :         throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Invalid IP address");
    1004                 :             :     }
    1005                 :             : 
    1006                 :       32222 :     bool success{false};
    1007                 :             : 
    1008         [ +  - ]:       32222 :     CService service{net_addr.value(), port};
    1009         [ +  - ]:       64444 :     CAddress address{MaybeFlipIPv6toCJDNS(service), ServiceFlags{NODE_NETWORK | NODE_WITNESS}};
    1010                 :       32222 :     address.nTime = Now<NodeSeconds>();
    1011                 :             :     // The source address is set equal to the address. This is equivalent to the peer
    1012                 :             :     // announcing itself.
    1013   [ +  -  +  -  :       64444 :     if (addrman.Add({address}, address)) {
          +  +  +  +  -  
                      - ]
    1014                 :       28401 :         success = true;
    1015         [ +  + ]:       28401 :         if (tried) {
    1016                 :             :             // Attempt to move the address to the tried addresses table.
    1017   [ +  -  +  + ]:          22 :             if (!addrman.Good(address)) {
    1018                 :           2 :                 success = false;
    1019   [ +  -  +  -  :           4 :                 obj.pushKV("error", "failed-adding-to-tried");
                   +  - ]
    1020                 :             :             }
    1021                 :             :         }
    1022                 :             :     } else {
    1023   [ +  -  +  -  :        7642 :         obj.pushKV("error", "failed-adding-to-new");
                   +  - ]
    1024                 :             :     }
    1025                 :             : 
    1026   [ +  -  +  -  :       64444 :     obj.pushKV("success", success);
                   +  - ]
    1027                 :       32222 :     return obj;
    1028                 :       64448 : },
    1029   [ +  -  +  -  :      242158 :     };
             +  +  -  - ]
    1030   [ +  -  +  -  :      276752 : }
          +  -  +  -  +  
             -  -  -  -  
                      - ]
    1031                 :             : 
    1032                 :        2378 : static RPCHelpMan sendmsgtopeer()
    1033                 :             : {
    1034                 :        2378 :     return RPCHelpMan{
    1035                 :        2378 :         "sendmsgtopeer",
    1036         [ +  - ]:        4756 :         "Send a p2p message to a peer specified by id.\n"
    1037                 :             :         "The message type and body must be provided, the message header will be generated.\n"
    1038                 :             :         "This RPC is for testing only.",
    1039                 :             :         {
    1040   [ +  -  +  - ]:        4756 :             {"peer_id", RPCArg::Type::NUM, RPCArg::Optional::NO, "The peer to send the message to."},
    1041   [ +  -  +  - ]:        4756 :             {"msg_type", RPCArg::Type::STR, RPCArg::Optional::NO, strprintf("The message type (maximum length %i)", CMessageHeader::MESSAGE_TYPE_SIZE)},
    1042   [ +  -  +  - ]:        4756 :             {"msg", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The serialized message body to send, in hex, without a message header"},
    1043                 :             :         },
    1044   [ +  -  +  -  :        4756 :         RPCResult{RPCResult::Type::OBJ, "", "", std::vector<RPCResult>{}},
             +  -  +  - ]
    1045                 :        2378 :         RPCExamples{
    1046   [ +  -  +  -  :        7134 :             HelpExampleCli("sendmsgtopeer", "0 \"addr\" \"ffffff\"") + HelpExampleRpc("sendmsgtopeer", "0 \"addr\" \"ffffff\"")},
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    1047                 :        2378 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
    1048                 :          18 :             const NodeId peer_id{request.params[0].getInt<int64_t>()};
    1049                 :          18 :             const auto msg_type{self.Arg<std::string_view>("msg_type")};
    1050         [ +  + ]:          18 :             if (msg_type.size() > CMessageHeader::MESSAGE_TYPE_SIZE) {
    1051   [ +  -  +  - ]:           4 :                 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Error: msg_type too long, max length is %i", CMessageHeader::MESSAGE_TYPE_SIZE));
    1052                 :             :             }
    1053                 :          16 :             auto msg{TryParseHex<unsigned char>(self.Arg<std::string_view>("msg"))};
    1054         [ -  + ]:          16 :             if (!msg.has_value()) {
    1055   [ #  #  #  # ]:           0 :                 throw JSONRPCError(RPC_INVALID_PARAMETER, "Error parsing input for msg");
    1056                 :             :             }
    1057                 :             : 
    1058         [ +  - ]:          16 :             NodeContext& node = EnsureAnyNodeContext(request.context);
    1059         [ +  - ]:          16 :             CConnman& connman = EnsureConnman(node);
    1060                 :             : 
    1061         [ +  - ]:          16 :             CSerializedNetMsg msg_ser;
    1062   [ +  -  +  - ]:          16 :             msg_ser.data = msg.value();
    1063         [ +  - ]:          16 :             msg_ser.m_type = msg_type;
    1064                 :             : 
    1065         [ +  - ]:          16 :             bool success = connman.ForNode(peer_id, [&](CNode* node) {
    1066                 :          14 :                 connman.PushMessage(node, std::move(msg_ser));
    1067                 :          14 :                 return true;
    1068                 :             :             });
    1069                 :             : 
    1070         [ +  + ]:          16 :             if (!success) {
    1071   [ +  -  +  - ]:           4 :                 throw JSONRPCError(RPC_MISC_ERROR, "Error: Could not send message to peer");
    1072                 :             :             }
    1073                 :             : 
    1074                 :          14 :             UniValue ret{UniValue::VOBJ};
    1075                 :          14 :             return ret;
    1076                 :          16 :         },
    1077   [ +  -  +  -  :       16646 :     };
             +  +  -  - ]
    1078   [ +  -  +  -  :       14268 : }
             +  -  -  - ]
    1079                 :             : 
    1080                 :        2377 : static RPCHelpMan getaddrmaninfo()
    1081                 :             : {
    1082                 :        2377 :     return RPCHelpMan{
    1083                 :        2377 :         "getaddrmaninfo",
    1084         [ +  - ]:        4754 :         "Provides information about the node's address manager by returning the number of "
    1085                 :             :         "addresses in the `new` and `tried` tables and their sum for all networks.\n",
    1086                 :             :         {},
    1087         [ +  - ]:        4754 :         RPCResult{
    1088         [ +  - ]:        4754 :             RPCResult::Type::OBJ_DYN, "", "json object with network type as keys", {
    1089   [ +  -  +  -  :        4754 :                 {RPCResult::Type::OBJ, "network", "the network (" + Join(GetNetworkNames(), ", ") + ", all_networks)", {
             +  -  +  - ]
    1090   [ +  -  +  - ]:        4754 :                 {RPCResult::Type::NUM, "new", "number of addresses in the new table, which represent potential peers the node has discovered but hasn't yet successfully connected to."},
    1091   [ +  -  +  - ]:        4754 :                 {RPCResult::Type::NUM, "tried", "number of addresses in the tried table, which represent peers the node has successfully connected to in the past."},
    1092   [ +  -  +  - ]:        4754 :                 {RPCResult::Type::NUM, "total", "total number of addresses in both new/tried tables"},
    1093                 :             :             }},
    1094   [ +  -  +  -  :       21393 :         }},
          +  -  +  +  +  
             +  -  -  -  
                      - ]
    1095   [ +  -  +  -  :        7131 :         RPCExamples{HelpExampleCli("getaddrmaninfo", "") + HelpExampleRpc("getaddrmaninfo", "")},
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    1096                 :        2377 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
    1097                 :           8 :             AddrMan& addrman = EnsureAnyAddrman(request.context);
    1098                 :             : 
    1099                 :           8 :             UniValue ret(UniValue::VOBJ);
    1100         [ +  + ]:          64 :             for (int n = 0; n < NET_MAX; ++n) {
    1101                 :          56 :                 enum Network network = static_cast<enum Network>(n);
    1102         [ +  + ]:          56 :                 if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
    1103                 :          40 :                 UniValue obj(UniValue::VOBJ);
    1104   [ +  -  +  -  :          80 :                 obj.pushKV("new", addrman.Size(network, true));
             +  -  +  - ]
    1105   [ +  -  +  -  :          80 :                 obj.pushKV("tried", addrman.Size(network, false));
             +  -  +  - ]
    1106   [ +  -  +  -  :          80 :                 obj.pushKV("total", addrman.Size(network));
             +  -  +  - ]
    1107   [ +  -  +  - ]:          80 :                 ret.pushKV(GetNetworkName(network), std::move(obj));
    1108                 :          40 :             }
    1109                 :           8 :             UniValue obj(UniValue::VOBJ);
    1110   [ +  -  +  -  :          16 :             obj.pushKV("new", addrman.Size(std::nullopt, true));
             +  -  +  - ]
    1111   [ +  -  +  -  :          16 :             obj.pushKV("tried", addrman.Size(std::nullopt, false));
             +  -  +  - ]
    1112   [ +  -  +  -  :          16 :             obj.pushKV("total", addrman.Size());
             +  -  +  - ]
    1113   [ +  -  +  - ]:          16 :             ret.pushKV("all_networks", std::move(obj));
    1114                 :           8 :             return ret;
    1115                 :           8 :         },
    1116   [ +  -  +  - ]:        9508 :     };
    1117   [ +  -  +  -  :        9508 : }
          +  -  +  -  -  
                      - ]
    1118                 :             : 
    1119                 :          26 : UniValue AddrmanEntryToJSON(const AddrInfo& info, const CConnman& connman)
    1120                 :             : {
    1121                 :          26 :     UniValue ret(UniValue::VOBJ);
    1122   [ +  -  +  -  :          52 :     ret.pushKV("address", info.ToStringAddr());
             +  -  +  - ]
    1123         [ +  - ]:          26 :     const uint32_t mapped_as{connman.GetMappedAS(info)};
    1124         [ +  + ]:          26 :     if (mapped_as) {
    1125   [ +  -  +  -  :           8 :         ret.pushKV("mapped_as", mapped_as);
                   +  - ]
    1126                 :             :     }
    1127   [ +  -  +  -  :          52 :     ret.pushKV("port", info.GetPort());
             +  -  +  - ]
    1128   [ +  -  +  -  :          52 :     ret.pushKV("services", static_cast<std::underlying_type_t<decltype(info.nServices)>>(info.nServices));
                   +  - ]
    1129   [ +  -  +  -  :          52 :     ret.pushKV("time", int64_t{TicksSinceEpoch<std::chrono::seconds>(info.nTime)});
                   +  - ]
    1130   [ +  -  +  -  :          52 :     ret.pushKV("network", GetNetworkName(info.GetNetClass()));
          +  -  +  -  +  
                      - ]
    1131   [ +  -  +  -  :          52 :     ret.pushKV("source", info.source.ToStringAddr());
             +  -  +  - ]
    1132   [ +  -  +  -  :          52 :     ret.pushKV("source_network", GetNetworkName(info.source.GetNetClass()));
          +  -  +  -  +  
                      - ]
    1133         [ +  - ]:          26 :     const uint32_t source_mapped_as{connman.GetMappedAS(info.source)};
    1134         [ +  + ]:          26 :     if (source_mapped_as) {
    1135   [ +  -  +  -  :           8 :         ret.pushKV("source_mapped_as", source_mapped_as);
                   +  - ]
    1136                 :             :     }
    1137                 :          26 :     return ret;
    1138                 :           0 : }
    1139                 :             : 
    1140                 :          14 : UniValue AddrmanTableToJSON(const std::vector<std::pair<AddrInfo, AddressPosition>>& tableInfos, const CConnman& connman)
    1141                 :             : {
    1142                 :          14 :     UniValue table(UniValue::VOBJ);
    1143         [ +  + ]:          40 :     for (const auto& e : tableInfos) {
    1144                 :          26 :         AddrInfo info = e.first;
    1145                 :          26 :         AddressPosition location = e.second;
    1146         [ +  - ]:          26 :         std::ostringstream key;
    1147   [ +  -  +  -  :          26 :         key << location.bucket << "/" << location.position;
                   +  - ]
    1148                 :             :         // Address manager tables have unique entries so there is no advantage
    1149                 :             :         // in using UniValue::pushKV, which checks if the key already exists
    1150                 :             :         // in O(N). UniValue::pushKVEnd is used instead which currently is O(1).
    1151   [ +  -  +  - ]:          78 :         table.pushKVEnd(key.str(), AddrmanEntryToJSON(info, connman));
    1152                 :          52 :     }
    1153                 :          14 :     return table;
    1154                 :           0 : }
    1155                 :             : 
    1156                 :        2369 : static RPCHelpMan getrawaddrman()
    1157                 :             : {
    1158                 :        2369 :     return RPCHelpMan{"getrawaddrman",
    1159         [ +  - ]:        4738 :         "EXPERIMENTAL warning: this call may be changed in future releases.\n"
    1160                 :             :         "\nReturns information on all address manager entries for the new and tried tables.\n",
    1161                 :             :         {},
    1162         [ +  - ]:        4738 :         RPCResult{
    1163         [ +  - ]:        4738 :             RPCResult::Type::OBJ_DYN, "", "", {
    1164   [ +  -  +  - ]:        4738 :                 {RPCResult::Type::OBJ_DYN, "table", "buckets with addresses in the address manager table ( new, tried )", {
    1165   [ +  -  +  - ]:        4738 :                     {RPCResult::Type::OBJ, "bucket/position", "the location in the address manager table (<bucket>/<position>)", {
    1166   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::STR, "address", "The address of the node"},
    1167   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::NUM, "mapped_as", /*optional=*/true, "Mapped AS (Autonomous System) number at the end of the BGP route to the peer, used for diversifying peer selection (only displayed if the -asmap config option is set)"},
    1168   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::NUM, "port", "The port number of the node"},
    1169   [ +  -  +  -  :        4738 :                         {RPCResult::Type::STR, "network", "The network (" + Join(GetNetworkNames(), ", ") + ") of the address"},
             +  -  +  - ]
    1170   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::NUM, "services", "The services offered by the node"},
    1171   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " when the node was last seen"},
    1172   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::STR, "source", "The address that relayed the address to us"},
    1173   [ +  -  +  -  :        4738 :                         {RPCResult::Type::STR, "source_network", "The network (" + Join(GetNetworkNames(), ", ") + ") of the source address"},
             +  -  +  - ]
    1174   [ +  -  +  - ]:        4738 :                         {RPCResult::Type::NUM, "source_mapped_as", /*optional=*/true, "Mapped AS (Autonomous System) number at the end of the BGP route to the source, used for diversifying peer selection (only displayed if the -asmap config option is set)"}
    1175                 :             :                     }}
    1176                 :             :                 }}
    1177                 :             :             }
    1178   [ +  -  +  -  :       54487 :         },
          +  -  +  -  +  
          +  +  +  +  +  
          -  -  -  -  -  
                      - ]
    1179                 :        2369 :         RPCExamples{
    1180   [ +  -  +  -  :        4738 :             HelpExampleCli("getrawaddrman", "")
                   +  - ]
    1181   [ +  -  +  -  :        9476 :             + HelpExampleRpc("getrawaddrman", "")
             +  -  +  - ]
    1182         [ +  - ]:        2369 :         },
    1183                 :        2369 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
    1184                 :           7 :             AddrMan& addrman = EnsureAnyAddrman(request.context);
    1185                 :           7 :             NodeContext& node_context = EnsureAnyNodeContext(request.context);
    1186                 :           7 :             CConnman& connman = EnsureConnman(node_context);
    1187                 :             : 
    1188                 :           7 :             UniValue ret(UniValue::VOBJ);
    1189   [ +  -  +  -  :          14 :             ret.pushKV("new", AddrmanTableToJSON(addrman.GetEntries(false), connman));
             +  -  +  - ]
    1190   [ +  -  +  -  :          14 :             ret.pushKV("tried", AddrmanTableToJSON(addrman.GetEntries(true), connman));
             +  -  +  - ]
    1191                 :           7 :             return ret;
    1192                 :           0 :         },
    1193   [ +  -  +  - ]:        9476 :     };
    1194   [ +  -  +  -  :       26059 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      - ]
    1195                 :             : 
    1196                 :        1313 : void RegisterNetRPCCommands(CRPCTable& t)
    1197                 :             : {
    1198                 :        1313 :     static const CRPCCommand commands[]{
    1199         [ +  - ]:        2358 :         {"network", &getconnectioncount},
    1200         [ +  - ]:        2358 :         {"network", &ping},
    1201         [ +  - ]:        2358 :         {"network", &getpeerinfo},
    1202         [ +  - ]:        2358 :         {"network", &addnode},
    1203         [ +  - ]:        2358 :         {"network", &disconnectnode},
    1204         [ +  - ]:        2358 :         {"network", &getaddednodeinfo},
    1205         [ +  - ]:        2358 :         {"network", &getnettotals},
    1206         [ +  - ]:        2358 :         {"network", &getnetworkinfo},
    1207         [ +  - ]:        2358 :         {"network", &setban},
    1208         [ +  - ]:        2358 :         {"network", &listbanned},
    1209         [ +  - ]:        2358 :         {"network", &clearbanned},
    1210         [ +  - ]:        2358 :         {"network", &setnetworkactive},
    1211         [ +  - ]:        2358 :         {"network", &getnodeaddresses},
    1212         [ +  - ]:        2358 :         {"network", &getaddrmaninfo},
    1213         [ +  - ]:        2358 :         {"hidden", &addconnection},
    1214         [ +  - ]:        2358 :         {"hidden", &addpeeraddress},
    1215         [ +  - ]:        2358 :         {"hidden", &sendmsgtopeer},
    1216         [ +  - ]:        2358 :         {"hidden", &getrawaddrman},
    1217   [ +  +  +  -  :       22535 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  - ]
    1218         [ +  + ]:       24947 :     for (const auto& c : commands) {
    1219                 :       23634 :         t.appendCommand(c.name, &c);
    1220                 :             :     }
    1221                 :        1313 : }
        

Generated by: LCOV version 2.0-1