Skip to content

Commit 1cb2399

Browse files
doc: clarify the GetAddresses/GetAddressesUnsafe documentation
Better reflect in the documentation that the two methods should be used in different contexts. Also update the outdated "call the function without a parameter" phrasing in the cached version. This wording was accurate when the cache was introduced in #18991, but became outdated after later commits (f26502e, 81b00f8) added parameters to each function, and the previous commit changed the function naming completely. Co-Authored-By: stickies-v <[email protected]>
1 parent e5a7dfd commit 1cb2399

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/net.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,10 @@ class CConnman
11691169

11701170
// Addrman functions
11711171
/**
1172-
* Return all or many randomly selected addresses, optionally by network.
1172+
* Return randomly selected addresses. This function does not use the address response cache and
1173+
* should only be used in trusted contexts.
1174+
*
1175+
* An untrusted caller (e.g. from p2p) should instead use @ref GetAddresses to use the cache.
11731176
*
11741177
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
11751178
* @param[in] max_pct Maximum percentage of addresses to return (0 = all). Value must be from 0 to 100.
@@ -1178,10 +1181,18 @@ class CConnman
11781181
*/
11791182
std::vector<CAddress> GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
11801183
/**
1181-
* Cache is used to minimize topology leaks, so it should
1182-
* be used for all non-trusted calls, for example, p2p.
1183-
* A non-malicious call (from RPC or a peer with addr permission) should
1184-
* call the function without a parameter to avoid using the cache.
1184+
* Return addresses from the per-requestor cache. If no cache entry exists, it is populated with
1185+
* randomly selected addresses. This function can be used in untrusted contexts.
1186+
*
1187+
* A trusted caller (e.g. from RPC or a peer with addr permission) can use
1188+
* @ref GetAddressesUnsafe to avoid using the cache.
1189+
*
1190+
* @param[in] requestor The requesting peer. Used to key the cache to prevent privacy leaks.
1191+
* @param[in] max_addresses Maximum number of addresses to return (0 = all). Ignored when cache
1192+
* already contains an entry for requestor.
1193+
* @param[in] max_pct Maximum percentage of addresses to return (0 = all). Value must be
1194+
* from 0 to 100. Ignored when cache already contains an entry for
1195+
* requestor.
11851196
*/
11861197
std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);
11871198

0 commit comments

Comments
 (0)