mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-19 13:36:54 +02:00
cleaned more
This commit is contained in:
parent
77f6f34dbe
commit
dc8979b382
1 changed files with 11 additions and 11 deletions
|
@ -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<Application::IncomingPacketBuffer, MAX_NOISE_HANDSHAKE_FRAGMENTS>); MAX_INCOMPLETE_SESSION_QUEUE_SIZE]>,
|
||||
active_sessions: RwLock<HashMap<SessionId, Weak<Session<'a, Application>>>>,
|
||||
init_defrag: Mutex<[(i64, u64, Fragged<Application::IncomingPacketBuffer, MAX_NOISE_HANDSHAKE_FRAGMENTS>); MAX_INCOMPLETE_SESSION_QUEUE_SIZE]>,
|
||||
incoming_sessions: RwLock<[(i64, u64, Option<Arc<IncomingIncompleteSession<Application>>>); MAX_INCOMPLETE_SESSION_QUEUE_SIZE]>,
|
||||
active_sessions: RwLock<HashMap<SessionId, Weak<Session<'a, Application>>>>,
|
||||
}
|
||||
|
||||
/// 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<T>(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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue