aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-05-02 18:44:17 +0200
committerJon Atack <jon@atack.com>2021-05-19 13:04:07 +0200
commitd35ddca91ebbcf8d8b790c3b9f8cf218fafb7a53 (patch)
tree5264e3a68bbffed7b708b9c513bb91d6a31d53f9 /src/addrman.cpp
parent4da26fb85d6d6d205a2794ccb98beee1302b4a25 (diff)
p2p: enable CAddrMan::GetAddr_() by network, add doxygen
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f91121f156..ae2f1c23a2 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -7,9 +7,11 @@
#include <hash.h>
#include <logging.h>
+#include <netaddress.h>
#include <serialize.h>
#include <cmath>
+#include <optional>
int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
{
@@ -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, std::optional<Network> network)
{
size_t nNodes = vRandom.size();
if (max_pct != 0) {
@@ -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 != std::nullopt && ai.GetNetClass() != network) continue;
+
+ // Filter for quality
+ if (ai.IsTerrible()) continue;
+
+ vAddr.push_back(ai);
}
}