Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ Changes to Wallet or GUI related settings can be found in the GUI or Wallet sect

- Passing an invalid `-rpcauth` argument now cause bitcoind to fail to start. (#20461)

- The `getnodeaddresses` RPC now returns a "network" field indicating the
network type (ipv4, ipv6, onion, or i2p) for each address. (#21594)

Tools and Utilities
-------------------

Expand Down
22 changes: 10 additions & 12 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ static RPCHelpMan setnetworkactive()
static RPCHelpMan getnodeaddresses()
{
return RPCHelpMan{"getnodeaddresses",
"\nReturn known addresses which can potentially be used to find new nodes in the network\n",
"\nReturn known addresses, which can potentially be used to find new nodes in the network.\n",
{
{"count", RPCArg::Type::NUM, /* default */ "1", "The maximum number of addresses to return. Specify 0 to return all known addresses."},
},
Expand All @@ -844,10 +844,11 @@ static RPCHelpMan getnodeaddresses()
{
{RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " of when the node was last seen"},
{RPCResult::Type::NUM, "services", "The services offered"},
{RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " when the node was last seen"},
{RPCResult::Type::NUM, "services", "The services offered by the node"},
{RPCResult::Type::STR, "address", "The address of the node"},
{RPCResult::Type::NUM, "port", "The port of the node"},
{RPCResult::Type::NUM, "port", "The port number of the node"},
{RPCResult::Type::STR, "network", "The network (" + Join(GetNetworkNames(), ", ") + ") the node connected through"},
}},
}
},
Expand All @@ -862,15 +863,11 @@ static RPCHelpMan getnodeaddresses()
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
}

int count = 1;
if (!request.params[0].isNull()) {
count = request.params[0].get_int();
if (count < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
}
}
const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()};
Comment thread
jonatack marked this conversation as resolved.
Outdated
if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");

// returns a shuffled list of CAddress
std::vector<CAddress> vAddr = node.connman->GetAddresses(count, /* max_pct */ 0);
const std::vector<CAddress> vAddr{node.connman->GetAddresses(count, /* max_pct */ 0)};
UniValue ret(UniValue::VARR);

for (const CAddress& addr : vAddr) {
Expand All @@ -879,6 +876,7 @@ static RPCHelpMan getnodeaddresses()
obj.pushKV("services", (uint64_t)addr.nServices);
obj.pushKV("address", addr.ToStringIP());
obj.pushKV("port", addr.GetPort());
obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
Comment thread
jonatack marked this conversation as resolved.
Outdated
ret.push_back(obj);
}
return ret;
Expand Down
3 changes: 2 additions & 1 deletion test/functional/rpc_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_getnodeaddresses(self):
for i in range(10000):
first_octet = i >> 8
second_octet = i % 256
a = "{}.{}.1.1".format(first_octet, second_octet)
a = "{}.{}.1.1".format(first_octet, second_octet) # IPV4
imported_addrs.append(a)
self.nodes[0].addpeeraddress(a, 8333)

Expand All @@ -212,6 +212,7 @@ def test_getnodeaddresses(self):
assert_equal(a["services"], NODE_NETWORK | NODE_WITNESS)
assert a["address"] in imported_addrs
assert_equal(a["port"], 8333)
assert_equal(a["network"], "ipv4")

node_addresses = self.nodes[0].getnodeaddresses(1)
assert_equal(len(node_addresses), 1)
Expand Down