@@ -157,6 +157,29 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
157
157
/* unprotected_peer_ids */ {3 , 4 , 5 , 6 , 10 , 11 },
158
158
random_context));
159
159
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
+
160
183
// Tests with 2 networks...
161
184
162
185
// Combined test: expect having 1 localhost and 1 onion peer out of 4 to
0 commit comments