mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +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> {
|
pub struct Context<'a, Application: ApplicationLayer> {
|
||||||
default_physical_mtu: AtomicUsize,
|
default_physical_mtu: AtomicUsize,
|
||||||
dos_salt: RandomState,
|
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
|
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]>,
|
init_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>>>>,
|
|
||||||
incoming_sessions: RwLock<[(i64, u64, Option<Arc<IncomingIncompleteSession<Application>>>); 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.
|
/// Result generated by the context packet receive function, with possible payloads.
|
||||||
|
@ -146,9 +146,9 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> {
|
||||||
Self {
|
Self {
|
||||||
default_physical_mtu: AtomicUsize::new(default_physical_mtu),
|
default_physical_mtu: AtomicUsize::new(default_physical_mtu),
|
||||||
dos_salt: RandomState::new(),
|
dos_salt: RandomState::new(),
|
||||||
defrag_has_pending: AtomicBool::new(false),
|
init_has_pending: AtomicBool::new(false),
|
||||||
incoming_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)),
|
active_sessions: RwLock::new(HashMap::with_capacity(64)),
|
||||||
incoming_sessions: RwLock::new(std::array::from_fn(|_| (i64::MAX, 0, None))),
|
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.
|
// Only check for expiration if we have a pending packet.
|
||||||
// This check is allowed to have false positives for simplicity's sake.
|
// 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;
|
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 {
|
if pending.0 <= negotiation_timeout_cutoff {
|
||||||
pending.0 = i64::MAX;
|
pending.0 = i64::MAX;
|
||||||
pending.2.drop_in_place();
|
pending.2.drop_in_place();
|
||||||
|
@ -242,7 +242,7 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if has_pending {
|
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) {
|
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);
|
hasher.write_u64(incoming_counter);
|
||||||
let hashed_counter = hasher.finish();
|
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(
|
let (idx, is_old) = lookup(
|
||||||
&*defrag,
|
&*defrag,
|
||||||
hashed_counter,
|
hashed_counter,
|
||||||
|
@ -575,7 +575,7 @@ impl<'a, Application: ApplicationLayer> Context<'a, Application> {
|
||||||
} else if !is_old {
|
} else if !is_old {
|
||||||
defrag[idx].0 = current_time;
|
defrag[idx].0 = current_time;
|
||||||
defrag[idx].1 = hashed_counter;
|
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 {
|
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)
|
(idx0, true)
|
||||||
} else if table[idx1].1 == key {
|
} else if table[idx1].1 == key {
|
||||||
(idx1, true)
|
(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.
|
// slot0 is either empty, expired, or the youngest of the two slots so use it.
|
||||||
(idx0, false)
|
(idx0, false)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue