1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/// Standard `RateLimit-Limit` response header name.
pub const HEADER_RATE_LIMIT_LIMIT: &str = "ratelimit-limit";
/// Standard `RateLimit-Remaining` response header name.
pub const HEADER_RATE_LIMIT_REMAINING: &str = "ratelimit-remaining";
/// Standard `RateLimit-Reset` response header name (seconds until window/burst reset).
pub const HEADER_RATE_LIMIT_RESET: &str = "ratelimit-reset";
/// Default maximum requests permitted per window.
pub const DEFAULT_RATE_LIMIT_REQUESTS: u64 = 100;
/// Default rate-limit window duration in milliseconds (60 seconds).
pub const DEFAULT_RATE_LIMIT_WINDOW_MS: u64 = 60_000;
/// Default burst capacity when not overridden.
pub const DEFAULT_RATE_LIMIT_BURST: u64 = 100;
/// Default maximum tracked distinct rate-limit keys across all shards.
pub const DEFAULT_RATE_LIMIT_MAX_KEYS: usize = 65_536;
/// Number of independent lock-striped shards (`64`, power of two).
pub const RATE_LIMIT_SHARD_COUNT: usize = 64;
/// Nanoseconds per millisecond conversion factor.
pub const NANOS_PER_MS: u64 = 1_000_000;
/// Nanoseconds per second conversion factor.
pub const NANOS_PER_SEC: u64 = 1_000_000_000;
/// Fallback key used when no peer address or forwarding header is available.
pub const FALLBACK_CLIENT_KEY: &str = "anonymous";
/// Maximum decimal digits needed to format any `u64` on the stack.
pub const U64_STACK_BUF_LEN: usize = 20;
/// Stack buffer capacity in bytes for formatting any IPv4 or IPv6 address without heap allocation.
pub const IP_STACK_BUF_LEN: usize = 64;
/// Maximum header name length lowercased on the stack before falling back to heap allocation.
pub const STACK_HEADER_NAME_LEN: usize = 64;
/// Separator character joining request path and client IP in composite rate-limit keys.
pub const KEY_PATH_IP_SEPARATOR: char = '|';
/// Comma delimiter separating addresses in `X-Forwarded-For` headers.
pub const XFF_COMMA_DELIMITER: char = ',';
/// Multiplicative 64-bit mixing constant for zero-allocation [`FxHasher`].
pub const FX_HASH_K: u64 = 0x517c_c1b7_2722_0a95;
/// ASCII zero digit byte.
pub const BYTE_ZERO: u8 = b'0';
/// ASCII dot byte used in IPv4 formatting.
pub const BYTE_DOT: u8 = b'.';
/// Two-digit ASCII decimal lookup pairs for `00..=99`.
pub const DEC_DIGITS_LUT: & = b"00010203040506070809\
10111213141516171819\
20212223242526272829\
30313233343536373839\
40414243444546474849\
50515253545556575859\
60616263646566676869\
70717273747576777879\
80818283848586878889\
90919293949596979899";
/// Bit shift separating the 32-bit window id from the 32-bit counter in packed fixed-window mode.
pub const FIXED_WIN_PACK_SHIFT: u32 = 32;
/// Bitmask extracting the 32-bit request count in packed fixed-window mode.
pub const FIXED_WIN_COUNT_MASK: u64 = 0xFFFF_FFFF;