LCOV - code coverage report
Current view: top level - src/rpc - net.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 363 795 45.7 %
Date: 2023-11-04 20:49:09 Functions: 18 43 41.9 %
Branches: 794 3041 26.1 %

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

Generated by: LCOV version 1.14