aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@bitpay.com>2014-08-23 12:59:55 -0400
committerJeff Garzik <jgarzik@bitpay.com>2014-08-23 12:59:55 -0400
commit57fe1eaadc7c404b199239351e7bd80f48f3bcba (patch)
treef73da9dc4b87e28c848bebabce96dded48983b4c
parent92b3d3630d6d63305bec136a23c7be4cb2bb2652 (diff)
parent3a56de7fc318a45a7096cd318e2f2d7f8124ce24 (diff)
Merge pull request #4632
-rw-r--r--src/addrman.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 3628af2eab..704766dbf8 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -492,17 +492,23 @@ int CAddrMan::Check_()
void CAddrMan::GetAddr_(std::vector<CAddress> &vAddr)
{
- int nNodes = ADDRMAN_GETADDR_MAX_PCT*vRandom.size()/100;
+ unsigned int nNodes = ADDRMAN_GETADDR_MAX_PCT * vRandom.size() / 100;
if (nNodes > ADDRMAN_GETADDR_MAX)
nNodes = ADDRMAN_GETADDR_MAX;
- // perform a random shuffle over the first nNodes elements of vRandom (selecting from all)
- for (int n = 0; n<nNodes; n++)
+ // gather a list of random nodes, skipping those of low quality
+ for (unsigned int n = 0; n < vRandom.size(); n++)
{
+ if (vAddr.size() >= nNodes)
+ break;
+
int nRndPos = GetRandInt(vRandom.size() - n) + n;
SwapRandom(n, nRndPos);
assert(mapInfo.count(vRandom[n]) == 1);
- vAddr.push_back(mapInfo[vRandom[n]]);
+
+ const CAddrInfo& ai = mapInfo[vRandom[n]];
+ if (!ai.IsTerrible())
+ vAddr.push_back(ai);
}
}