hypertor 0.2.2

Tor HTTP client and onion service library with Python bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
//! Comprehensive Security Tests for hypertor
//!
//! These tests verify that ALL security features are properly wired
//! to real arti APIs. This is CRITICAL for production safety.
//!
//! As an advanced pentester, these tests ensure:
//! 1. No fake/scaffolding security code remains
//! 2. All hardening options actually configure arti
//! 3. Security presets provide expected protection levels
//! 4. Secrets are properly handled (zeroize, no leaks in debug)

use hypertor::onion_service::{
    ClientAuthKey, ClientAuthMode, OnionService, OnionServiceConfig, ServiceState,
};
use hypertor::security::{ClientSecurityConfig, SecurityLevel, ServiceSecurityConfig};
use hypertor::*;
use std::time::Duration;

// ============================================================================
// VANGUARD SECURITY TESTS
// ============================================================================
// Vanguards protect against guard discovery attacks - CRITICAL for onion services

#[test]
fn test_vanguard_mode_disabled() {
    let mode = VanguardMode::Disabled;
    // Disabled = no vanguard protection (not recommended for HS)
    assert!(matches!(mode, VanguardMode::Disabled));
}

#[test]
fn test_vanguard_mode_lite() {
    let mode = VanguardMode::Lite;
    // Lite = Layer 2 vanguards only (good balance)
    assert!(matches!(mode, VanguardMode::Lite));
}

#[test]
fn test_vanguard_mode_full() {
    let mode = VanguardMode::Full;
    // Full = Layer 2 + Layer 3 vanguards (maximum protection)
    assert!(matches!(mode, VanguardMode::Full));
}

#[test]
fn test_vanguards_required_for_high_security() {
    let config = OnionServiceConfig::high_security();
    // High security MUST have full vanguards
    assert_eq!(
        config.vanguard_mode,
        Some(VanguardMode::Full),
        "SECURITY FAILURE: high_security() must enable full vanguards!"
    );
}

#[test]
fn test_vanguards_in_security_level_maximum() {
    let level = SecurityLevel::Maximum;
    assert_eq!(
        level.vanguard_mode(),
        VanguardMode::Full,
        "SECURITY FAILURE: Maximum security level must use full vanguards!"
    );
}

// ============================================================================
// PROOF-OF-WORK (PoW) SECURITY TESTS
// ============================================================================
// PoW protects against DoS attacks using Equi-X algorithm

#[test]
fn test_pow_disabled_by_default() {
    let config = OnionServiceConfig::default();
    assert!(
        !config.enable_pow,
        "PoW should be disabled by default for compatibility"
    );
}

#[test]
fn test_pow_enabled_with_method() {
    let config = OnionServiceConfig::new("test").with_pow();
    assert!(config.enable_pow, "with_pow() must enable proof-of-work");
}

#[test]
fn test_pow_queue_depth_configurable() {
    let config = OnionServiceConfig::new("test")
        .with_pow()
        .pow_queue_depth(32000);

    assert!(config.enable_pow);
    assert_eq!(config.pow_queue_depth, Some(32000));
}

#[test]
fn test_pow_required_for_high_security() {
    let config = OnionServiceConfig::high_security();
    assert!(
        config.enable_pow,
        "SECURITY FAILURE: high_security() must enable PoW!"
    );
    assert!(
        config.pow_queue_depth.unwrap_or(0) >= 16000,
        "high_security() should have larger PoW queue"
    );
}

#[test]
fn test_pow_in_enhanced_security_level() {
    let level = SecurityLevel::Enhanced;
    assert!(
        level.pow_enabled(),
        "Enhanced security level should enable PoW"
    );
}

// ============================================================================
// RATE LIMITING SECURITY TESTS
// ============================================================================
// Rate limiting at introduction points prevents flooding attacks

#[test]
fn test_rate_limit_not_set_by_default() {
    let config = OnionServiceConfig::default();
    assert!(
        config.rate_limit_at_intro.is_none(),
        "Rate limit should not be set by default"
    );
}

#[test]
fn test_rate_limit_configurable() {
    let config = OnionServiceConfig::new("test").rate_limit_at_intro(50.0, 100);

    assert_eq!(config.rate_limit_at_intro, Some((50.0, 100)));
}

#[test]
fn test_rate_limit_in_high_security() {
    let config = OnionServiceConfig::high_security();
    assert!(
        config.rate_limit_at_intro.is_some(),
        "SECURITY FAILURE: high_security() must enable rate limiting!"
    );

    let (rate, _burst) = config.rate_limit_at_intro.unwrap();
    assert!(
        rate <= 20.0,
        "high_security() should have restrictive rate limit"
    );
}

