Skip to content

Commit 3931e6a

Browse files
committed
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
1 parent 97f756b commit 3931e6a

File tree

2 files changed

+38
-50
lines changed

2 files changed

+38
-50
lines changed

src/rpc/net.cpp

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,50 +1033,43 @@ static RPCHelpMan sendmsgtopeer()
10331033

10341034
static RPCHelpMan getaddrmaninfo()
10351035
{
1036-
return RPCHelpMan{"getaddrmaninfo",
1037-
"\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-
{},
1041-
RPCResult{
1042-
RPCResult::Type::OBJ_DYN, "", "json object with network type as keys",
1043-
{
1044-
{RPCResult::Type::OBJ, "network", "the network (" + Join(GetNetworkNames(), ", ") + ")",
1045-
{
1046-
{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-
{RPCResult::Type::NUM, "tried", "number of addresses in the tried table, which represent peers the node has successfully connected to in the past."},
1048-
{RPCResult::Type::NUM, "total", "total number of addresses in both new/tried tables"},
1049-
}},
1050-
}
1051-
},
1052-
RPCExamples{
1053-
HelpExampleCli("getaddrmaninfo", "")
1054-
+ HelpExampleRpc("getaddrmaninfo", "")
1055-
},
1056-
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1057-
{
1058-
NodeContext& node = EnsureAnyNodeContext(request.context);
1059-
if (!node.addrman) {
1060-
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
1061-
}
1062-
1063-
UniValue ret(UniValue::VOBJ);
1064-
for (int n = 0; n < NET_MAX; ++n) {
1065-
enum Network network = static_cast<enum Network>(n);
1066-
if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
1067-
UniValue obj(UniValue::VOBJ);
1068-
obj.pushKV("new", node.addrman->Size(network, true));
1069-
obj.pushKV("tried", node.addrman->Size(network, false));
1070-
obj.pushKV("total", node.addrman->Size(network));
1071-
ret.pushKV(GetNetworkName(network), obj);
1072-
}
1073-
UniValue obj(UniValue::VOBJ);
1074-
obj.pushKV("new", node.addrman->Size(std::nullopt, true));
1075-
obj.pushKV("tried", node.addrman->Size(std::nullopt, false));
1076-
obj.pushKV("total", node.addrman->Size());
1077-
ret.pushKV("all_networks", obj);
1078-
return ret;
1079-
},
1036+
return RPCHelpMan{
1037+
"getaddrmaninfo",
1038+
"\nProvides information about the node's address manager by returning the number of "
1039+
"addresses in the `new` and `tried` tables and their sum for all networks.\n",
1040+
{},
1041+
RPCResult{
1042+
RPCResult::Type::OBJ_DYN, "", "json object with network type as keys", {
1043+
{RPCResult::Type::OBJ, "network", "the network (" + Join(GetNetworkNames(), ", ") + ", all_networks)", {
1044+
{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."},
1045+
{RPCResult::Type::NUM, "tried", "number of addresses in the tried table, which represent peers the node has successfully connected to in the past."},
1046+
{RPCResult::Type::NUM, "total", "total number of addresses in both new/tried tables"},
1047+
}},
1048+
}},
1049+
RPCExamples{HelpExampleCli("getaddrmaninfo", "") + HelpExampleRpc("getaddrmaninfo", "")},
1050+
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
1051+
NodeContext& node = EnsureAnyNodeContext(request.context);
1052+
if (!node.addrman) {
1053+
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
1054+
}
1055+
1056+
UniValue ret(UniValue::VOBJ);
1057+
for (int n = 0; n < NET_MAX; ++n) {
1058+
enum Network network = static_cast<enum Network>(n);
1059+
if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
1060+
UniValue obj(UniValue::VOBJ);
1061+
obj.pushKV("new", node.addrman->Size(network, true));
1062+
obj.pushKV("tried", node.addrman->Size(network, false));
1063+
obj.pushKV("total", node.addrman->Size(network));
1064+
ret.pushKV(GetNetworkName(network), obj);
1065+
}
1066+
UniValue obj(UniValue::VOBJ);
1067+
obj.pushKV("new", node.addrman->Size(std::nullopt, true));
1068+
obj.pushKV("tried", node.addrman->Size(std::nullopt, false));
1069+
obj.pushKV("total", node.addrman->Size());
1070+
ret.pushKV("all_networks", obj);
1071+
return ret;
1072+
},
10801073
};
10811074
}
10821075

@@ -1164,10 +1157,10 @@ void RegisterNetRPCCommands(CRPCTable& t)
11641157
{"network", &clearbanned},
11651158
{"network", &setnetworkactive},
11661159
{"network", &getnodeaddresses},
1160+
{"network", &getaddrmaninfo},
11671161
{"hidden", &addconnection},
11681162
{"hidden", &addpeeraddress},
11691163
{"hidden", &sendmsgtopeer},
1170-
{"hidden", &getaddrmaninfo},
11711164
{"hidden", &getrawaddrman},
11721165
};
11731166
for (const auto& c : commands) {

test/functional/rpc_net.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,6 @@ def test_getaddrmaninfo(self):
371371
self.log.info("Test getaddrmaninfo")
372372
node = self.nodes[1]
373373

374-
self.log.debug("Test that getaddrmaninfo is a hidden RPC")
375-
# It is hidden from general help, but its detailed help may be called directly.
376-
assert "getaddrmaninfo" not in node.help()
377-
assert "getaddrmaninfo" in node.help("getaddrmaninfo")
378-
379374
# current count of ipv4 addresses in addrman is {'new':1, 'tried':1}
380375
self.log.info("Test that count of addresses in addrman match expected values")
381376
res = node.getaddrmaninfo()

0 commit comments

Comments
 (0)