ant_quic/bootstrap_cache/mod.rs
1//! Greedy Bootstrap Cache
2//!
3//! Provides persistent peer caching with quality-based selection for network bootstrap.
4//!
5//! ## Features
6//!
7//! - **Large capacity**: 10,000-30,000 peer entries (configurable)
8//! - **Quality scoring**: Success rate, RTT, age decay, capability bonuses
9//! - **Epsilon-greedy selection**: Balances exploitation vs exploration
10//! - **Multi-process safe**: Atomic writes with file locking (Unix)
11//! - **Background maintenance**: Periodic save, cleanup, and quality updates
12//!
13//! ## Example
14//!
15//! ```rust,ignore
16//! use ant_quic::bootstrap_cache::{BootstrapCache, BootstrapCacheConfig};
17//! use std::sync::Arc;
18//!
19//! #[tokio::main]
20//! async fn main() -> anyhow::Result<()> {
21//! let config = BootstrapCacheConfig::builder()
22//! .cache_dir("/var/lib/ant-quic")
23//! .max_peers(20_000)
24//! .epsilon(0.1)
25//! .build();
26//!
27//! let cache = Arc::new(BootstrapCache::open(config).await?);
28//!
29//! // Start background maintenance
30//! let _maintenance = cache.clone().start_maintenance();
31//!
32//! // Get peers for bootstrap (epsilon-greedy selection)
33//! let peers = cache.select_peers(50).await;
34//!
35//! // Record connection results
36//! for peer in &peers {
37//! // ... attempt connection ...
38//! cache.record_success(&peer.peer_id, 100).await; // or record_failure
39//! }
40//!
41//! // Save periodically (also done by maintenance task)
42//! cache.save().await?;
43//!
44//! Ok(())
45//! }
46//! ```
47
48mod cache;
49mod config;
50mod entry;
51mod persistence;
52mod selection;
53
54pub use cache::{BootstrapCache, CacheEvent, CacheStats};
55pub use config::{BootstrapCacheConfig, BootstrapCacheConfigBuilder, QualityWeights};
56pub use entry::{
57 CachedPeer, ConnectionOutcome, ConnectionStats, NatType, PeerCapabilities, PeerSource,
58};
59pub use selection::SelectionStrategy;