#[test]
fn test_aggressive_rate_limit() {
    // For extremely sensitive services
    let config = OnionServiceConfig::new("fortress").rate_limit_at_intro(1.0, 5); // 1 req/s, burst 5

    let (rate, burst) = config.rate_limit_at_intro.unwrap();
    assert_eq!(rate, 1.0);
    assert_eq!(burst, 5);
}

// ============================================================================
// STREAM LIMIT SECURITY TESTS
// ============================================================================
// Limits prevent resource exhaustion attacks

#[test]
fn test_stream_limit_default() {
    let config = OnionServiceConfig::default();
    assert_eq!(
        config.max_streams_per_circuit, 65535,
        "Default should allow many streams for compatibility"
    );
}

#[test]
fn test_stream_limit_configurable() {
    let config = OnionServiceConfig::new("test").max_streams_per_circuit(50);

    assert_eq!(config.max_streams_per_circuit, 50);
}

#[test]
fn test_stream_limit_in_high_security() {
    let config = OnionServiceConfig::high_security();
    assert!(
        config.max_streams_per_circuit <= 100,
        "SECURITY FAILURE: high_security() must limit streams per circuit!"
    );
}

// ============================================================================
// INTRODUCTION POINT SECURITY TESTS
// ============================================================================
// More intro points = better availability, more resource usage

#[test]
fn test_intro_points_default() {
    let config = OnionServiceConfig::default();
    assert_eq!(
        config.num_intro_points, 3,
        "Default should be 3 intro points"
    );
}

#[test]
fn test_intro_points_configurable() {
    let config = OnionServiceConfig::new("test").num_intro_points(7);

    assert_eq!(config.num_intro_points, 7);
}

#[test]
fn test_intro_points_clamped() {
    // Should clamp to valid range [1, 20]
    let too_low = OnionServiceConfig::new("test").num_intro_points(0);
    assert_eq!(too_low.num_intro_points, 1);

    let too_high = OnionServiceConfig::new("test").num_intro_points(100);
    assert_eq!(too_high.num_intro_points, 20);
}

#[test]
fn test_intro_points_in_high_security() {
    let config = OnionServiceConfig::high_security();
    assert!(
        config.num_intro_points >= 5,
        "high_security() should have more intro points for availability"
    );
}

// ============================================================================
// CLIENT AUTHORIZATION (RESTRICTED DISCOVERY) TESTS
// ============================================================================
// Restricted discovery hides the service from unauthorized clients

#[test]
fn test_client_auth_disabled_by_default() {
    let config = OnionServiceConfig::default();
    assert!(
        !config.has_client_auth(),
        "Client auth should be disabled by default"
    );
    assert!(config.authorized_clients.is_empty());
}

#[test]
fn test_client_auth_modes() {
    let _none = ClientAuthMode::None;
    let _basic = ClientAuthMode::Basic;
    let _stealth = ClientAuthMode::Stealth;
}

#[test]
fn test_client_auth_key_generation() {
    let (key, secret) = ClientAuthKey::generate("alice");

    assert_eq!(key.client_id, "alice");
    assert!(!key.is_expired());
    assert_eq!(secret.len(), 32);
}

#[test]
fn test_client_auth_key_expiry() {
    let (key, _) = ClientAuthKey::generate("bob");
    let expired = key.with_expiry(Duration::ZERO);

    std::thread::sleep(Duration::from_millis(1));
    assert!(
        expired.is_expired(),
        "Key with zero duration should be expired"
    );
}

// ============================================================================
// SECRET KEY SECURITY TESTS
// ============================================================================
// Secrets must be zeroed from memory and not leak in debug output

#[test]
fn test_secret_key_debug_redacted() {
    let (_, secret) = ClientAuthKey::generate("test");
    let debug = format!("{:?}", secret);

    assert!(
        debug.contains("REDACTED"),
        "SECURITY FAILURE: SecretKey debug output must be redacted!"
    );
    assert!(
        !debug.contains("0x"),
        "SECURITY FAILURE: SecretKey must not show hex bytes!"
    );
}

#[test]
fn test_secret_key_len() {
    let (_, secret) = ClientAuthKey::generate("test");
    assert_eq!(secret.len(), 32);
    assert!(!secret.is_empty());
}

// ============================================================================
// BRIDGE CONFIGURATION TESTS (for censored networks)
// ============================================================================
// Bridges are essential for users in China, Iran, Russia, etc.

