diff options
author | stratospher <44024636+stratospher@users.noreply.github.com> | 2023-10-03 09:04:40 +0530 |
---|---|---|
committer | stratospher <44024636+stratospher@users.noreply.github.com> | 2023-10-04 08:34:30 +0530 |
commit | 3931e6abc39b8aee1472028dbf76eeb10708d2b4 (patch) | |
tree | 29ebccfb127b338db616879bd47d847ba50a67c5 /src | |
parent | 97f756b12c8d8a9d3b621f296725dd7bf36bc8a9 (diff) |
rpc: `getaddrmaninfo` followups
- make `getaddrmaninfo` RPC public since it's not for development
purposes only and regular users might find it useful
- add missing `all_networks` key to RPC help
- use clang format spacing
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/net.cpp | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 96d06b6b9f..70d1cc715f 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -1033,50 +1033,43 @@ static RPCHelpMan sendmsgtopeer() static RPCHelpMan getaddrmaninfo() { - return RPCHelpMan{"getaddrmaninfo", - "\nProvides information about the node's address manager by returning the number of " - "addresses in the `new` and `tried` tables and their sum for all networks.\n" - "This RPC is for testing only.\n", - {}, - RPCResult{ - RPCResult::Type::OBJ_DYN, "", "json object with network type as keys", - { - {RPCResult::Type::OBJ, "network", "the network (" + Join(GetNetworkNames(), ", ") + ")", - { - {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."}, - {RPCResult::Type::NUM, "tried", "number of addresses in the tried table, which represent peers the node has successfully connected to in the past."}, - {RPCResult::Type::NUM, "total", "total number of addresses in both new/tried tables"}, - }}, - } - }, - RPCExamples{ - HelpExampleCli("getaddrmaninfo", "") - + HelpExampleRpc("getaddrmaninfo", "") - }, - [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue - { - NodeContext& node = EnsureAnyNodeContext(request.context); - if (!node.addrman) { - throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled"); - } - - UniValue ret(UniValue::VOBJ); - for (int n = 0; n < NET_MAX; ++n) { - enum Network network = static_cast<enum Network>(n); - if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue; - UniValue obj(UniValue::VOBJ); - obj.pushKV("new", node.addrman->Size(network, true)); - obj.pushKV("tried", node.addrman->Size(network, false)); - obj.pushKV("total", node.addrman->Size(network)); - ret.pushKV(GetNetworkName(network), obj); - } - UniValue obj(UniValue::VOBJ); - obj.pushKV("new", node.addrman->Size(std::nullopt, true)); - obj.pushKV("tried", node.addrman->Size(std::nullopt, false)); - obj.pushKV("total", node.addrman->Size()); - ret.pushKV("all_networks", obj); - return ret; - }, + return RPCHelpMan{ + "getaddrmaninfo", + "\nProvides information about the node's address manager by returning the number of " + "addresses in the `new` and `tried` tables and their sum for all networks.\n", + {}, + RPCResult{ + RPCResult::Type::OBJ_DYN, "", "json object with network type as keys", { + {RPCResult::Type::OBJ, "network", "the network (" + Join(GetNetworkNames(), ", ") + ", all_networks)", { + {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."}, + {RPCResult::Type::NUM, "tried", "number of addresses in the tried table, which represent peers the node has successfully connected to in the past."}, + {RPCResult::Type::NUM, "total", "total number of addresses in both new/tried tables"}, + }}, + }}, + RPCExamples{HelpExampleCli("getaddrmaninfo", "") + HelpExampleRpc("getaddrmaninfo", "")}, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { + NodeContext& node = EnsureAnyNodeContext(request.context); + if (!node.addrman) { + throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled"); + } + + UniValue ret(UniValue::VOBJ); + for (int n = 0; n < NET_MAX; ++n) { + enum Network network = static_cast<enum Network>(n); + if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue; + UniValue obj(UniValue::VOBJ); + obj.pushKV("new", node.addrman->Size(network, true)); + obj.pushKV("tried", node.addrman->Size(network, false)); + obj.pushKV("total", node.addrman->Size(network)); + ret.pushKV(GetNetworkName(network), obj); + } + UniValue obj(UniValue::VOBJ); + obj.pushKV("new", node.addrman->Size(std::nullopt, true)); + obj.pushKV("tried", node.addrman->Size(std::nullopt, false)); + obj.pushKV("total", node.addrman->Size()); + ret.pushKV("all_networks", obj); + return ret; + }, }; } @@ -1164,10 +1157,10 @@ void RegisterNetRPCCommands(CRPCTable& t) {"network", &clearbanned}, {"network", &setnetworkactive}, {"network", &getnodeaddresses}, + {"network", &getaddrmaninfo}, {"hidden", &addconnection}, {"hidden", &addpeeraddress}, {"hidden", &sendmsgtopeer}, - {"hidden", &getaddrmaninfo}, {"hidden", &getrawaddrman}, }; for (const auto& c : commands) { |