mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 17:03:43 +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"] }
|
lz4_flex = { version = "^0", features = ["safe-encode", "safe-decode", "checked-decode"] }
|
||||||
dashmap = "^4"
|
dashmap = "^4"
|
||||||
parking_lot = "^0"
|
parking_lot = "^0"
|
||||||
arc-swap = { version = "^1", features = [], default-features = false }
|
|
||||||
lazy_static = "^1"
|
lazy_static = "^1"
|
||||||
highway = "^0"
|
highway = "^0"
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use std::num::NonZeroI64;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicI64, Ordering};
|
use std::sync::atomic::{AtomicI64, Ordering};
|
||||||
|
|
||||||
use arc_swap::ArcSwap;
|
|
||||||
use highway::HighwayHash;
|
use highway::HighwayHash;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use zerotier_core_crypto::hash::SHA384_HASH_SIZE;
|
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
|
/// one and only one unique path object. That enables statistics to be tracked
|
||||||
/// for them and uniform application of things like keepalives.
|
/// for them and uniform application of things like keepalives.
|
||||||
pub struct Path {
|
pub struct Path {
|
||||||
endpoint: ArcSwap<Endpoint>,
|
endpoint: Mutex<Arc<Endpoint>>,
|
||||||
local_socket: Option<NonZeroI64>,
|
local_socket: Option<NonZeroI64>,
|
||||||
local_interface: Option<NonZeroI64>,
|
local_interface: Option<NonZeroI64>,
|
||||||
last_send_time_ticks: AtomicI64,
|
last_send_time_ticks: AtomicI64,
|
||||||
|
@ -84,7 +83,7 @@ impl Path {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(endpoint: Endpoint, local_socket: Option<NonZeroI64>, local_interface: Option<NonZeroI64>) -> Self {
|
pub fn new(endpoint: Endpoint, local_socket: Option<NonZeroI64>, local_interface: Option<NonZeroI64>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
endpoint: ArcSwap::new(Arc::new(endpoint)),
|
endpoint: Mutex::new(Arc::new(endpoint)),
|
||||||
local_socket,
|
local_socket,
|
||||||
local_interface,
|
local_interface,
|
||||||
last_send_time_ticks: AtomicI64::new(0),
|
last_send_time_ticks: AtomicI64::new(0),
|
||||||
|
@ -94,7 +93,7 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn endpoint(&self) -> Arc<Endpoint> { self.endpoint.load_full() }
|
pub fn endpoint(&self) -> Arc<Endpoint> { self.endpoint.lock().clone() }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn local_socket(&self) -> Option<NonZeroI64> { self.local_socket }
|
pub fn local_socket(&self) -> Option<NonZeroI64> { self.local_socket }
|
||||||
|
@ -146,7 +145,7 @@ impl Path {
|
||||||
let mut replace = false;
|
let mut replace = false;
|
||||||
match source_endpoint {
|
match source_endpoint {
|
||||||
Endpoint::IpUdp(ip) => {
|
Endpoint::IpUdp(ip) => {
|
||||||
let ep = self.endpoint.load();
|
let ep = self.endpoint.lock().clone();
|
||||||
match ep.as_ref() {
|
match ep.as_ref() {
|
||||||
Endpoint::IpUdp(ip_orig) => {
|
Endpoint::IpUdp(ip_orig) => {
|
||||||
debug_assert!(ip_orig.ip_bytes().eq(ip.ip_bytes()));
|
debug_assert!(ip_orig.ip_bytes().eq(ip.ip_bytes()));
|
||||||
|
@ -160,7 +159,7 @@ impl Path {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
if replace {
|
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::Arc;
|
||||||
use std::sync::atomic::{AtomicI64, AtomicU64, AtomicU8, Ordering};
|
use std::sync::atomic::{AtomicI64, AtomicU64, AtomicU8, Ordering};
|
||||||
|
|
||||||
use arc_swap::ArcSwapOption;
|
|
||||||
use parking_lot::Mutex;
|
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::poly1305::Poly1305;
|
||||||
use zerotier_core_crypto::random::next_u64_secure;
|
use zerotier_core_crypto::random::next_u64_secure;
|
||||||
use zerotier_core_crypto::salsa::Salsa;
|
use zerotier_core_crypto::salsa::Salsa;
|
||||||
use zerotier_core_crypto::secret::Secret;
|
use zerotier_core_crypto::secret::Secret;
|
||||||
|
|
||||||
use crate::{PacketBuffer, VERSION_MAJOR, VERSION_MINOR, VERSION_PROTO, VERSION_REVISION};
|
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::util::buffer::Buffer;
|
||||||
use crate::vl1::{Endpoint, Identity, InetAddress, Path};
|
use crate::vl1::{Endpoint, Identity, InetAddress, Path};
|
||||||
use crate::vl1::identity::{IDENTITY_ALGORITHM_ALL, IDENTITY_ALGORITHM_X25519};
|
use crate::vl1::identity::{IDENTITY_ALGORITHM_ALL, IDENTITY_ALGORITHM_X25519};
|
||||||
|
@ -41,7 +40,7 @@ pub struct Peer {
|
||||||
static_secret: SymmetricSecret,
|
static_secret: SymmetricSecret,
|
||||||
|
|
||||||
// Latest ephemeral secret or None if not yet negotiated.
|
// 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 sorted in descending order of quality / preference.
|
||||||
paths: Mutex<Vec<Arc<Path>>>,
|
paths: Mutex<Vec<Arc<Path>>>,
|
||||||
|
@ -183,7 +182,7 @@ impl Peer {
|
||||||
Peer {
|
Peer {
|
||||||
identity: id,
|
identity: id,
|
||||||
static_secret: SymmetricSecret::new(static_secret),
|
static_secret: SymmetricSecret::new(static_secret),
|
||||||
ephemeral_secret: ArcSwapOption::const_empty(),
|
ephemeral_secret: Mutex::new(None),
|
||||||
paths: Mutex::new(Vec::new()),
|
paths: Mutex::new(Vec::new()),
|
||||||
reported_local_ip: Mutex::new(None),
|
reported_local_ip: Mutex::new(None),
|
||||||
last_send_time_ticks: AtomicI64::new(0),
|
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 _ = 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 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) {
|
if let Some(message_id) = try_aead_decrypt(&ephemeral_secret.secret, packet_frag0_payload_bytes, header, fragments, &mut payload) {
|
||||||
// Decryption successful with ephemeral secret
|
// Decryption successful with ephemeral secret
|
||||||
ephemeral_secret.decrypt_uses.fetch_add(1, Ordering::Relaxed);
|
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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"
|
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arc-swap"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-channel"
|
name = "async-channel"
|
||||||
version = "1.6.1"
|
version = "1.6.1"
|
||||||
|
@ -2172,7 +2166,6 @@ dependencies = [
|
||||||
name = "zerotier-network-hypervisor"
|
name = "zerotier-network-hypervisor"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arc-swap",
|
|
||||||
"base64",
|
"base64",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"highway",
|
"highway",
|
||||||
|
|
Loading…
Add table
Reference in a new issue