aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorstratospher <44024636+stratospher@users.noreply.github.com>2023-01-29 18:59:00 +0530
committerstratospher <44024636+stratospher@users.noreply.github.com>2023-09-19 16:02:55 +0530
commitc8eb8dae51039aa1938e7040001a149210e87275 (patch)
treed2507978bb9edcdcd488da73c7c82febdf7ab192 /src/rpc
parent83719146047947e588aa0c7b5eee02f44884553d (diff)
downloadbitcoin-c8eb8dae51039aa1938e7040001a149210e87275.tar.xz
rpc: Introduce getaddrmaninfo for count of addresses stored in new/tried table
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/net.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index f7b6c68344..e9e9ad62ae 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -1016,6 +1016,55 @@ 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;
+ },
+ };
+}
+
void RegisterNetRPCCommands(CRPCTable& t)
{
static const CRPCCommand commands[]{
@@ -1035,6 +1084,7 @@ void RegisterNetRPCCommands(CRPCTable& t)
{"hidden", &addconnection},
{"hidden", &addpeeraddress},
{"hidden", &sendmsgtopeer},
+ {"hidden", &getaddrmaninfo},
};
for (const auto& c : commands) {
t.appendCommand(c.name, &c);