aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/net.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/net.cpp')
-rw-r--r--src/rpc/net.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 1f6b6e8d7e..4999eefc24 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -28,6 +28,8 @@
#include <version.h>
#include <warnings.h>
+#include <optional>
+
#include <univalue.h>
const std::vector<std::string> CONNECTION_TYPE_DOC{
@@ -159,7 +161,7 @@ static RPCHelpMan getpeerinfo()
"When a message type is not listed in this json object, the bytes sent are 0.\n"
"Only known message types can appear as keys in the object."}
}},
- {RPCResult::Type::OBJ, "bytesrecv_per_msg", "",
+ {RPCResult::Type::OBJ_DYN, "bytesrecv_per_msg", "",
{
{RPCResult::Type::NUM, "msg", "The total bytes received aggregated by message type\n"
"When a message type is not listed in this json object, the bytes received are 0.\n"
@@ -851,6 +853,7 @@ static RPCHelpMan getnodeaddresses()
"\nReturn known addresses, which can potentially be used to find new nodes in the network.\n",
{
{"count", RPCArg::Type::NUM, RPCArg::Default{1}, "The maximum number of addresses to return. Specify 0 to return all known addresses."},
+ {"network", RPCArg::Type::STR, RPCArg::DefaultHint{"all networks"}, "Return only addresses of the specified network. Can be one of: " + Join(GetNetworkNames(), ", ") + "."},
},
RPCResult{
RPCResult::Type::ARR, "", "",
@@ -867,7 +870,10 @@ static RPCHelpMan getnodeaddresses()
},
RPCExamples{
HelpExampleCli("getnodeaddresses", "8")
- + HelpExampleRpc("getnodeaddresses", "8")
+ + HelpExampleCli("getnodeaddresses", "4 \"i2p\"")
+ + HelpExampleCli("-named getnodeaddresses", "network=onion count=12")
+ + HelpExampleRpc("getnodeaddresses", "8")
+ + HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
@@ -877,8 +883,13 @@ static RPCHelpMan getnodeaddresses()
const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()};
if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
+ const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}};
+ if (network == NET_UNROUTABLE) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Network not recognized: %s", request.params[1].get_str()));
+ }
+
// returns a shuffled list of CAddress
- const std::vector<CAddress> vAddr{connman.GetAddresses(count, /* max_pct */ 0)};
+ const std::vector<CAddress> vAddr{connman.GetAddresses(count, /* max_pct */ 0, network)};
UniValue ret(UniValue::VARR);
for (const CAddress& addr : vAddr) {