@@ -158,6 +158,29 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
158
158
/* unprotected_peer_ids=*/ {3 , 5 , 6 , 7 , 8 , 11 },
159
159
random_context));
160
160
161
+ // Expect 1/4 CJDNS peers to be protected from eviction,
162
+ // if no onion, localhost, or I2P peers.
163
+ BOOST_CHECK (IsProtected (
164
+ num_peers, [](NodeEvictionCandidate& c) {
165
+ c.m_is_local = false ;
166
+ c.m_network = (c.id == 2 || c.id == 7 || c.id == 10 ) ? NET_CJDNS : NET_IPV4;
167
+ },
168
+ /* protected_peer_ids=*/ {2 , 7 , 10 },
169
+ /* unprotected_peer_ids=*/ {},
170
+ random_context));
171
+
172
+ // Expect 1/4 CJDNS peers and 1/4 of the other peers to be protected, sorted
173
+ // by longest uptime (lowest m_connected), if no onion, localhost, or I2P peers.
174
+ BOOST_CHECK (IsProtected (
175
+ num_peers, [](NodeEvictionCandidate& c) {
176
+ c.m_connected = std::chrono::seconds{c.id };
177
+ c.m_is_local = false ;
178
+ c.m_network = (c.id == 4 || c.id > 8 ) ? NET_CJDNS : NET_IPV6;
179
+ },
180
+ /* protected_peer_ids=*/ {0 , 1 , 2 , 4 , 9 , 10 },
181
+ /* unprotected_peer_ids=*/ {3 , 5 , 6 , 7 , 8 , 11 },
182
+ random_context));
183
+
161
184
// Tests with 2 networks...
162
185
163
186
// Combined test: expect having 1 localhost and 1 onion peer out of 4 to
@@ -416,15 +439,15 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
416
439
/* unprotected_peer_ids=*/ {6 , 7 , 8 , 9 , 10 , 11 , 16 , 19 , 20 , 21 , 22 , 23 },
417
440
random_context));
418
441
419
- // Combined test: expect having 8 localhost, 4 I2P , and 3 onion peers out of
420
- // 24 to protect 2 of each (6 total), plus 6 others for 12/24 total, sorted
421
- // by longest uptime.
442
+ // Combined test: expect having 8 localhost, 4 CJDNS , and 3 onion peers out
443
+ // of 24 to protect 2 of each (6 total), plus 6 others for 12/24 total,
444
+ // sorted by longest uptime.
422
445
BOOST_CHECK (IsProtected (
423
446
24 , [](NodeEvictionCandidate& c) {
424
447
c.m_connected = std::chrono::seconds{c.id };
425
448
c.m_is_local = (c.id > 15 );
426
449
if (c.id > 10 && c.id < 15 ) {
427
- c.m_network = NET_I2P ;
450
+ c.m_network = NET_CJDNS ;
428
451
} else if (c.id > 6 && c.id < 10 ) {
429
452
c.m_network = NET_ONION;
430
453
} else {
0 commit comments