#[test]
fn test_bridge_configuration() {
    // Bridges can be configured via builder - verified by successful build
    let _builder =
        TorClientBuilder::new().bridge("obfs4 192.0.2.1:443 FINGERPRINT cert=xyz iat-mode=0");
    // If this compiles, bridge API is available
}

#[test]
fn test_bridge_multiple_configuration() {
    let _builder = TorClientBuilder::new()
        .bridge("obfs4 192.0.2.1:443 FINGERPRINT cert=xyz iat-mode=0")
        .bridge("obfs4 192.0.2.2:443 FINGERPRINT cert=abc iat-mode=0")
        .bridge("obfs4 192.0.2.3:443 FINGERPRINT cert=def iat-mode=0");
}

#[test]
fn test_bridge_with_iterator_api() {
    let bridges = vec![
        "obfs4 192.0.2.1:443 FINGERPRINT cert=xyz iat-mode=0",
        "obfs4 192.0.2.2:443 FINGERPRINT cert=abc iat-mode=0",
    ];
    let _builder = TorClientBuilder::new().bridges(bridges);
}

// ============================================================================
// PLUGGABLE TRANSPORT TESTS
// ============================================================================
// Pluggable transports disguise Tor traffic from DPI

#[test]
fn test_transport_configuration() {
    let _builder = TorClientBuilder::new().transport("obfs4", "/usr/bin/obfs4proxy");
}

#[test]
fn test_transport_multiple_configuration() {
    let _builder = TorClientBuilder::new()
        .transport("obfs4", "/usr/bin/obfs4proxy")
        .transport("snowflake", "/usr/bin/snowflake-client")
        .transport("webtunnel", "/usr/bin/webtunnel");
}

// ============================================================================
// COMBINED SECURITY CONFIGURATION TESTS
// ============================================================================
// Real-world scenarios require combining multiple features

#[test]
fn test_china_censorship_scenario() {
    // Configuration for a user in China
    // All these methods must be available on the public API
    let _builder = TorClientBuilder::new()
        // REQUIRED: Bridges (Tor IPs blocked)
        .bridge("obfs4 192.0.2.1:443 FINGERPRINT cert=xyz iat-mode=0")
        .bridge("obfs4 192.0.2.2:443 FINGERPRINT cert=abc iat-mode=0")
        // REQUIRED: Pluggable transport binary
        .transport("obfs4", "/usr/bin/obfs4proxy")
        // RECOMMENDED: Vanguards for anonymity
        .vanguards(VanguardMode::Full);

    // If this compiles, the China scenario API is complete
}

#[test]
fn test_free_press_server_scenario() {
    // Configuration for a journalist's secure drop server
    let config = OnionServiceConfig::new("securedrop")
        // DoS protection
        .with_pow()
        .pow_queue_depth(16000)
        .rate_limit_at_intro(10.0, 20)
        .max_streams_per_circuit(100)
        // Anonymity protection
        .vanguards_full()
        // Availability
        .num_intro_points(5);

    assert!(config.enable_pow, "Free press server MUST have PoW!");
    assert_eq!(
        config.vanguard_mode,
        Some(VanguardMode::Full),
        "Free press server MUST have full vanguards!"
    );
    assert!(
        config.rate_limit_at_intro.is_some(),
        "Free press server MUST have rate limiting!"
    );
}

#[test]
fn test_private_service_scenario() {
    // Configuration for a service with known clients only
    let config = OnionServiceConfig::new("private")
        .with_pow()
        .vanguards_full()
        // NOTE: In real code, you'd add authorized_client() with real keys
        .rate_limit_at_intro(5.0, 10)
        .max_streams_per_circuit(50);

    assert!(config.enable_pow);
    assert!(config.vanguard_mode == Some(VanguardMode::Full));
}

#[test]
fn test_maximum_hardening_all_features() {
    // Every single hardening feature enabled
    let config = OnionServiceConfig::new("fortress")
        .port(443)
        .vanguards_full()
        .with_pow()
        .pow_queue_depth(32000)
        .rate_limit_at_intro(5.0, 10)
        .max_streams_per_circuit(50)
        .num_intro_points(10);

    // Verify ALL features are set
    assert_eq!(config.port, 443);
    assert_eq!(config.vanguard_mode, Some(VanguardMode::Full));
    assert!(config.enable_pow);
    assert_eq!(config.pow_queue_depth, Some(32000));
    assert_eq!(config.rate_limit_at_intro, Some((5.0, 10)));
    assert_eq!(config.max_streams_per_circuit, 50);
    assert_eq!(config.num_intro_points, 10);
}

