diff --git a/zerotier-network-hypervisor/Cargo.toml b/zerotier-network-hypervisor/Cargo.toml index 6f92e7bbe..c38726837 100644 --- a/zerotier-network-hypervisor/Cargo.toml +++ b/zerotier-network-hypervisor/Cargo.toml @@ -17,7 +17,6 @@ base64 = "^0" lz4_flex = { version = "^0", features = ["safe-encode", "safe-decode", "checked-decode"] } dashmap = "^4" parking_lot = "^0" -arc-swap = { version = "^1", features = [], default-features = false } lazy_static = "^1" highway = "^0" diff --git a/zerotier-network-hypervisor/src/vl1/path.rs b/zerotier-network-hypervisor/src/vl1/path.rs index 78666e2ee..92abf5591 100644 --- a/zerotier-network-hypervisor/src/vl1/path.rs +++ b/zerotier-network-hypervisor/src/vl1/path.rs @@ -13,7 +13,6 @@ use std::num::NonZeroI64; use std::sync::Arc; use std::sync::atomic::{AtomicI64, Ordering}; -use arc_swap::ArcSwap; use highway::HighwayHash; use parking_lot::Mutex; use zerotier_core_crypto::hash::SHA384_HASH_SIZE; @@ -39,7 +38,7 @@ lazy_static! { /// one and only one unique path object. That enables statistics to be tracked /// for them and uniform application of things like keepalives. pub struct Path { - endpoint: ArcSwap, + endpoint: Mutex>, local_socket: Option, local_interface: Option, last_send_time_ticks: AtomicI64, @@ -84,7 +83,7 @@ impl Path { #[inline(always)] pub fn new(endpoint: Endpoint, local_socket: Option, local_interface: Option) -> Self { Self { - endpoint: ArcSwap::new(Arc::new(endpoint)), + endpoint: Mutex::new(Arc::new(endpoint)), local_socket, local_interface, last_send_time_ticks: AtomicI64::new(0), @@ -94,7 +93,7 @@ impl Path { } #[inline(always)] - pub fn endpoint(&self) -> Arc { self.endpoint.load_full() } + pub fn endpoint(&self) -> Arc { self.endpoint.lock().clone() } #[inline(always)] pub fn local_socket(&self) -> Option { self.local_socket } @@ -146,7 +145,7 @@ impl Path { let mut replace = false; match source_endpoint { Endpoint::IpUdp(ip) => { - let ep = self.endpoint.load(); + let ep = self.endpoint.lock().clone(); match ep.as_ref() { Endpoint::IpUdp(ip_orig) => { debug_assert!(ip_orig.ip_bytes().eq(ip.ip_bytes())); @@ -160,7 +159,7 @@ impl Path { _ => {} } if replace { - self.endpoint.swap(Arc::new(source_endpoint.clone())); + (*self.endpoint.lock()) = Arc::new(source_endpoint.clone()); } } diff --git a/zerotier-network-hypervisor/src/vl1/peer.rs b/zerotier-network-hypervisor/src/vl1/peer.rs index 4d4197050..ea8d95988 100644 --- a/zerotier-network-hypervisor/src/vl1/peer.rs +++ b/zerotier-network-hypervisor/src/vl1/peer.rs @@ -12,17 +12,16 @@ use std::num::NonZeroI64; use std::sync::Arc; use std::sync::atomic::{AtomicI64, AtomicU64, AtomicU8, Ordering}; -use arc_swap::ArcSwapOption; use parking_lot::Mutex; -use zerotier_core_crypto::hash::{hmac_sha384, SHA384, SHA384_HASH_SIZE}; +use zerotier_core_crypto::hash::*; use zerotier_core_crypto::poly1305::Poly1305; use zerotier_core_crypto::random::next_u64_secure; use zerotier_core_crypto::salsa::Salsa; use zerotier_core_crypto::secret::Secret; use crate::{PacketBuffer, VERSION_MAJOR, VERSION_MINOR, VERSION_PROTO, VERSION_REVISION}; -use crate::util::{array_range, u64_as_bytes}; +use crate::util::array_range; use crate::util::buffer::Buffer; use crate::vl1::{Endpoint, Identity, InetAddress, Path}; use crate::vl1::identity::{IDENTITY_ALGORITHM_ALL, IDENTITY_ALGORITHM_X25519}; @@ -41,7 +40,7 @@ pub struct Peer { static_secret: SymmetricSecret, // Latest ephemeral secret or None if not yet negotiated. - ephemeral_secret: ArcSwapOption, + ephemeral_secret: Mutex>>, // Paths sorted in descending order of quality / preference. paths: Mutex>>, @@ -183,7 +182,7 @@ impl Peer { Peer { identity: id, static_secret: SymmetricSecret::new(static_secret), - ephemeral_secret: ArcSwapOption::const_empty(), + ephemeral_secret: Mutex::new(None), paths: Mutex::new(Vec::new()), reported_local_ip: Mutex::new(None), last_send_time_ticks: AtomicI64::new(0), @@ -224,7 +223,7 @@ impl Peer { let _ = frag0.as_bytes_starting_at(PACKET_VERB_INDEX).map(|packet_frag0_payload_bytes| { let mut payload: Buffer = unsafe { Buffer::new_without_memzero() }; - let (forward_secrecy, mut message_id) = if let Some(ephemeral_secret) = self.ephemeral_secret.load_full() { + let (forward_secrecy, mut message_id) = if let Some(ephemeral_secret) = self.ephemeral_secret.lock().clone() { if let Some(message_id) = try_aead_decrypt(&ephemeral_secret.secret, packet_frag0_payload_bytes, header, fragments, &mut payload) { // Decryption successful with ephemeral secret ephemeral_secret.decrypt_uses.fetch_add(1, Ordering::Relaxed); diff --git a/zerotier-system-service/Cargo.lock b/zerotier-system-service/Cargo.lock index 2fedff6dc..baad5b788 100644 --- a/zerotier-system-service/Cargo.lock +++ b/zerotier-system-service/Cargo.lock @@ -87,12 +87,6 @@ version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7" -[[package]] -name = "arc-swap" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f" - [[package]] name = "async-channel" version = "1.6.1" @@ -2172,7 +2166,6 @@ dependencies = [ name = "zerotier-network-hypervisor" version = "2.0.0" dependencies = [ - "arc-swap", "base64", "dashmap", "highway",