aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorEthan Heilman <ethan@geographicslab.org>2016-10-27 13:55:39 -0400
committere0 <ethan.r.heilman@gmail.com>2018-03-06 11:21:01 -0500
commite68172ed9fd0e35d4e848142e9b36ffcc41de254 (patch)
treed7ce5da09cf039698d7e914e1144d304367f2d9a /src/net.cpp
parentbf3353de90598f08a68d966c50b57ceaeb5b5d96 (diff)
Add test-before-evict discipline to addrman
Changes addrman to use the test-before-evict discipline in which an address is to be evicted from the tried table is first tested and if it is still online it is not evicted. Adds tests to provide test coverage for this change. This change was suggested as Countermeasure 3 in Eclipse Attacks on Bitcoin’s Peer-to-Peer Network, Ethan Heilman, Alison Kendler, Aviv Zohar, Sharon Goldberg. ePrint Archive Report 2015/263. March 2015.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 201914685c..e08ce0fd33 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1824,11 +1824,18 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
}
}
+ addrman.ResolveCollisions();
+
int64_t nANow = GetAdjustedTime();
int nTries = 0;
while (!interruptNet)
{
- CAddrInfo addr = addrman.Select(fFeeler);
+ CAddrInfo addr = addrman.SelectTriedCollision();
+
+ // SelectTriedCollision returns an invalid address if it is empty.
+ if (!fFeeler || !addr.IsValid()) {
+ addr = addrman.Select(fFeeler);
+ }
// if we selected an invalid address, restart
if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr))