pako_tools/
flow.rs

1use std::hash::{Hash, Hasher};
2
3use crate::{five_tuple::FiveTuple, Duration};
4
5/// Unique `Flow` identifier
6#[allow(clippy::upper_case_acronyms)]
7pub type FlowID = u64;
8
9/// Network flow information
10#[derive(Clone, PartialEq, Eq, Default, Debug)]
11pub struct Flow {
12    /// The `Flow` identifier
13    pub flow_id: FlowID,
14    /// The `FiveTuple` identifying the `Flow`
15    pub five_tuple: FiveTuple,
16    /// timestamp of first packet
17    pub first_seen: Duration,
18    /// timestamp of last seen packet
19    pub last_seen: Duration,
20}
21
22impl Flow {
23    pub fn new(five_tuple: &FiveTuple, ts_sec: u32, ts_usec: u32) -> Self {
24        let d = Duration::new(ts_sec, ts_usec);
25        Flow {
26            flow_id: 0,
27            five_tuple: five_tuple.clone(),
28            first_seen: d,
29            last_seen: d,
30        }
31    }
32}
33
34#[allow(clippy::derive_hash_xor_eq)]
35impl Hash for Flow {
36    fn hash<H: Hasher>(&self, state: &mut H) {
37        // skip flow_id
38        self.five_tuple.hash(state);
39        self.first_seen.hash(state);
40        // skip last seen
41    }
42}