Creates unittests for addrman, makes addrman testable.

Adds several unittests for addrman to verify it works as expected.
Makes small modifications to addrman to allow deterministic and targeted tests.

Signed-off-by: Simon <simon@bitcartel.com>
This commit is contained in:
EthanHeilman
2015-09-22 15:24:16 -04:00
committed by Simon
parent b0f75847ea
commit 8375e1a3e7
4 changed files with 199 additions and 6 deletions

View File

@@ -331,7 +331,7 @@ void CAddrMan::Attempt_(const CService& addr, int64_t nTime)
info.nAttempts++;
}
CAddrInfo CAddrMan::Select_()
CAddrInfo CAddrMan::Select_(bool newOnly)
{
if (size() == 0)
return CAddrInfo();
@@ -339,8 +339,12 @@ CAddrInfo CAddrMan::Select_()
// Track number of attempts to find a table entry, before giving up
int nRetries = 0;
if (newOnly && nNew == 0)
return CAddrInfo();
// Use a 50% chance for choosing between tried and new table entries.
if (nTried > 0 && (nNew == 0 || GetRandInt(2) == 0)) {
if (!newOnly &&
(nTried > 0 && (nNew == 0 || GetRandInt(2) == 0))) {
// use a tried node
double fChanceFactor = 1.0;
while (nRetries++ < ADDRMAN_TRIED_BUCKET_COUNT) {