Expand description
Connection rate limiting for preventing connection storms and resource exhaustion.
This module provides sophisticated rate limiting capabilities to control the rate of connection establishment, preventing connection storms, respecting peer limits, and protecting against resource exhaustion.
§Features
- Token Bucket Algorithm: Classic token bucket with configurable rate and burst
- Per-Peer Limits: Individual rate limits for each peer
- Global Limits: System-wide connection rate limits
- Priority-based Limiting: Different limits for different priority levels
- Adaptive Rate Limiting: Adjust rates based on success/failure patterns
- Backpressure Support: Queue connections when rate limit is exceeded
§Example
use ipfrs_network::rate_limiter::{ConnectionRateLimiter, RateLimiterConfig};
use std::time::Duration;
// Create rate limiter allowing 10 connections per second with burst of 20
let mut limiter = ConnectionRateLimiter::new(RateLimiterConfig {
max_rate: 10.0,
burst_size: 20,
enable_per_peer_limits: true,
..Default::default()
});
// Check if connection is allowed
let peer_id = "QmExample".to_string();
if limiter.allow_connection(&peer_id).await {
println!("Connection allowed");
// Establish connection...
} else {
println!("Rate limit exceeded, queuing...");
}Structs§
- Connection
Rate Limiter - Connection rate limiter
- Rate
Limiter Config - Configuration for the connection rate limiter
- Rate
Limiter Stats - Statistics tracked by the rate limiter
Enums§
- Connection
Priority - Priority level for connections
- Rate
Limiter Error - Errors that can occur during rate limiting operations