Skip to content

Commit 14f9e00

Browse files
committed
[refactor] Update GetAddr_() function signature
Update so the internal function signature matches the external one, as is the case for the other addrman functions.
1 parent 40acd6f commit 14f9e00

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/addrman.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
745745
}
746746
}
747747

748-
void AddrManImpl::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const
748+
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
749749
{
750750
AssertLockHeld(cs);
751751

@@ -759,8 +759,9 @@ void AddrManImpl::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, s
759759

760760
// gather a list of random nodes, skipping those of low quality
761761
const int64_t now{GetAdjustedTime()};
762+
std::vector<CAddress> addresses;
762763
for (unsigned int n = 0; n < vRandom.size(); n++) {
763-
if (vAddr.size() >= nNodes)
764+
if (addresses.size() >= nNodes)
764765
break;
765766

766767
int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n;
@@ -776,8 +777,10 @@ void AddrManImpl::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, s
776777
// Filter for quality
777778
if (ai.IsTerrible(now)) continue;
778779

779-
vAddr.push_back(ai);
780+
addresses.push_back(ai);
780781
}
782+
783+
return addresses;
781784
}
782785

783786
void AddrManImpl::Connected_(const CService& addr, int64_t nTime)
@@ -1080,10 +1083,9 @@ std::vector<CAddress> AddrManImpl::GetAddr(size_t max_addresses, size_t max_pct,
10801083
{
10811084
LOCK(cs);
10821085
Check();
1083-
std::vector<CAddress> vAddr;
1084-
GetAddr_(vAddr, max_addresses, max_pct, network);
1086+
const auto addresses = GetAddr_(max_addresses, max_pct, network);
10851087
Check();
1086-
return vAddr;
1088+
return addresses;
10871089
}
10881090

10891091
void AddrManImpl::Connected(const CService &addr, int64_t nTime)

src/addrman_impl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,13 @@ class AddrManImpl
242242
/**
243243
* Return all or many randomly selected addresses, optionally by network.
244244
*
245-
* @param[out] vAddr Vector of randomly selected addresses from vRandom.
246245
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
247246
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
248247
* @param[in] network Select only addresses of this network (nullopt = all).
248+
*
249+
* @returns A vector of randomly selected addresses from vRandom.
249250
*/
250-
void GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
251+
std::vector<CAddress> GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
251252

252253
/** We have successfully connected to this peer. Calling this function
253254
* updates the CAddress's nTime, which is used in our IsTerrible()

0 commit comments

Comments
 (0)