@@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
112
112
// Test protection of onion, localhost, and I2P peers...
113
113
114
114
// Expect 1/4 onion peers to be protected from eviction,
115
- // if no localhost or I2P peers.
115
+ // if no localhost, I2P, or CJDNS peers.
116
116
BOOST_CHECK (IsProtected (
117
117
num_peers, [](NodeEvictionCandidate& c) {
118
118
c.m_is_local = false ;
@@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
123
123
random_context));
124
124
125
125
// Expect 1/4 onion peers and 1/4 of the other peers to be protected,
126
- // sorted by longest uptime (lowest nTimeConnected), if no localhost or I2P peers.
126
+ // sorted by longest uptime (lowest nTimeConnected), if no localhost, I2P or CJDNS peers.
127
127
BOOST_CHECK (IsProtected (
128
128
num_peers, [](NodeEvictionCandidate& c) {
129
129
c.nTimeConnected = c.id ;
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
135
135
random_context));
136
136
137
137
// Expect 1/4 localhost peers to be protected from eviction,
138
- // if no onion or I2P peers.
138
+ // if no onion, I2P, or CJDNS peers.
139
139
BOOST_CHECK (IsProtected (
140
140
num_peers, [](NodeEvictionCandidate& c) {
141
141
c.m_is_local = (c.id == 1 || c.id == 9 || c.id == 11 );
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
146
146
random_context));
147
147
148
148
// Expect 1/4 localhost peers and 1/4 of the other peers to be protected,
149
- // sorted by longest uptime (lowest nTimeConnected), if no onion or I2P peers.
149
+ // sorted by longest uptime (lowest nTimeConnected), if no onion, I2P, or CJDNS peers.
150
150
BOOST_CHECK (IsProtected (
151
151
num_peers, [](NodeEvictionCandidate& c) {
152
152
c.nTimeConnected = c.id ;
@@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
158
158
random_context));
159
159
160
160
// Expect 1/4 I2P peers to be protected from eviction,
161
- // if no onion or localhost peers.
161
+ // if no onion, localhost, or CJDNS peers.
162
162
BOOST_CHECK (IsProtected (
163
163
num_peers, [](NodeEvictionCandidate& c) {
164
164
c.m_is_local = false ;
@@ -168,8 +168,8 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
168
168
/* unprotected_peer_ids */ {},
169
169
random_context));
170
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.
171
+ // Expect 1/4 I2P peers and 1/4 of the other peers to be protected, sorted
172
+ // by longest uptime (lowest nTimeConnected), if no onion, localhost, or CJDNS peers.
173
173
BOOST_CHECK (IsProtected (
174
174
num_peers, [](NodeEvictionCandidate& c) {
175
175
c.nTimeConnected = c.id ;
@@ -180,6 +180,29 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
180
180
/* unprotected_peer_ids */ {3 , 5 , 6 , 7 , 8 , 11 },
181
181
random_context));
182
182
183
+ // Expect 1/4 CJDNS peers to be protected from eviction,
184
+ // if no onion, localhost, or I2P peers.
185
+ BOOST_CHECK (IsProtected (
186
+ num_peers, [](NodeEvictionCandidate& c) {
187
+ c.m_is_local = false ;
188
+ c.m_network = (c.id == 2 || c.id == 7 || c.id == 10 ) ? NET_CJDNS : NET_IPV4;
189
+ },
190
+ /* protected_peer_ids=*/ {2 , 7 , 10 },
191
+ /* unprotected_peer_ids=*/ {},
192
+ random_context));
193
+
194
+ // Expect 1/4 CJDNS peers and 1/4 of the other peers to be protected, sorted
195
+ // by longest uptime (lowest nTimeConnected), if no onion, localhost, or I2P peers.
196
+ BOOST_CHECK (IsProtected (
197
+ num_peers, [](NodeEvictionCandidate& c) {
198
+ c.nTimeConnected = c.id ;
199
+ c.m_is_local = false ;
200
+ c.m_network = (c.id == 4 || c.id > 8 ) ? NET_CJDNS : NET_IPV6;
201
+ },
202
+ /* protected_peer_ids=*/ {0 , 1 , 2 , 4 , 9 , 10 },
203
+ /* unprotected_peer_ids=*/ {3 , 5 , 6 , 7 , 8 , 11 },
204
+ random_context));
205
+
183
206
// Tests with 2 networks...
184
207
185
208
// Combined test: expect having 1 localhost and 1 onion peer out of 4 to
@@ -311,16 +334,16 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
311
334
BOOST_CHECK (IsProtected (
312
335
4 , [](NodeEvictionCandidate& c) {
313
336
c.nTimeConnected = c.id ;
314
- c.m_is_local = (c.id == 3 );
315
- if (c.id == 4 ) {
337
+ c.m_is_local = (c.id == 2 );
338
+ if (c.id == 3 ) {
316
339
c.m_network = NET_I2P;
317
- } else if (c.id == 2 ) {
340
+ } else if (c.id == 1 ) {
318
341
c.m_network = NET_ONION;
319
342
} else {
320
343
c.m_network = NET_IPV6;
321
344
}
322
345
},
323
- /* protected_peer_ids */ {0 , 4 },
346
+ /* protected_peer_ids */ {0 , 3 },
324
347
/* unprotected_peer_ids */ {1 , 2 },
325
348
random_context));
326
349
@@ -438,15 +461,15 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
438
461
/* unprotected_peer_ids */ {6 , 7 , 8 , 9 , 10 , 11 , 16 , 19 , 20 , 21 , 22 , 23 },
439
462
random_context));
440
463
441
- // Combined test: expect having 8 localhost, 4 I2P , and 3 onion peers out of
442
- // 24 to protect 2 of each (6 total), plus 6 others for 12/24 total, sorted
443
- // by longest uptime.
464
+ // Combined test: expect having 8 localhost, 4 CJDNS , and 3 onion peers out
465
+ // of 24 to protect 2 of each (6 total), plus 6 others for 12/24 total,
466
+ // sorted by longest uptime.
444
467
BOOST_CHECK (IsProtected (
445
468
24 , [](NodeEvictionCandidate& c) {
446
469
c.nTimeConnected = c.id ;
447
470
c.m_is_local = (c.id > 15 );
448
471
if (c.id > 10 && c.id < 15 ) {
449
- c.m_network = NET_I2P ;
472
+ c.m_network = NET_CJDNS ;
450
473
} else if (c.id > 6 && c.id < 10 ) {
451
474
c.m_network = NET_ONION;
452
475
} else {
@@ -456,6 +479,116 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
456
479
/* protected_peer_ids */ {0 , 1 , 2 , 3 , 4 , 5 , 7 , 8 , 11 , 12 , 16 , 17 },
457
480
/* unprotected_peer_ids */ {6 , 9 , 10 , 13 , 14 , 15 , 18 , 19 , 20 , 21 , 22 , 23 },
458
481
random_context));
482
+
483
+ // Tests with 4 networks...
484
+
485
+ // Combined test: expect having 1 CJDNS, 1 I2P, 1 localhost and 1 onion peer
486
+ // out of 5 to protect 1 CJDNS, 0 I2P, 0 localhost, 0 onion and 1 other peer
487
+ // (2 total), sorted by longest uptime; stable sort breaks tie with array
488
+ // order of CJDNS first.
489
+ BOOST_CHECK (IsProtected (
490
+ 5 , [](NodeEvictionCandidate& c) {
491
+ c.nTimeConnected = c.id ;
492
+ c.m_is_local = (c.id == 3 );
493
+ if (c.id == 4 ) {
494
+ c.m_network = NET_CJDNS;
495
+ } else if (c.id == 1 ) {
496
+ c.m_network = NET_I2P;
497
+ } else if (c.id == 2 ) {
498
+ c.m_network = NET_ONION;
499
+ } else {
500
+ c.m_network = NET_IPV6;
501
+ }
502
+ },
503
+ /* protected_peer_ids */ {0 , 4 },
504
+ /* unprotected_peer_ids */ {1 , 2 , 3 },
505
+ random_context));
506
+
507
+ // Combined test: expect having 1 CJDNS, 1 I2P, 1 localhost and 1 onion peer
508
+ // out of 7 to protect 1 CJDNS, 0, I2P, 0 localhost, 0 onion and 2 other
509
+ // peers (3 total) sorted by longest uptime; stable sort breaks tie with
510
+ // array order of CJDNS first.
511
+ BOOST_CHECK (IsProtected (
512
+ 7 , [](NodeEvictionCandidate& c) {
513
+ c.nTimeConnected = c.id ;
514
+ c.m_is_local = (c.id == 4 );
515
+ if (c.id == 6 ) {
516
+ c.m_network = NET_CJDNS;
517
+ } else if (c.id == 5 ) {
518
+ c.m_network = NET_I2P;
519
+ } else if (c.id == 3 ) {
520
+ c.m_network = NET_ONION;
521
+ } else {
522
+ c.m_network = NET_IPV4;
523
+ }
524
+ },
525
+ /* protected_peer_ids=*/ {0 , 1 , 6 },
526
+ /* unprotected_peer_ids=*/ {2 , 3 , 4 , 5 },
527
+ random_context));
528
+
529
+ // Combined test: expect having 1 CJDNS, 1 I2P, 1 localhost and 1 onion peer
530
+ // out of 8 to protect 1 CJDNS, 1 I2P, 0 localhost, 0 onion and 2 other
531
+ // peers (4 total) sorted by longest uptime; stable sort breaks tie with
532
+ // array order of CJDNS first.
533
+ BOOST_CHECK (IsProtected (
534
+ 8 , [](NodeEvictionCandidate& c) {
535
+ c.nTimeConnected = c.id ;
536
+ c.m_is_local = (c.id == 3 );
537
+ if (c.id == 5 ) {
538
+ c.m_network = NET_CJDNS;
539
+ } else if (c.id == 6 ) {
540
+ c.m_network = NET_I2P;
541
+ } else if (c.id == 3 ) {
542
+ c.m_network = NET_ONION;
543
+ } else {
544
+ c.m_network = NET_IPV6;
545
+ }
546
+ },
547
+ /* protected_peer_ids=*/ {0 , 1 , 5 , 6 },
548
+ /* unprotected_peer_ids=*/ {2 , 3 , 4 , 7 },
549
+ random_context));
550
+
551
+ // Combined test: expect having 2 CJDNS, 2 I2P, 4 localhost, and 2 onion
552
+ // peers out of 16 to protect 1 CJDNS, 1 I2P, 1 localhost, 1 onion (4/16
553
+ // total), plus 4 others for 8 total, sorted by longest uptime.
554
+ BOOST_CHECK (IsProtected (
555
+ 16 , [](NodeEvictionCandidate& c) {
556
+ c.nTimeConnected = c.id ;
557
+ c.m_is_local = (c.id > 5 );
558
+ if (c.id == 11 || c.id == 15 ) {
559
+ c.m_network = NET_CJDNS;
560
+ } else if (c.id == 10 || c.id == 14 ) {
561
+ c.m_network = NET_I2P;
562
+ } else if (c.id == 8 || c.id == 9 ) {
563
+ c.m_network = NET_ONION;
564
+ } else {
565
+ c.m_network = NET_IPV4;
566
+ }
567
+ },
568
+ /* protected_peer_ids=*/ {0 , 1 , 2 , 3 , 6 , 8 , 10 , 11 },
569
+ /* unprotected_peer_ids=*/ {4 , 5 , 7 , 9 , 12 , 13 , 14 , 15 },
570
+ random_context));
571
+
572
+ // Combined test: expect having 6 CJDNS, 1 I2P, 1 localhost, and 4 onion
573
+ // peers out of 24 to protect 2 CJDNS, 1 I2P, 1 localhost, and 2 onions (6
574
+ // total), plus 6 others for 12/24 total, sorted by longest uptime.
575
+ BOOST_CHECK (IsProtected (
576
+ 24 , [](NodeEvictionCandidate& c) {
577
+ c.nTimeConnected = c.id ;
578
+ c.m_is_local = (c.id == 13 );
579
+ if (c.id > 17 ) {
580
+ c.m_network = NET_CJDNS;
581
+ } else if (c.id == 17 ) {
582
+ c.m_network = NET_I2P;
583
+ } else if (c.id == 12 || c.id == 14 || c.id == 15 || c.id == 16 ) {
584
+ c.m_network = NET_ONION;
585
+ } else {
586
+ c.m_network = NET_IPV6;
587
+ }
588
+ },
589
+ /* protected_peer_ids=*/ {0 , 1 , 2 , 3 , 4 , 5 , 12 , 13 , 14 , 17 , 18 , 19 },
590
+ /* unprotected_peer_ids=*/ {6 , 7 , 8 , 9 , 10 , 11 , 15 , 16 , 20 , 21 , 22 , 23 },
591
+ random_context));
459
592
}
460
593
461
594
// Returns true if any of the node ids in node_ids are selected for eviction.
0 commit comments