diff --git a/src/addrman.cpp b/src/addrman.cpp index 324bab7292..40e087f5fb 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -745,7 +745,7 @@ std::pair AddrManImpl::Select_(bool newOnly) const } } -void AddrManImpl::GetAddr_(std::vector& vAddr, size_t max_addresses, size_t max_pct, std::optional network) const +std::vector AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional network) const { AssertLockHeld(cs); @@ -759,8 +759,9 @@ void AddrManImpl::GetAddr_(std::vector& vAddr, size_t max_addresses, s // gather a list of random nodes, skipping those of low quality const int64_t now{GetAdjustedTime()}; + std::vector addresses; for (unsigned int n = 0; n < vRandom.size(); n++) { - if (vAddr.size() >= nNodes) + if (addresses.size() >= nNodes) break; int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n; @@ -776,8 +777,10 @@ void AddrManImpl::GetAddr_(std::vector& vAddr, size_t max_addresses, s // Filter for quality if (ai.IsTerrible(now)) continue; - vAddr.push_back(ai); + addresses.push_back(ai); } + + return addresses; } void AddrManImpl::Connected_(const CService& addr, int64_t nTime) @@ -1080,10 +1083,9 @@ std::vector AddrManImpl::GetAddr(size_t max_addresses, size_t max_pct, { LOCK(cs); Check(); - std::vector vAddr; - GetAddr_(vAddr, max_addresses, max_pct, network); + const auto addresses = GetAddr_(max_addresses, max_pct, network); Check(); - return vAddr; + return addresses; } void AddrManImpl::Connected(const CService &addr, int64_t nTime) diff --git a/src/addrman_impl.h b/src/addrman_impl.h index 1d13df803d..918034caf8 100644 --- a/src/addrman_impl.h +++ b/src/addrman_impl.h @@ -242,12 +242,13 @@ private: /** * Return all or many randomly selected addresses, optionally by network. * - * @param[out] vAddr Vector of randomly selected addresses from vRandom. * @param[in] max_addresses Maximum number of addresses to return (0 = all). * @param[in] max_pct Maximum percentage of addresses to return (0 = all). * @param[in] network Select only addresses of this network (nullopt = all). + * + * @returns A vector of randomly selected addresses from vRandom. */ - void GetAddr_(std::vector& vAddr, size_t max_addresses, size_t max_pct, std::optional network) const EXCLUSIVE_LOCKS_REQUIRED(cs); + std::vector GetAddr_(size_t max_addresses, size_t max_pct, std::optional network) const EXCLUSIVE_LOCKS_REQUIRED(cs); /** We have successfully connected to this peer. Calling this function * updates the CAddress's nTime, which is used in our IsTerrible()