Skip to content

Commit 7c2284e

Browse files
committed
test: add tests for inbound eviction protection of I2P peers
1 parent ce02dd1 commit 7c2284e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/test/net_peer_eviction_tests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
157157
/* unprotected_peer_ids */ {3, 4, 5, 6, 10, 11},
158158
random_context));
159159

160+
// Expect 1/4 I2P peers to be protected from eviction,
161+
// if no onion or localhost peers.
162+
BOOST_CHECK(IsProtected(
163+
num_peers, [](NodeEvictionCandidate& c) {
164+
c.m_is_local = false;
165+
c.m_network = (c.id == 2 || c.id == 7 || c.id == 10) ? NET_I2P : NET_IPV4;
166+
},
167+
/* protected_peer_ids */ {2, 7, 10},
168+
/* unprotected_peer_ids */ {},
169+
random_context));
170+
171+
// Expect 1/4 I2P peers and 1/4 of the other peers to be protected,
172+
// sorted by longest uptime (lowest nTimeConnected), if no onion or localhost peers.
173+
BOOST_CHECK(IsProtected(
174+
num_peers, [](NodeEvictionCandidate& c) {
175+
c.nTimeConnected = c.id;
176+
c.m_is_local = false;
177+
c.m_network = (c.id == 4 || c.id > 8) ? NET_I2P : NET_IPV6;
178+
},
179+
/* protected_peer_ids */ {0, 1, 2, 4, 9, 10},
180+
/* unprotected_peer_ids */ {3, 5, 6, 7, 8, 11},
181+
random_context));
182+
160183
// Tests with 2 networks...
161184

162185
// Combined test: expect having 1 localhost and 1 onion peer out of 4 to

0 commit comments

Comments
 (0)