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
(f26502e9fc,
81b00f8780) added parameters to each
function, and the previous commit changed the function naming completely.

Co-Authored-By: stickies-v <stickies-v@protonmail.com>
This commit is contained in:
Daniela Brozzoni
2025-07-21 14:48:06 +02:00
parent e5a7dfd79f
commit 1cb2399703

View File

@@ -1169,7 +1169,10 @@ public:
// Addrman functions
/**
* Return all or many randomly selected addresses, optionally by network.
* Return randomly selected addresses. This function does not use the address response cache and
* should only be used in trusted contexts.
*
* An untrusted caller (e.g. from p2p) should instead use @ref GetAddresses to use the cache.
*
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
* @param[in] max_pct Maximum percentage of addresses to return (0 = all). Value must be from 0 to 100.
@@ -1178,10 +1181,18 @@ public:
*/
std::vector<CAddress> GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
/**
* Cache is used to minimize topology leaks, so it should
* be used for all non-trusted calls, for example, p2p.
* A non-malicious call (from RPC or a peer with addr permission) should
* call the function without a parameter to avoid using the cache.
* Return addresses from the per-requestor cache. If no cache entry exists, it is populated with
* randomly selected addresses. This function can be used in untrusted contexts.
*
* A trusted caller (e.g. from RPC or a peer with addr permission) can use
* @ref GetAddressesUnsafe to avoid using the cache.
*
* @param[in] requestor The requesting peer. Used to key the cache to prevent privacy leaks.
* @param[in] max_addresses Maximum number of addresses to return (0 = all). Ignored when cache
* already contains an entry for requestor.
* @param[in] max_pct Maximum percentage of addresses to return (0 = all). Value must be
* from 0 to 100. Ignored when cache already contains an entry for
* requestor.
*/
std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);