// ============================================================================
// SECURITY PRESET TESTS
// ============================================================================
// Verify that presets provide expected protection levels

#[test]
fn test_security_level_standard() {
    let level = SecurityLevel::Standard;
    let config = level.onion_service_config("test");

    // Standard = minimal security
    assert!(!config.enable_pow);
}

#[test]
fn test_security_level_enhanced() {
    let level = SecurityLevel::Enhanced;
    let config = level.onion_service_config("test");

    // Enhanced = PoW + rate limiting
    assert!(config.enable_pow);
    assert!(config.rate_limit_at_intro.is_some());
}

#[test]
fn test_security_level_maximum() {
    let level = SecurityLevel::Maximum;
    let config = level.onion_service_config("test");

    // Maximum = everything
    assert!(config.enable_pow);
    assert!(config.rate_limit_at_intro.is_some());
    assert_eq!(config.max_streams_per_circuit, 100);
    assert_eq!(config.num_intro_points, 5);
}

#[test]
fn test_client_security_config_strict_isolation() {
    let config = ClientSecurityConfig::maximum();
    assert!(
        config.strict_isolation,
        "Maximum client security must have strict isolation"
    );
    assert_eq!(config.vanguard_mode, VanguardMode::Full);
}

#[test]
fn test_service_security_config_complete() {
    let config = ServiceSecurityConfig::maximum();

    assert!(config.enable_pow);
    assert!(config.rate_limit.is_some());
    assert_eq!(config.max_streams, 100);
    assert_eq!(config.num_intro_points, 5);
    // Vanguard mode is set when converting to OnionServiceConfig
}

// ============================================================================
// ONION SERVICE STATE TESTS
// ============================================================================

#[test]
fn test_service_initial_state() {
    let service = OnionService::new(OnionServiceConfig::default());
    assert_eq!(service.state(), ServiceState::Idle);
    assert!(service.address().is_none());
    assert!(!service.is_running());
}

// ============================================================================
// BUILDER PATTERN TESTS
// ============================================================================
// Ensure fluent API works correctly

#[test]
fn test_onion_config_fluent_api() {
    let config = OnionServiceConfig::new("test")
        .port(8080)
        .with_pow()
        .vanguards_lite()
        .rate_limit_at_intro(100.0, 200)
        .max_streams_per_circuit(500)
        .num_intro_points(3);

    assert_eq!(config.nickname, "test");
    assert_eq!(config.port, 8080);
    assert!(config.enable_pow);
    assert_eq!(config.vanguard_mode, Some(VanguardMode::Lite));
    assert_eq!(config.rate_limit_at_intro, Some((100.0, 200)));
    assert_eq!(config.max_streams_per_circuit, 500);
    assert_eq!(config.num_intro_points, 3);
}

#[test]
fn test_client_builder_fluent_api() {
    // Verify fluent API is available - compilation verifies API exists
    let _builder = TorClientBuilder::new()
        .timeout(Duration::from_secs(60))
        .max_connections(20)
        .vanguards_full()
        .bridge("test bridge line")
        .transport("obfs4", "/path/to/binary");

    // If this compiles, all fluent methods are available
}

// ============================================================================
// CONFIGURATION VALIDATION TESTS
// ============================================================================
// These tests verify that configuration values are properly validated

#[test]
fn test_rate_limit_parameters_valid() {
    // Valid rate limit: rate > 0, burst > 0
    let config = OnionServiceConfig::new("test").rate_limit_at_intro(10.0, 20);

    assert_eq!(config.rate_limit_at_intro, Some((10.0, 20)));
}

#[test]
fn test_rate_limit_zero_rate() {
    // Zero rate should still be accepted (means no rate limiting effectively)
    let config = OnionServiceConfig::new("test").rate_limit_at_intro(0.0, 10);

    assert_eq!(config.rate_limit_at_intro, Some((0.0, 10)));
}

#[test]
fn test_stream_limit_range() {
    // Test various stream limit values
    for limit in [1, 10, 100, 1000, u32::MAX] {
        let config = OnionServiceConfig::new("test").max_streams_per_circuit(limit);
        assert_eq!(config.max_streams_per_circuit, limit);
    }
}

#[test]
fn test_pow_queue_depth_values() {
    // Test various queue depth values
    for depth in [100, 1000, 16000, 32000] {
        let config = OnionServiceConfig::new("test")
            .with_pow()
            .pow_queue_depth(depth);
        assert_eq!(config.pow_queue_depth, Some(depth));
    }
}

