# Examples
Runnable demos for the Shadow Network library. Each file focuses on a
different subsystem or phase of the project.
## Running
```bash
cargo run --example basic_encryption
cargo run --example dht_demo
cargo run --example stego_demo
cargo run --example phase2_demo
cargo run --example phase3_demo
cargo run --example phase4_demo
cargo run --example system_overview
cargo run --example simple_demo
```
Add `--release` for optimized builds.
## What each example does
### basic_encryption
Core cryptographic operations: keypair generation, X25519 key exchange,
ChaCha20-Poly1305 encryption/decryption, Ed25519 signing and verification.
### dht_demo
Creates two nodes, bootstraps them, stores and retrieves values from the
Kademlia DHT, and shows node statistics.
### stego_demo
Hides a secret message inside an image using LSB steganography, extracts it,
and tests different embedding configurations (bit depth, randomization).
### phase2_demo
End-to-end demo of Phase 2 features: libp2p transport configuration, DHT
replication with peer-loss recovery, encrypted messaging with offline queues
and group chat, and steganographic packet pipelines.
### phase3_demo
Production hardening: benchmarking with profiler, monitoring (metrics, health
checks, alerting), security audit (crypto audit, fuzzing, timing analysis),
integration tests, and load testing with a 10,000-peer virtual swarm.
### phase4_demo
Advanced anonymity: onion routing through multi-hop circuits, traffic analysis
resistance (constant-rate shaping, mix networks, fingerprint detection),
pluggable transports (obfs, domain fronting, bridge relays), reputation
scoring with Sybil defense, and adversary/censorship simulation.
### system_overview
Prints a summary of every module and its capabilities.
### simple_demo
Quick reference: lists available commands and shows minimal code snippets for
each subsystem.
## Writing your own
Use any of these as a starting point. The typical pattern is:
```rust
use client::{ShadowNodeBuilder, ShadowApi};
use crypto::Keypair;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let node = ShadowNodeBuilder::new()
.with_keypair(Keypair::generate())
.build()?;
let mut api = ShadowApi::new(node);
api.start().await?;
// ... your logic here ...
api.stop().await?;
Ok(())
}
```
See the `shadow-client` crate for the full high-level API.