p2p: enable CAddrMan::GetAddr_() by network, add doxygen

This commit is contained in:
Jon Atack
2021-05-02 18:44:17 +02:00
parent 4da26fb85d
commit d35ddca91e
2 changed files with 21 additions and 5 deletions

View File

@@ -7,9 +7,11 @@
#include <hash.h> #include <hash.h>
#include <logging.h> #include <logging.h>
#include <netaddress.h>
#include <serialize.h> #include <serialize.h>
#include <cmath> #include <cmath>
#include <optional>
int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
{ {
@@ -481,7 +483,7 @@ int CAddrMan::Check_()
} }
#endif #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, std::optional<Network> network)
{ {
size_t nNodes = vRandom.size(); size_t nNodes = vRandom.size();
if (max_pct != 0) { if (max_pct != 0) {
@@ -501,7 +503,13 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size
assert(mapInfo.count(vRandom[n]) == 1); assert(mapInfo.count(vRandom[n]) == 1);
const CAddrInfo& ai = mapInfo[vRandom[n]]; const CAddrInfo& ai = mapInfo[vRandom[n]];
if (!ai.IsTerrible())
// Filter by network (optional)
if (network != std::nullopt && ai.GetNetClass() != network) continue;
// Filter for quality
if (ai.IsTerrible()) continue;
vAddr.push_back(ai); vAddr.push_back(ai);
} }
} }

View File

@@ -20,6 +20,7 @@
#include <hash.h> #include <hash.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <optional>
#include <set> #include <set>
#include <stdint.h> #include <stdint.h>
#include <streams.h> #include <streams.h>
@@ -278,8 +279,15 @@ protected:
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs); int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs);
#endif #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, std::optional<Network> network = std::nullopt) EXCLUSIVE_LOCKS_REQUIRED(cs);
/** We have successfully connected to this peer. Calling this function /** We have successfully connected to this peer. Calling this function
* updates the CAddress's nTime, which is used in our IsTerrible() * updates the CAddress's nTime, which is used in our IsTerrible()