Expand description
Validation framework for input sanitization and rate limiting Comprehensive input validation framework for P2P Foundation
This module provides a robust validation system for all external inputs, including network messages, API parameters, file paths, and cryptographic parameters.
§Features
- Type-safe validation traits: Extensible validation system
- Rate limiting: Per-IP and global rate limiting with adaptive throttling
- Performance optimized: < 5% overhead for validation operations
- Security hardened: Protection against common attack vectors
- Comprehensive logging: All validation failures are logged
§Usage
use p2p_core::validation::{Validate, ValidationContext};
#[derive(Debug)]
struct NetworkMessage {
peer_id: String,
payload: Vec<u8>,
}
impl Validate for NetworkMessage {
fn validate(&self, ctx: &ValidationContext) -> Result<()> {
// Validate peer ID format
validate_peer_id(&self.peer_id)?;
// Validate payload size
validate_message_size(self.payload.len(), ctx.max_message_size)?;
Ok(())
}
}Structs§
- ApiRequest
- API request validation
- Network
Message - Network message validation
- Rate
Limit Config - Rate limit configuration
- Rate
Limiter - Rate limiter for preventing abuse (unified engine)
- Validation
Context - Context for validation operations
Enums§
- Validation
Error - Validation errors specific to input validation
Traits§
Functions§
- sanitize_
string - Sanitize a string for safe usage
- validate_
config_ value - Configuration value validation
- validate_
dht_ key - Validate DHT key
- validate_
dht_ value - Validate DHT value
- validate_
file_ path - Validate a file path for security
- validate_
key_ size - Validate key size for cryptographic operations
- validate_
message_ size - Validate message size
- validate_
network_ address - Validate a network address
- validate_
nonce_ size - Validate nonce size
- validate_
peer_ id - Validate a peer ID