From dc8979b382f9c28132aee32827da7e21f85ecf46 Mon Sep 17 00:00:00 2001 From: mamoniot Date: Sat, 25 Mar 2023 13:11:48 -0400 Subject: [PATCH] cleaned more --- zssp/src/zssp.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/zssp/src/zssp.rs b/zssp/src/zssp.rs index 465eb034c..bf100f649 100644 --- a/zssp/src/zssp.rs +++ b/zssp/src/zssp.rs @@ -40,11 +40,11 @@ const GCM_CIPHER_POOL_SIZE: usize = 4; pub struct Context<'a, Application: ApplicationLayer> { default_physical_mtu: AtomicUsize, dos_salt: RandomState, - defrag_has_pending: AtomicBool, // Allowed to be falsely positive + init_has_pending: AtomicBool, // Allowed to be falsely positive incoming_has_pending: AtomicBool, // Allowed to be falsely positive - defrag: Mutex<[(i64, u64, Fragged); MAX_INCOMPLETE_SESSION_QUEUE_SIZE]>, - active_sessions: RwLock>>>, + init_defrag: Mutex<[(i64, u64, Fragged); MAX_INCOMPLETE_SESSION_QUEUE_SIZE]>, incoming_sessions: RwLock<[(i64, u64, Option>>); MAX_INCOMPLETE_SESSION_QUEUE_SIZE]>, + active_sessions: RwLock>>>, } /// Result generated by the context packet receive function, with possible payloads. @@ -146,9 +146,9 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> { Self { default_physical_mtu: AtomicUsize::new(default_physical_mtu), dos_salt: RandomState::new(), - defrag_has_pending: AtomicBool::new(false), + init_has_pending: AtomicBool::new(false), incoming_has_pending: AtomicBool::new(false), - defrag: Mutex::new(std::array::from_fn(|_| (i64::MAX, 0, Fragged::new()))), + init_defrag: Mutex::new(std::array::from_fn(|_| (i64::MAX, 0, Fragged::new()))), active_sessions: RwLock::new(HashMap::with_capacity(64)), incoming_sessions: RwLock::new(std::array::from_fn(|_| (i64::MAX, 0, None))), } @@ -231,9 +231,9 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> { // Only check for expiration if we have a pending packet. // This check is allowed to have false positives for simplicity's sake. - if self.defrag_has_pending.swap(false, Ordering::Relaxed) { + if self.init_has_pending.swap(false, Ordering::Relaxed) { let mut has_pending = false; - for pending in &mut *self.defrag.lock().unwrap() { + for pending in &mut *self.init_defrag.lock().unwrap() { if pending.0 <= negotiation_timeout_cutoff { pending.0 = i64::MAX; pending.2.drop_in_place(); @@ -242,7 +242,7 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> { } } if has_pending { - self.defrag_has_pending.store(true, Ordering::Relaxed); + self.init_has_pending.store(true, Ordering::Relaxed); } } if self.incoming_has_pending.swap(false, Ordering::Relaxed) { @@ -561,7 +561,7 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> { hasher.write_u64(incoming_counter); let hashed_counter = hasher.finish(); - let mut defrag = self.defrag.lock().unwrap(); + let mut defrag = self.init_defrag.lock().unwrap(); let (idx, is_old) = lookup( &*defrag, hashed_counter, @@ -575,7 +575,7 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> { } else if !is_old { defrag[idx].0 = current_time; defrag[idx].1 = hashed_counter; - self.defrag_has_pending.store(true, Ordering::Relaxed); + self.init_has_pending.store(true, Ordering::Relaxed); } if let Some(assembled_packet) = &assembled { @@ -1767,7 +1767,7 @@ fn lookup(table: &[(i64, u64, T)], key: u64, expiry: i64) -> (usize, bool) { (idx0, true) } else if table[idx1].1 == key { (idx1, true) - } else if table[idx0].0 == i64::MAX || table[idx0].0 > table[idx1].0 || table[idx0].0 <= expiry { + } else if table[idx0].0 == i64::MAX || table[idx0].0 > table[idx1].0 || table[idx0].0 < expiry { // slot0 is either empty, expired, or the youngest of the two slots so use it. (idx0, false) } else {