summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-08-20 20:21:07 +0800
committerluwenpeng <[email protected]>2023-08-20 20:21:07 +0800
commit3a6c7d587e6e8d7c3e7b70a93646c0e41a385220 (patch)
tree7939d44cd458e1ac23a4b7f31e528dcb9ca54913
parentc664b7effcbda542dcb2bcaa3c62eb5087246b84 (diff)
implement methods for manipulating the session current dir
-rw-r--r--src/session/session.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/session/session.rs b/src/session/session.rs
index 65da07c..8eb5dae 100644
--- a/src/session/session.rs
+++ b/src/session/session.rs
@@ -7,6 +7,12 @@ use std::collections::HashMap;
******************************************************************************/
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum SessionDirection {
+ C2S,
+ S2C,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SessionState {
New,
Active,
@@ -30,7 +36,6 @@ pub struct SessionMetrics {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-
struct SessionTimeStamp {
ts_start: i64,
ts_end: i64,
@@ -38,6 +43,12 @@ struct SessionTimeStamp {
ts_last_seen: i64,
}
+/******************************************************************************
+ * why no current packet in session?
+ * - session lifetime is longer than packet lifetime
+ * - if current packet is iterm of session, require packet lifetime > session lifetime
+ ******************************************************************************/
+
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Session {
session_id: String,
@@ -46,6 +57,7 @@ pub struct Session {
session_five_tuple: FiveTuple,
session_timestamp: SessionTimeStamp,
session_exdata: HashMap<String, String>,
+ session_current_dir: SessionDirection,
}
/******************************************************************************
@@ -76,6 +88,7 @@ impl Session {
ts_last_seen: timestamp,
},
session_exdata: HashMap::new(),
+ session_current_dir: SessionDirection::C2S,
}
}
@@ -160,6 +173,14 @@ impl Session {
pub fn get_session_exdata(&self, key: String) -> Option<&String> {
self.session_exdata.get(&key)
}
+
+ pub fn set_session_current_dir(&mut self, dir: SessionDirection) {
+ self.session_current_dir = dir;
+ }
+
+ pub fn get_session_current_dir(&self) -> SessionDirection {
+ self.session_current_dir
+ }
}
/******************************************************************************
@@ -213,5 +234,9 @@ mod tests {
session.get_session_exdata("Hello".to_string()),
Some(&"Word".to_string())
);
+ assert_eq!(
+ session.get_session_current_dir(),
+ super::SessionDirection::C2S
+ );
}
}