use super::*;
#[derive(Clone, Data, Debug)]
pub struct StoredIdempotentResponse {
#[get(type(copy))]
pub(crate) status_code: usize,
pub(crate) headers: Vec<(String, String)>,
pub(crate) body: Vec<u8>,
pub(crate) replayed_wire: Vec<u8>,
#[get(type(copy))]
pub(crate) stored_at_ms: u64,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct IdempotencyConfig {
pub(crate) header_name: String,
#[get(type(copy))]
pub(crate) ttl_ms: u64,
#[get(type(copy))]
pub(crate) in_flight_ttl_ms: u64,
#[get(type(copy))]
pub(crate) max_entries: usize,
#[get(type(copy))]
pub(crate) max_bytes: usize,
#[get(type(copy))]
pub(crate) max_body_bytes: usize,
#[get(type(copy))]
pub(crate) max_key_len: usize,
pub(crate) methods: Vec<Method>,
pub(crate) require_key_prefixes: Vec<String>,
#[get(type(copy))]
pub(crate) cache_server_errors: bool,
}
#[derive(Clone)]
pub(crate) struct IdempotencySlot {
pub(crate) fingerprint: u64,
pub(crate) state: IdempotencySlotState,
pub(crate) expires_at_ms: u64,
pub(crate) footprint_bytes: usize,
}
#[repr(align(64))]
pub(crate) struct IdempotencyShard {
pub(crate) map: RwLock<HashMapXxHash3_64<String, IdempotencySlot>>,
}
pub(crate) struct InMemoryIdempotencyStoreInner {
pub(crate) max_entries: usize,
pub(crate) max_bytes: usize,
pub(crate) entry_count: AtomicUsize,
pub(crate) total_bytes: AtomicUsize,
pub(crate) shards: Box<[IdempotencyShard; IDEMPOTENCY_SHARD_COUNT]>,
}
#[derive(Clone)]
pub struct InMemoryIdempotencyStore {
pub(crate) inner: Arc<InMemoryIdempotencyStoreInner>,
}
pub(crate) struct IdempotencyInFlightGuardInner {
pub(crate) settled: AtomicBool,
pub(crate) storage_key: String,
pub(crate) fingerprint: u64,
pub(crate) store: Arc<dyn IdempotencyStore>,
}
#[derive(Clone)]
pub struct IdempotencyInFlightGuard {
pub(crate) inner: Arc<IdempotencyInFlightGuardInner>,
}
#[derive(Clone)]
pub struct IdempotencyPlugin {
pub(crate) config: IdempotencyConfig,
pub(crate) guarded_method_mask: u16,
pub(crate) has_unknown_method: bool,
pub(crate) require_prefixes: Box<[String]>,
pub(crate) store: Arc<dyn IdempotencyStore>,
pub(crate) local_store: Option<InMemoryIdempotencyStore>,
pub(crate) prebuilt_bad_key_wire: Vec<u8>,
pub(crate) prebuilt_in_flight_wire: Vec<u8>,
pub(crate) prebuilt_mismatch_wire: Vec<u8>,
}
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-78)]
pub struct IdempotencyRequestHook;
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::response_middleware(-60)]
pub struct IdempotencyResponseHook;