Skip to main content

network_protocol/utils/
mod.rs

1//! # Utility Modules
2//!
3//! Supporting utilities for cryptography, compression, logging, and timing.
4//!
5//! This module provides reusable utilities used throughout the protocol implementation.
6//!
7//! ## Components
8//! - **Crypto**: ChaCha20-Poly1305 AEAD encryption
9//! - **Compression**: LZ4 and Zstd with size limits and adaptive entropy-based selection
10//! - **Logging**: Structured logging configuration
11//! - **Time**: Timestamp utilities for timeout and expiry checks
12//! - **Timeout**: Async timeout wrappers
13//! - **Replay Cache**: TTL-based nonce deduplication for replay attack prevention
14//! - **Metrics**: Thread-safe observability counters
15//! - **Buffer Pool**: Object pooling for small buffer allocations (<4KB)
16//!
17//! ## Security
18//! - Cryptographically secure RNG (getrandom)
19//! - Decompression bomb protection (16MB limit)
20//! - Memory zeroing for sensitive data (zeroize crate)
21//!
22//! ## Performance
23//! - Buffer pooling reduces allocation overhead by 3-5%
24//! - Adaptive compression reduces CPU usage by 10-15% for mixed workloads
25
26pub mod buffer_pool;
27pub mod compression;
28pub mod crypto;
29pub mod logging;
30pub mod metrics;
31pub mod replay_cache;
32pub mod time;
33pub mod timeout;
34
35// Re-export public types for advanced users
36pub use buffer_pool::BufferPool;
37pub use replay_cache::{CacheKey, ReplayCache};