LCOV - code coverage report
Current view: top level - src/rpc - net.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 520 846 61.5 %
Date: 2023-10-05 15:40:34 Functions: 38 48 79.2 %
Branches: 1068 3305 32.3 %

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

Generated by: LCOV version 1.14