aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorEthanHeilman <ethan.r.heilman@gmail.com>2015-09-22 15:24:16 -0400
committerEthanHeilman <ethan.r.heilman@gmail.com>2015-09-24 15:20:48 -0400
commit1534d9a83c3648709690f8ad6af752b782a35be7 (patch)
treee97554f6ee564182aa1c6e09af938c39f222b684 /src/addrman.cpp
parent8bc1b3a1f37b86014bca583f8e33a5dd75772019 (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.cpp8
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) {