Skip to main content

stackforge_core/flow/
config.rs

1use std::time::Duration;
2
3/// Configuration for the flow extraction engine.
4///
5/// Controls timeouts, buffer limits, and eviction thresholds for
6/// conversation tracking and TCP stream reassembly.
7#[derive(Debug, Clone)]
8pub struct FlowConfig {
9    /// Timeout for established TCP connections (default: 86400s / 24h).
10    pub tcp_established_timeout: Duration,
11    /// Timeout for half-open TCP connections (SYN sent, no ACK) (default: 5s).
12    pub tcp_half_open_timeout: Duration,
13    /// Timeout for TCP `TIME_WAIT` state (default: 120s).
14    pub tcp_time_wait_timeout: Duration,
15    /// Timeout for UDP pseudo-conversations (default: 120s).
16    pub udp_timeout: Duration,
17    /// Maximum reassembly buffer size per direction per flow (default: 16 MB).
18    pub max_reassembly_buffer: usize,
19    /// Maximum number of out-of-order fragments per direction (default: 100).
20    pub max_ooo_fragments: usize,
21    /// Interval between idle conversation eviction sweeps (default: 30s).
22    pub eviction_interval: Duration,
23    /// Track maximum packet length per direction (default: false).
24    pub track_max_packet_len: bool,
25    /// Track maximum flow length per direction (default: false).
26    pub track_max_flow_len: bool,
27}
28
29impl Default for FlowConfig {
30    fn default() -> Self {
31        Self {
32            tcp_established_timeout: Duration::from_secs(86_400),
33            tcp_half_open_timeout: Duration::from_secs(5),
34            tcp_time_wait_timeout: Duration::from_secs(120),
35            udp_timeout: Duration::from_secs(120),
36            max_reassembly_buffer: 16 * 1024 * 1024, // 16 MB
37            max_ooo_fragments: 100,
38            eviction_interval: Duration::from_secs(30),
39            track_max_packet_len: false,
40            track_max_flow_len: false,
41        }
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_default_config() {
51        let config = FlowConfig::default();
52        assert_eq!(config.tcp_established_timeout, Duration::from_secs(86_400));
53        assert_eq!(config.tcp_half_open_timeout, Duration::from_secs(5));
54        assert_eq!(config.tcp_time_wait_timeout, Duration::from_secs(120));
55        assert_eq!(config.udp_timeout, Duration::from_secs(120));
56        assert_eq!(config.max_reassembly_buffer, 16 * 1024 * 1024);
57        assert_eq!(config.max_ooo_fragments, 100);
58        assert_eq!(config.eviction_interval, Duration::from_secs(30));
59        assert!(!config.track_max_packet_len);
60        assert!(!config.track_max_flow_len);
61    }
62}