use super::*;
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub struct RateLimitDecision {
#[get(type(copy))]
pub(crate) allowed: bool,
#[get(type(copy))]
pub(crate) limit: u64,
#[get(type(copy))]
pub(crate) remaining: u64,
#[get(type(copy))]
pub(crate) reset_after_secs: u64,
#[get(type(copy))]
pub(crate) retry_after_secs: u64,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct RateLimitPolicy {
#[get(type(copy))]
pub(crate) requests_per_window: u64,
#[get(type(copy))]
pub(crate) window_ms: u64,
#[get(type(copy))]
pub(crate) burst: u64,
#[get(type(copy))]
pub(crate) algorithm: RateLimitAlgorithm,
#[get(type(copy))]
pub(crate) max_keys: usize,
#[get(type(copy))]
pub(crate) include_headers: bool,
pub(crate) exempt_paths: Vec<String>,
}
pub(crate) struct BucketEntry {
pub(crate) primary: AtomicU64,
pub(crate) counter: AtomicU64,
pub(crate) last_seen_ns: AtomicU64,
}
pub(crate) struct ShardedRateLimiterInner {
pub(crate) policy: RateLimitPolicy,
pub(crate) epoch: Instant,
pub(crate) emission_interval_ns: u64,
pub(crate) burst_tolerance_ns: u64,
pub(crate) window_ns: u64,
pub(crate) key_count: AtomicUsize,
pub(crate) shards: RateLimitShardArray,
}
#[derive(Clone)]
pub struct ShardedRateLimiter {
pub(crate) inner: Arc<ShardedRateLimiterInner>,
}
#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
pub struct ClientIpKeyExtractor {
#[get(type(copy))]
pub(crate) trust_proxy_headers: bool,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct HeaderKeyExtractor {
pub(crate) header_name: String,
#[get(type(copy))]
pub(crate) fallback_to_ip: bool,
}
#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
pub struct PathAndIpKeyExtractor {
#[get(type(copy))]
pub(crate) trust_proxy_headers: bool,
}
pub(crate) struct StackFmtWriter<'a> {
pub(crate) buf: &'a mut [u8],
pub(crate) len: usize,
}
#[derive(Clone)]
pub struct RateLimitPlugin {
pub(crate) policy: RateLimitPolicy,
pub(crate) store: SharedRateLimitStore,
pub(crate) key_extractor: SharedKeyExtractor,
pub(crate) use_default_ip_fast_path: bool,
}
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-95)]
pub struct RateLimitHook;