Skip to content

Commit

Permalink
p2p: enable CAddrMan::GetAddr_() by network, add doxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzbawls committed Aug 12, 2021
1 parent 67e2c2f commit d5c1250
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/addrman.cpp
Expand Up @@ -7,8 +7,10 @@
#include "addrman.h"

#include "hash.h"
#include "streams.h"
#include "logging.h"
#include "netaddress.h"
#include "optional.h"
#include "streams.h"
#include "serialize.h"


Expand Down Expand Up @@ -481,7 +483,7 @@ int CAddrMan::Check_()
}
#endif

void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct)
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, Optional<Network> network)
{
size_t nNodes = vRandom.size();
if (max_pct != 0) {
Expand All @@ -501,8 +503,14 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size
assert(mapInfo.count(vRandom[n]) == 1);

const CAddrInfo& ai = mapInfo[vRandom[n]];
if (!ai.IsTerrible())
vAddr.push_back(ai);

// Filter by network (optional)
if (network != nullopt && ai.GetNetClass() != network) continue;

// Filter for quality
if (ai.IsTerrible()) continue;

vAddr.push_back(ai);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/addrman.h
Expand Up @@ -13,6 +13,7 @@

#include "clientversion.h"
#include "netaddress.h"
#include "optional.h"
#include "protocol.h"
#include "random.h"
#include "sync.h"
Expand Down Expand Up @@ -282,8 +283,15 @@ friend class CAddrManTest;
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs);
#endif

//! Select several addresses at once.
void GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct) EXCLUSIVE_LOCKS_REQUIRED(cs);
/**
* 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).
*/
void GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, Optional<Network> network = nullopt) EXCLUSIVE_LOCKS_REQUIRED(cs);

//! Mark an entry as currently-connected-to.
void Connected_(const CService& addr, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs);
Expand Down

0 comments on commit d5c1250

Please sign in to comment.