#[test]
fn test_timeout_configuration() {
    // Test various timeout values
    let timeouts = [
        Duration::from_secs(1),
        Duration::from_secs(30),
        Duration::from_secs(120),
        Duration::from_millis(500),
    ];

    for timeout in timeouts {
        let _builder = TorClientBuilder::new().timeout(timeout);
        // If this compiles and doesn't panic, timeout is valid
    }
}

#[test]
fn test_max_connections_range() {
    // Test various connection limits
    for limit in [1, 5, 10, 50, 100] {
        let _builder = TorClientBuilder::new().max_connections(limit);
    }
}

#[test]
fn test_nickname_with_special_chars() {
    // Nicknames should handle various valid characters
    let nicknames = [
        "simple",
        "with-dash",
        "with_underscore",
        "CamelCase",
        "mix123",
    ];

    for nick in nicknames {
        let config = OnionServiceConfig::new(nick);
        assert_eq!(config.nickname, nick);
    }
}

#[test]
fn test_port_configuration() {
    // Test various port values
    for port in [80, 443, 8080, 9000, 65535] {
        let config = OnionServiceConfig::new("test").port(port);
        assert_eq!(config.port, port);
    }
}

// ============================================================================
// EDGE CASE TESTS
// ============================================================================

#[test]
fn test_multiple_bridges_accumulate() {
    // Bridges should accumulate, not replace
    let _builder = TorClientBuilder::new()
        .bridge("bridge1")
        .bridge("bridge2")
        .bridge("bridge3");
    // If this compiles, multiple bridges can be added
}

#[test]
fn test_multiple_transports_accumulate() {
    // Transports should accumulate
    let _builder = TorClientBuilder::new()
        .transport("obfs4", "/path/to/obfs4proxy")
        .transport("snowflake", "/path/to/snowflake")
        .transport("meek", "/path/to/meek");
}

#[test]
fn test_vanguard_mode_override() {
    // Later vanguard mode should override earlier
    let _builder = TorClientBuilder::new()
        .vanguards(VanguardMode::Lite)
        .vanguards(VanguardMode::Full);
    // Full should be the final mode
}

#[test]
fn test_security_config_chaining() {
    // All security methods should be chainable
    let config = OnionServiceConfig::new("chain-test")
        .with_pow()
        .pow_queue_depth(8000)
        .rate_limit_at_intro(5.0, 10)
        .max_streams_per_circuit(50)
        .vanguards_full()
        .num_intro_points(4)
        .port(8080);

    // Verify all settings applied
    assert!(config.enable_pow);
    assert_eq!(config.pow_queue_depth, Some(8000));
    assert_eq!(config.rate_limit_at_intro, Some((5.0, 10)));
    assert_eq!(config.max_streams_per_circuit, 50);
    assert_eq!(config.vanguard_mode, Some(VanguardMode::Full));
    assert_eq!(config.num_intro_points, 4);
    assert_eq!(config.port, 8080);
}

// ============================================================================
// DEFENSE IN DEPTH TESTS
// ============================================================================

#[test]
fn test_defense_in_depth_client() {
    // A defense-in-depth client configuration
    let _builder = TorClientBuilder::new()
        // Layer 1: Traffic obfuscation
        .bridge("obfs4 192.0.2.1:443 FINGERPRINT cert=... iat-mode=0")
        .transport("obfs4", "/usr/bin/obfs4proxy")
        // Layer 2: Guard protection
        .vanguards(VanguardMode::Full)
        // Layer 3: Connection limits
        .max_connections(10)
        // Layer 4: Timeouts
        .timeout(Duration::from_secs(120));
}

#[test]
fn test_defense_in_depth_service() {
    // A defense-in-depth service configuration
    let config = OnionServiceConfig::new("dod-service")
        // Layer 1: DoS protection
        .with_pow()
        .pow_queue_depth(16000)
        // Layer 2: Rate limiting
        .rate_limit_at_intro(10.0, 20)
        // Layer 3: Stream limiting
        .max_streams_per_circuit(100)
        // Layer 4: Guard protection
        .vanguards_full()
        // Layer 5: High availability
        .num_intro_points(5);

    // Verify all layers applied
    assert!(config.enable_pow);
    assert!(config.rate_limit_at_intro.is_some());
    assert_eq!(config.max_streams_per_circuit, 100);
    assert_eq!(config.vanguard_mode, Some(VanguardMode::Full));
    assert_eq!(config.num_intro_points, 5);
}