http_tunnel_common/
constants.rs

1/// Maximum connection lifetime before requiring reconnection (2 hours)
2pub const MAX_CONNECTION_LIFETIME_SECS: i64 = 7200;
3
4/// DynamoDB TTL buffer for cleanup of old connections (2 hours)
5pub const CONNECTION_TTL_SECS: i64 = 7200;
6
7/// Heartbeat interval to keep WebSocket connection alive (5 minutes)
8pub const HEARTBEAT_INTERVAL_SECS: u64 = 300;
9
10/// API Gateway WebSocket idle timeout (10 minutes)
11pub const WEBSOCKET_IDLE_TIMEOUT_SECS: u64 = 600;
12
13/// Request timeout waiting for response from agent (under API Gateway's 29s limit)
14pub const REQUEST_TIMEOUT_SECS: u64 = 25;
15
16/// Pending request TTL in DynamoDB (30 seconds)
17pub const PENDING_REQUEST_TTL_SECS: i64 = 30;
18
19/// Maximum request/response body size (2 MB per API Gateway limit)
20pub const MAX_BODY_SIZE_BYTES: usize = 2 * 1024 * 1024;
21
22/// Minimum delay for exponential backoff reconnection (1 second)
23pub const RECONNECT_MIN_DELAY_MS: u64 = 1000;
24
25/// Maximum delay for exponential backoff reconnection (60 seconds)
26pub const RECONNECT_MAX_DELAY_MS: u64 = 60000;
27
28/// Multiplier for exponential backoff reconnection
29pub const RECONNECT_MULTIPLIER: f64 = 2.0;
30
31/// Initial polling interval when waiting for response (50ms)
32pub const POLL_INITIAL_INTERVAL_MS: u64 = 50;
33
34/// Maximum polling interval (500ms)
35pub const POLL_MAX_INTERVAL_MS: u64 = 500;
36
37/// Polling backoff multiplier
38pub const POLL_BACKOFF_MULTIPLIER: u32 = 2;
39
40/// Optimized polling: first check interval (200ms) - covers fast responses
41pub const OPTIMIZED_POLL_FIRST_INTERVAL_MS: u64 = 200;
42
43/// Optimized polling: second check interval (300ms) - cumulative 500ms
44pub const OPTIMIZED_POLL_SECOND_INTERVAL_MS: u64 = 300;
45
46/// Optimized polling: final polling interval (400ms) - for edge cases
47pub const OPTIMIZED_POLL_FINAL_INTERVAL_MS: u64 = 400;
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_constants_values() {
55        // These are compile-time checks for constant sanity
56        // Even though they're optimized out, they document constraints
57        const _: () = assert!(REQUEST_TIMEOUT_SECS < 29, "Must be under API Gateway limit");
58        const _: () = assert!(HEARTBEAT_INTERVAL_SECS < WEBSOCKET_IDLE_TIMEOUT_SECS);
59        const _: () = assert!(PENDING_REQUEST_TTL_SECS < MAX_CONNECTION_LIFETIME_SECS);
60        const _: () = assert!(RECONNECT_MIN_DELAY_MS < RECONNECT_MAX_DELAY_MS);
61        const _: () = assert!(RECONNECT_MULTIPLIER > 1.0);
62
63        // Verify size limits
64        assert_eq!(MAX_BODY_SIZE_BYTES, 2 * 1024 * 1024);
65    }
66}