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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user