mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 08:57:26 +02:00
Remove some premature optimization.
This commit is contained in:
parent
ca823e5fa3
commit
a60e4838fe
4 changed files with 10 additions and 20 deletions
|
@ -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"
|
||||
|
||||
|
|
|
@ -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>,
|
||||
endpoint: Mutex<Arc<Endpoint>>,
|
||||
local_socket: Option<NonZeroI64>,
|
||||
local_interface: Option<NonZeroI64>,
|
||||
last_send_time_ticks: AtomicI64,
|
||||
|
@ -84,7 +83,7 @@ impl Path {
|
|||
#[inline(always)]
|
||||
pub fn new(endpoint: Endpoint, local_socket: Option<NonZeroI64>, local_interface: Option<NonZeroI64>) -> 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<Endpoint> { self.endpoint.load_full() }
|
||||
pub fn endpoint(&self) -> Arc<Endpoint> { self.endpoint.lock().clone() }
|
||||
|
||||
#[inline(always)]
|
||||
pub fn local_socket(&self) -> Option<NonZeroI64> { 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<EphemeralSymmetricSecret>,
|
||||
ephemeral_secret: Mutex<Option<Arc<EphemeralSymmetricSecret>>>,
|
||||
|
||||
// Paths sorted in descending order of quality / preference.
|
||||
paths: Mutex<Vec<Arc<Path>>>,
|
||||
|
@ -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<PACKET_SIZE_MAX> = 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);
|
||||
|
|
7
zerotier-system-service/Cargo.lock
generated
7
zerotier-system-service/Cargo.lock
generated
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue