Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13711159
D11126.id32580.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D11126.id32580.diff
View Options
diff --git a/doc/release-notes.md b/doc/release-notes.md
--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -5,3 +5,5 @@
<https://download.bitcoinabc.org/0.25.1/>
This release includes the following features and fixes:
+- The `getnodeaddresses` RPC now returns a "network" field indicating the
+ network type (ipv4, ipv6, onion, or i2p) for each address.
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -1069,31 +1069,35 @@
static RPCHelpMan getnodeaddresses() {
return RPCHelpMan{
"getnodeaddresses",
- "Return known addresses which can potentially be used to find new "
- "nodes in the network\n",
+ "Return 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."},
},
- RPCResult{
- RPCResult::Type::ARR,
- "",
- "",
- {
- {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::STR, "address",
- "The address of the node"},
- {RPCResult::Type::NUM, "port", "The port of the node"},
- }},
- }},
+ RPCResult{RPCResult::Type::ARR,
+ "",
+ "",
+ {
+ {RPCResult::Type::OBJ,
+ "",
+ "",
+ {
+ {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 number of the node"},
+ {RPCResult::Type::STR, "network",
+ "The network (" + Join(GetNetworkNames(), ", ") +
+ ") the node connected through"},
+ }},
+ }},
RPCExamples{HelpExampleCli("getnodeaddresses", "8") +
HelpExampleRpc("getnodeaddresses", "8")},
[&](const RPCHelpMan &self, const Config &config,
@@ -1105,17 +1109,16 @@
"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()};
+ 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) {
@@ -1124,6 +1127,7 @@
obj.pushKV("services", uint64_t(addr.nServices));
obj.pushKV("address", addr.ToStringIP());
obj.pushKV("port", addr.GetPort());
+ obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
ret.push_back(obj);
}
return ret;
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py
--- a/test/functional/rpc_net.py
+++ b/test/functional/rpc_net.py
@@ -251,7 +251,7 @@
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)
@@ -268,6 +268,7 @@
assert_equal(a["services"], NODE_NETWORK)
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)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 26, 10:37 (5 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573304
Default Alt Text
D11126.id32580.diff (5 KB)
Attached To
D11126: rpc: add network field to rpc getnodeaddresses
Event Timeline
Log In to Comment