diff options
author | EthanHeilman <ethan.r.heilman@gmail.com> | 2015-09-22 15:24:16 -0400 |
---|---|---|
committer | EthanHeilman <ethan.r.heilman@gmail.com> | 2015-09-24 15:20:48 -0400 |
commit | 1534d9a83c3648709690f8ad6af752b782a35be7 (patch) | |
tree | e97554f6ee564182aa1c6e09af938c39f222b684 /src/addrman.cpp | |
parent | 8bc1b3a1f37b86014bca583f8e33a5dd75772019 (diff) |
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.
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r-- | src/addrman.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index ff1f7e9187..078b9e1681 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -329,13 +329,17 @@ void CAddrMan::Attempt_(const CService& addr, int64_t nTime) info.nAttempts++; } -CAddrInfo CAddrMan::Select_() +CAddrInfo CAddrMan::Select_(bool newOnly) { if (size() == 0) return CAddrInfo(); + 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 (1) { |