diff --git a/Cargo.lock b/Cargo.lock index 7d90d38adc08..5cfe187ea57e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2147,7 +2147,6 @@ dependencies = [ "log", "mullvad-fs", "mullvad-types", - "once_cell", "rustls-pemfile", "serde", "serde_json", @@ -2205,7 +2204,6 @@ dependencies = [ "mullvad-version", "nix 0.23.2", "objc", - "once_cell", "regex", "serde", "serde_json", @@ -2293,7 +2291,6 @@ dependencies = [ "mullvad-paths", "mullvad-types", "nix 0.23.2", - "once_cell", "parity-tokio-ipc", "prost", "prost-types", @@ -2337,7 +2334,6 @@ dependencies = [ "mullvad-api", "mullvad-paths", "mullvad-version", - "once_cell", "regex", "talpid-platform-metadata", "talpid-types", @@ -2358,7 +2354,6 @@ dependencies = [ "itertools 0.12.1", "log", "mullvad-types", - "once_cell", "proptest", "rand 0.8.5", "serde_json", @@ -2378,7 +2373,6 @@ dependencies = [ "mullvad-paths", "mullvad-types", "mullvad-version", - "once_cell", "talpid-core", "talpid-future", "talpid-types", @@ -2395,7 +2389,6 @@ dependencies = [ "intersection-derive", "ipnetwork", "log", - "once_cell", "regex", "serde", "talpid-types", @@ -3925,7 +3918,6 @@ dependencies = [ "dbus", "libc", "log", - "once_cell", "thiserror", "tokio", ] @@ -4008,7 +4000,6 @@ dependencies = [ "netlink-packet-route", "netlink-sys", "nix 0.28.0", - "once_cell", "rtnetlink", "system-configuration", "talpid-types", @@ -4446,7 +4437,6 @@ name = "translations-converter" version = "0.0.0" dependencies = [ "htmlize", - "once_cell", "quick-xml", "regex", "serde", diff --git a/android/translations-converter/Cargo.toml b/android/translations-converter/Cargo.toml index 57deb26a57a2..c6d4b8015720 100644 --- a/android/translations-converter/Cargo.toml +++ b/android/translations-converter/Cargo.toml @@ -13,7 +13,6 @@ workspace = true [dependencies] thiserror = { workspace = true } htmlize = { version = "1.0.2", features = ["unescape"] } -once_cell = { workspace = true } regex = "1" serde = { version = "1", features = ["derive"] } quick-xml = { version = "0.27.1", features = ["serialize"] } diff --git a/android/translations-converter/src/android/string_value.rs b/android/translations-converter/src/android/string_value.rs index 9513f3e09642..9a01e9df86af 100644 --- a/android/translations-converter/src/android/string_value.rs +++ b/android/translations-converter/src/android/string_value.rs @@ -1,9 +1,9 @@ -use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Deserializer, Serialize}; use std::{ fmt::{self, Display, Formatter, Write}, ops::Deref, + sync::LazyLock, }; /// An Android string value @@ -32,7 +32,7 @@ impl StringValue { /// The input XML file might have line breaks inside the string, and they should be collapsed /// into a single whitespace character. fn collapse_line_breaks(original: String) -> String { - static LINE_BREAKS: Lazy = Lazy::new(|| Regex::new(r"\s*\n\s*").unwrap()); + static LINE_BREAKS: LazyLock = LazyLock::new(|| Regex::new(r"\s*\n\s*").unwrap()); LINE_BREAKS.replace_all(&original, " ").into_owned() } @@ -43,7 +43,8 @@ impl StringValue { /// would update the string so that all parameters have indices: `Things are %1$d, %3$s and /// %4$s`. fn ensure_parameters_are_indexed(original: String) -> String { - static PARAMETER_INDEX: Lazy = Lazy::new(|| Regex::new(r"^(\d+)\$").unwrap()); + static PARAMETER_INDEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\d+)\$").unwrap()); let mut parts = original.split('%'); let mut output = parts.next().unwrap().to_owned(); diff --git a/android/translations-converter/src/normalize.rs b/android/translations-converter/src/normalize.rs index 1ea0ae94404b..ace645570e04 100644 --- a/android/translations-converter/src/normalize.rs +++ b/android/translations-converter/src/normalize.rs @@ -1,5 +1,5 @@ -use once_cell::sync::Lazy; use regex::Regex; +use std::sync::LazyLock; pub trait Normalize { /// Normalize the string value into a common format. @@ -12,9 +12,9 @@ mod android { use super::*; use crate::android::StringValue; - static APOSTROPHES: Lazy = Lazy::new(|| Regex::new(r"\\'").unwrap()); - static DOUBLE_QUOTES: Lazy = Lazy::new(|| Regex::new(r#"\\""#).unwrap()); - static PARAMETERS: Lazy = Lazy::new(|| Regex::new(r"%[0-9]*\$").unwrap()); + static APOSTROPHES: LazyLock = LazyLock::new(|| Regex::new(r"\\'").unwrap()); + static DOUBLE_QUOTES: LazyLock = LazyLock::new(|| Regex::new(r#"\\""#).unwrap()); + static PARAMETERS: LazyLock = LazyLock::new(|| Regex::new(r"%[0-9]*\$").unwrap()); impl Normalize for StringValue { fn normalize(&self) -> String { @@ -35,9 +35,9 @@ mod gettext { use super::*; use crate::gettext::MsgString; - static ESCAPED_SINGLE_QUOTES: Lazy = Lazy::new(|| Regex::new(r"\\'").unwrap()); - static ESCAPED_DOUBLE_QUOTES: Lazy = Lazy::new(|| Regex::new(r#"\\""#).unwrap()); - static PARAMETERS: Lazy = Lazy::new(|| Regex::new(r"%\([^)]*\)").unwrap()); + static ESCAPED_SINGLE_QUOTES: LazyLock = LazyLock::new(|| Regex::new(r"\\'").unwrap()); + static ESCAPED_DOUBLE_QUOTES: LazyLock = LazyLock::new(|| Regex::new(r#"\\""#).unwrap()); + static PARAMETERS: LazyLock = LazyLock::new(|| Regex::new(r"%\([^)]*\)").unwrap()); impl Normalize for MsgString { fn normalize(&self) -> String { diff --git a/dist-assets/binaries b/dist-assets/binaries index e9043f890c56..d5772339cee9 160000 --- a/dist-assets/binaries +++ b/dist-assets/binaries @@ -1 +1 @@ -Subproject commit e9043f890c56b4d0db50851e3fa4db10f230118e +Subproject commit d5772339cee9c1a0d7671968746f02499b78e245 diff --git a/mullvad-api/Cargo.toml b/mullvad-api/Cargo.toml index 6958abb5bb6c..babb775a2de2 100644 --- a/mullvad-api/Cargo.toml +++ b/mullvad-api/Cargo.toml @@ -29,7 +29,6 @@ tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread", "ne tokio-rustls = "0.24.1" tokio-socks = "0.5.1" rustls-pemfile = "1.0.3" -once_cell = { workspace = true } mullvad-fs = { path = "../mullvad-fs" } mullvad-types = { path = "../mullvad-types" } diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 833dcf3f679f..87b6e3d6567a 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -139,8 +139,7 @@ pub struct ApiEndpoint { /// Whether bridges/proxies can be used to access the API or not. This is /// useful primarily for testing purposes. /// - /// * If `force_direct` is `true`, bridges and proxies will not be used to - /// reach the API. + /// * If `force_direct` is `true`, bridges and proxies will not be used to reach the API. /// * If `force_direct` is `false`, bridges and proxies can be used to reach the API. /// /// # Note diff --git a/mullvad-api/src/tls_stream.rs b/mullvad-api/src/tls_stream.rs index 74b6e9b27dce..bf4ff336f567 100644 --- a/mullvad-api/src/tls_stream.rs +++ b/mullvad-api/src/tls_stream.rs @@ -7,7 +7,7 @@ use std::{ }; use hyper::client::connect::{Connected, Connection}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio_rustls::{ rustls::{self, ClientConfig, ServerName}, @@ -25,7 +25,7 @@ where S: AsyncRead + AsyncWrite + Unpin, { pub async fn connect_https(stream: S, domain: &str) -> io::Result> { - static TLS_CONFIG: Lazy> = Lazy::new(|| { + static TLS_CONFIG: LazyLock> = LazyLock::new(|| { let config = ClientConfig::builder() .with_safe_default_cipher_suites() .with_safe_default_kx_groups() diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index ca7c46d8ca31..3cd1f0cb17ca 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -19,7 +19,6 @@ chrono = { workspace = true } thiserror = { workspace = true } fern = { version = "0.6", features = ["colored"] } futures = "0.3" -once_cell = { workspace = true } libc = "0.2" log = { workspace = true } regex = "1.0" diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs index c03a84f0cc8a..09e0f47a38f2 100644 --- a/mullvad-daemon/src/account_history.rs +++ b/mullvad-daemon/src/account_history.rs @@ -1,7 +1,6 @@ use mullvad_types::account::AccountToken; -use once_cell::sync::Lazy; use regex::Regex; -use std::path::Path; +use std::{path::Path, sync::LazyLock}; use talpid_types::ErrorExt; use tokio::{ fs, @@ -32,7 +31,7 @@ pub struct AccountHistory { token: Option, } -static ACCOUNT_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[0-9]+$").unwrap()); +static ACCOUNT_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^[0-9]+$").unwrap()); impl AccountHistory { pub async fn new( diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs index 4e9824aadaab..d702c443c581 100644 --- a/mullvad-daemon/src/cli.rs +++ b/mullvad-daemon/src/cli.rs @@ -1,7 +1,7 @@ use clap::{Args, Parser}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; -static ENV_DESC: Lazy = Lazy::new(|| { +static ENV_DESC: LazyLock = LazyLock::new(|| { format!( "ENV: @@ -119,7 +119,7 @@ impl From for Command { } pub fn get_config() -> &'static Config { - static CONFIG: Lazy = Lazy::new(create_config); + static CONFIG: LazyLock = LazyLock::new(create_config); &CONFIG } diff --git a/mullvad-daemon/src/geoip.rs b/mullvad-daemon/src/geoip.rs index af7db0cb2b02..da2fb3e8dbbf 100644 --- a/mullvad-daemon/src/geoip.rs +++ b/mullvad-daemon/src/geoip.rs @@ -3,7 +3,7 @@ use std::time::Duration; use futures::join; use mullvad_api::rest::{Error, RequestServiceHandle}; use mullvad_types::location::{AmIMullvad, GeoIpLocation, LocationEventData}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use talpid_core::mpsc::Sender; use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered}; use talpid_types::ErrorExt; @@ -19,7 +19,7 @@ use crate::{DaemonEventSender, InternalDaemonEvent}; // production build, a warning will be logged and the env variable *won´t* have // any effect on the api call. The default host name `am.i.mullvad.net` will // always be used in release mode. -static MULLVAD_CONNCHECK_HOST: Lazy = Lazy::new(|| { +static MULLVAD_CONNCHECK_HOST: LazyLock = LazyLock::new(|| { const DEFAULT_CONNCHECK_HOST: &str = "am.i.mullvad.net"; let conncheck_host_var = std::env::var("MULLVAD_CONNCHECK_HOST").ok(); let host = if cfg!(feature = "api-override") { diff --git a/mullvad-daemon/src/migrations/account_history.rs b/mullvad-daemon/src/migrations/account_history.rs index fb1691fb75c4..e367ffdce499 100644 --- a/mullvad-daemon/src/migrations/account_history.rs +++ b/mullvad-daemon/src/migrations/account_history.rs @@ -1,9 +1,8 @@ use super::{Error, Result}; use mullvad_types::account::AccountToken; -use once_cell::sync::Lazy; use regex::Regex; use serde::Deserialize; -use std::path::Path; +use std::{path::Path, sync::LazyLock}; use talpid_types::ErrorExt; use tokio::{ fs::{self, File}, @@ -17,7 +16,7 @@ use tokio::{ const ACCOUNT_HISTORY_FILE: &str = "account-history.json"; -static ACCOUNT_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[0-9]+$").unwrap()); +static ACCOUNT_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^[0-9]+$").unwrap()); pub async fn migrate_location(old_dir: &Path, new_dir: &Path) { let old_path = old_dir.join(ACCOUNT_HISTORY_FILE); diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index a5a76e72b440..ccec49486b55 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -1,13 +1,12 @@ use crate::cli; use mullvad_daemon::{runtime::new_multi_thread, DaemonShutdownHandle}; -use once_cell::sync::Lazy; use std::{ env, ffi::{c_void, OsString}, ptr, slice, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering}, - mpsc, Arc, + mpsc, Arc, LazyLock, }, thread, time::{Duration, Instant}, @@ -39,7 +38,7 @@ static SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS; const SERVICE_RECOVERY_LAST_RESTART_DELAY: Duration = Duration::from_secs(60 * 10); const SERVICE_FAILURE_RESET_PERIOD: Duration = Duration::from_secs(60 * 15); -static SERVICE_ACCESS: Lazy = Lazy::new(|| { +static SERVICE_ACCESS: LazyLock = LazyLock::new(|| { ServiceAccess::QUERY_CONFIG | ServiceAccess::CHANGE_CONFIG | ServiceAccess::START diff --git a/mullvad-daemon/src/tunnel.rs b/mullvad-daemon/src/tunnel.rs index 31f4686df7c3..264c419d3984 100644 --- a/mullvad-daemon/src/tunnel.rs +++ b/mullvad-daemon/src/tunnel.rs @@ -13,7 +13,7 @@ use mullvad_types::{ endpoint::MullvadWireguardEndpoint, location::GeoIpLocation, relay_list::Relay, settings::TunnelOptions, }; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use talpid_core::tunnel_state_machine::TunnelParametersGenerator; #[cfg(not(target_os = "android"))] use talpid_types::net::{ @@ -31,9 +31,9 @@ use crate::device::{AccountManagerHandle, PrivateAccountAndDevice}; /// "Same IP" functionality. This means all clients have the same in-tunnel IP on these /// servers. This improves anonymity since the in-tunnel IP will not be unique to a specific /// peer. -static SAME_IP_V4: Lazy = - Lazy::new(|| Ipv4Addr::from_str("10.127.255.254").unwrap().into()); -static SAME_IP_V6: Lazy = Lazy::new(|| { +static SAME_IP_V4: LazyLock = + LazyLock::new(|| Ipv4Addr::from_str("10.127.255.254").unwrap().into()); +static SAME_IP_V6: LazyLock = LazyLock::new(|| { Ipv6Addr::from_str("fc00:bbbb:bbbb:bb01:ffff:ffff:ffff:ffff") .unwrap() .into() diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs index d4274ec10d32..4aae30f574d3 100644 --- a/mullvad-daemon/src/version_check.rs +++ b/mullvad-daemon/src/version_check.rs @@ -6,7 +6,6 @@ use futures::{ }; use mullvad_api::{availability::ApiAvailabilityHandle, rest::MullvadRestHandle, AppVersionProxy}; use mullvad_types::version::{AppVersionInfo, ParsedAppVersion}; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::{ cmp::max, @@ -15,6 +14,7 @@ use std::{ path::{Path, PathBuf}, pin::Pin, str::FromStr, + sync::LazyLock, time::{Duration, SystemTime}, }; use talpid_core::mpsc::Sender; @@ -24,9 +24,9 @@ use tokio::{fs::File, io::AsyncReadExt}; const VERSION_INFO_FILENAME: &str = "version-info.json"; -static APP_VERSION: Lazy = - Lazy::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); -static IS_DEV_BUILD: Lazy = Lazy::new(|| APP_VERSION.is_dev()); +static APP_VERSION: LazyLock = + LazyLock::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); +static IS_DEV_BUILD: LazyLock = LazyLock::new(|| APP_VERSION.is_dev()); const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15); diff --git a/mullvad-management-interface/Cargo.toml b/mullvad-management-interface/Cargo.toml index 352b1e631c2f..75c6f1b0adc0 100644 --- a/mullvad-management-interface/Cargo.toml +++ b/mullvad-management-interface/Cargo.toml @@ -27,7 +27,6 @@ log = { workspace = true } [target.'cfg(unix)'.dependencies] nix = "0.23" -once_cell = { workspace = true } [build-dependencies] tonic-build = { workspace = true, default-features = false, features = ["transport", "prost"] } diff --git a/mullvad-management-interface/src/lib.rs b/mullvad-management-interface/src/lib.rs index 43b9974d59e0..0a61f6627f6d 100644 --- a/mullvad-management-interface/src/lib.rs +++ b/mullvad-management-interface/src/lib.rs @@ -24,10 +24,10 @@ pub type ManagementServiceClient = pub use types::management_service_server::{ManagementService, ManagementServiceServer}; #[cfg(unix)] -use once_cell::sync::Lazy; +use std::sync::LazyLock; #[cfg(unix)] -static MULLVAD_MANAGEMENT_SOCKET_GROUP: Lazy> = - Lazy::new(|| env::var("MULLVAD_MANAGEMENT_SOCKET_GROUP").ok()); +static MULLVAD_MANAGEMENT_SOCKET_GROUP: LazyLock> = + LazyLock::new(|| env::var("MULLVAD_MANAGEMENT_SOCKET_GROUP").ok()); pub const CUSTOM_LIST_LIST_NOT_FOUND_DETAILS: &[u8] = b"custom_list_list_not_found"; pub const CUSTOM_LIST_LIST_EXISTS_DETAILS: &[u8] = b"custom_list_list_exists"; diff --git a/mullvad-problem-report/Cargo.toml b/mullvad-problem-report/Cargo.toml index 53cc7a9d51d8..75360267b535 100644 --- a/mullvad-problem-report/Cargo.toml +++ b/mullvad-problem-report/Cargo.toml @@ -13,7 +13,6 @@ workspace = true [dependencies] dirs = "5.0.1" thiserror = { workspace = true } -once_cell = { workspace = true } log = { workspace = true } regex = "1.0" uuid = { version = "1.4.1", features = ["v4"] } diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index 74076a8b5a7b..270de55f9589 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -1,5 +1,4 @@ use mullvad_api::proxy::ApiConnectionMode; -use once_cell::sync::Lazy; use regex::Regex; use std::{ borrow::Cow, @@ -9,6 +8,7 @@ use std::{ fs::{self, File}, io::{self, BufWriter, Read, Seek, SeekFrom, Write}, path::{Path, PathBuf}, + sync::LazyLock, }; use talpid_types::ErrorExt; @@ -406,7 +406,7 @@ impl ProblemReport { } fn redact_account_number(input: &str) -> Cow<'_, str> { - static RE: Lazy = Lazy::new(|| Regex::new("\\d{16}").unwrap()); + static RE: LazyLock = LazyLock::new(|| Regex::new("\\d{16}").unwrap()); RE.replace_all(input, "[REDACTED ACCOUNT NUMBER]") } @@ -415,7 +415,7 @@ impl ProblemReport { } fn redact_network_info(input: &str) -> Cow<'_, str> { - static RE: Lazy = Lazy::new(|| { + static RE: LazyLock = LazyLock::new(|| { let boundary = "[^0-9a-zA-Z.:]"; let combined_pattern = format!( "(?P^|{})(?:{}|{}|{})", @@ -430,7 +430,7 @@ impl ProblemReport { } fn redact_guids(input: &str) -> Cow<'_, str> { - static RE: Lazy = Lazy::new(|| { + static RE: LazyLock = LazyLock::new(|| { Regex::new(r"(?i)\{?[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}?") .unwrap() }); diff --git a/mullvad-relay-selector/Cargo.toml b/mullvad-relay-selector/Cargo.toml index 0fb700d1f5c2..736862711cf6 100644 --- a/mullvad-relay-selector/Cargo.toml +++ b/mullvad-relay-selector/Cargo.toml @@ -16,7 +16,6 @@ thiserror = { workspace = true } ipnetwork = { workspace = true } itertools = "0.12" log = { workspace = true } -once_cell = { workspace = true } rand = "0.8.5" serde_json = "1.0" diff --git a/mullvad-relay-selector/src/relay_selector/mod.rs b/mullvad-relay-selector/src/relay_selector/mod.rs index 5093ffdeca78..c370fa851eed 100644 --- a/mullvad-relay-selector/src/relay_selector/mod.rs +++ b/mullvad-relay-selector/src/relay_selector/mod.rs @@ -8,11 +8,10 @@ pub mod query; use chrono::{DateTime, Local}; use itertools::Itertools; -use once_cell::sync::Lazy; use rand::{seq::IteratorRandom, thread_rng}; use std::{ path::Path, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, time::SystemTime, }; @@ -51,7 +50,7 @@ use self::{ /// preferences. See [the documentation on `RelayQuery`][RelayQuery] for further details. /// /// This list should be kept in sync with the expected behavior defined in `docs/relay-selector.md` -pub static RETRY_ORDER: Lazy> = Lazy::new(|| { +pub static RETRY_ORDER: LazyLock> = LazyLock::new(|| { use query::builder::{IpVersion, RelayQueryBuilder}; vec![ // 1 diff --git a/mullvad-relay-selector/tests/relay_selector.rs b/mullvad-relay-selector/tests/relay_selector.rs index 7cf2329e9ae8..ee073a8af92d 100644 --- a/mullvad-relay-selector/tests/relay_selector.rs +++ b/mullvad-relay-selector/tests/relay_selector.rs @@ -1,7 +1,6 @@ //! Tests for verifying that the relay selector works as expected. -use once_cell::sync::Lazy; -use std::collections::HashSet; +use std::{collections::HashSet, sync::LazyLock}; use talpid_types::net::{ obfuscation::ObfuscatorConfig, wireguard::PublicKey, @@ -29,7 +28,7 @@ use mullvad_types::{ }, }; -static RELAYS: Lazy = Lazy::new(|| RelayList { +static RELAYS: LazyLock = LazyLock::new(|| RelayList { etag: None, countries: vec![RelayListCountry { name: "Sweden".to_string(), diff --git a/mullvad-setup/Cargo.toml b/mullvad-setup/Cargo.toml index f8a8239f43d0..0b526b8ff6d4 100644 --- a/mullvad-setup/Cargo.toml +++ b/mullvad-setup/Cargo.toml @@ -18,7 +18,6 @@ path = "src/main.rs" clap = { workspace = true } env_logger = { workspace = true } thiserror = { workspace = true } -once_cell = { workspace = true } mullvad-management-interface = { path = "../mullvad-management-interface" } diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs index 34155fbb7195..f937f04e7edf 100644 --- a/mullvad-setup/src/main.rs +++ b/mullvad-setup/src/main.rs @@ -1,6 +1,5 @@ use clap::Parser; -use once_cell::sync::Lazy; -use std::{path::PathBuf, process, str::FromStr, time::Duration}; +use std::{path::PathBuf, process, str::FromStr, sync::LazyLock, time::Duration}; use mullvad_api::{proxy::ApiConnectionMode, DEVICE_NOT_FOUND}; use mullvad_management_interface::MullvadProxyClient; @@ -9,8 +8,8 @@ use talpid_core::firewall::{self, Firewall}; use talpid_future::retry::{retry_future, ConstantInterval}; use talpid_types::ErrorExt; -static APP_VERSION: Lazy = - Lazy::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); +static APP_VERSION: LazyLock = + LazyLock::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); const DEVICE_REMOVAL_STRATEGY: ConstantInterval = ConstantInterval::new(Duration::ZERO, Some(5)); diff --git a/mullvad-types/Cargo.toml b/mullvad-types/Cargo.toml index 864a7465e6e5..e3683367527f 100644 --- a/mullvad-types/Cargo.toml +++ b/mullvad-types/Cargo.toml @@ -14,7 +14,6 @@ workspace = true chrono = { workspace = true, features = ["clock", "serde"] } thiserror = { workspace = true } ipnetwork = { workspace = true } -once_cell = { workspace = true } log = { workspace = true } regex = "1" serde = { version = "1.0", features = ["derive"] } diff --git a/mullvad-types/src/auth_failed.rs b/mullvad-types/src/auth_failed.rs index 6c118ff0ebfa..335f8463f334 100644 --- a/mullvad-types/src/auth_failed.rs +++ b/mullvad-types/src/auth_failed.rs @@ -1,5 +1,5 @@ -use once_cell::sync::Lazy; use regex::Regex; +use std::sync::LazyLock; use talpid_types::tunnel::ErrorStateCause; /// Used to parse [`talpid_types::tunnel::ErrorStateCause::AuthFailed`], which may be returned @@ -68,7 +68,7 @@ impl TryFrom<&ErrorStateCause> for AuthFailed { // * "This is not a valid Mullvad account" - human-readable message (ignored). // In the case that the message has preceding whitespace, it will be trimmed. fn parse_string(reason: &str) -> Option<&str> { - static REASON_REGEX: Lazy = Lazy::new(|| Regex::new(r"^\[(\w+)\]\s*").unwrap()); + static REASON_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^\[(\w+)\]\s*").unwrap()); let captures = REASON_REGEX.captures(reason)?; captures.get(1).map(|m| m.as_str()) } diff --git a/mullvad-types/src/version.rs b/mullvad-types/src/version.rs index 682070735add..1ca578514787 100644 --- a/mullvad-types/src/version.rs +++ b/mullvad-types/src/version.rs @@ -1,16 +1,17 @@ -use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt::{self, Formatter}, str::FromStr, + sync::LazyLock, }; -static STABLE_REGEX: Lazy = Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)$").unwrap()); -static BETA_REGEX: Lazy = Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)-beta(\d+)$").unwrap()); -static DEV_REGEX: Lazy = - Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)(\.\d+)?(-beta(\d+))?-dev-(\w+)$").unwrap()); +static STABLE_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^(\d{4})\.(\d+)$").unwrap()); +static BETA_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\d{4})\.(\d+)-beta(\d+)$").unwrap()); +static DEV_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\d{4})\.(\d+)(\.\d+)?(-beta(\d+))?-dev-(\w+)$").unwrap()); /// AppVersionInfo represents the current stable and the current latest release versions of the /// Mullvad VPN app. diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index f7c67b9be72d..1bc0d956920f 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -17,7 +17,6 @@ futures = "0.3.15" ipnetwork = { workspace = true } libc = "0.2" log = { workspace = true } -once_cell = { workspace = true } parking_lot = "0.12.0" rand = "0.8.5" talpid-routing = { path = "../talpid-routing" } @@ -66,6 +65,7 @@ bitflags = "1.2" widestring = "1.0" winreg = { version = "0.51", features = ["transactions"] } memoffset = "0.6" +once_cell = { workspace = true } windows-service = "0.6.0" talpid-windows = { path = "../talpid-windows" } diff --git a/talpid-core/src/firewall/linux.rs b/talpid-core/src/firewall/linux.rs index 7c3cb26ec7b0..1242739a3370 100644 --- a/talpid-core/src/firewall/linux.rs +++ b/talpid-core/src/firewall/linux.rs @@ -5,12 +5,12 @@ use nftnl::{ expr::{self, IcmpCode, Payload, RejectionType, Verdict}, nft_expr, table, Batch, Chain, FinalizedBatch, ProtoFamily, Rule, Table, }; -use once_cell::sync::Lazy; use std::{ env, ffi::{CStr, CString}, fs, io, net::{IpAddr, Ipv4Addr}, + sync::LazyLock, }; use talpid_types::net::{AllowedEndpoint, AllowedTunnelTraffic, Endpoint, TransportProtocol}; @@ -52,23 +52,24 @@ pub enum Error { /// TODO(linus): This crate is not supposed to be Mullvad-aware. So at some point this should be /// replaced by allowing the table name to be configured from the public API of this crate. -static TABLE_NAME: Lazy = Lazy::new(|| CString::new("mullvad").unwrap()); -static IN_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("input").unwrap()); -static OUT_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("output").unwrap()); -static FORWARD_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("forward").unwrap()); -static PREROUTING_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("prerouting").unwrap()); -static MANGLE_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("mangle").unwrap()); -static NAT_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("nat").unwrap()); +static TABLE_NAME: LazyLock = LazyLock::new(|| CString::new("mullvad").unwrap()); +static IN_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("input").unwrap()); +static OUT_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("output").unwrap()); +static FORWARD_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("forward").unwrap()); +static PREROUTING_CHAIN_NAME: LazyLock = + LazyLock::new(|| CString::new("prerouting").unwrap()); +static MANGLE_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("mangle").unwrap()); +static NAT_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("nat").unwrap()); /// Allows controlling whether firewall rules should have packet counters or not from an env /// variable. Useful for debugging the rules. -static ADD_COUNTERS: Lazy = Lazy::new(|| { +static ADD_COUNTERS: LazyLock = LazyLock::new(|| { env::var("TALPID_FIREWALL_DEBUG") .map(|v| v != "0") .unwrap_or(false) }); -static DONT_SET_SRC_VALID_MARK: Lazy = Lazy::new(|| { +static DONT_SET_SRC_VALID_MARK: LazyLock = LazyLock::new(|| { env::var("TALPID_FIREWALL_DONT_SET_SRC_VALID_MARK") .map(|v| v != "0") .unwrap_or(false) @@ -1063,10 +1064,10 @@ fn set_src_valid_mark_sysctl() -> io::Result<()> { /// Tables that are no longer used but need to be deleted due to upgrades. /// This can be removed when upgrades from 2023.3 are no longer supported. fn batch_deprecated_tables(batch: &mut Batch) { - static MANGLE_TABLE_NAME_V4: Lazy = - Lazy::new(|| CString::new("mullvadmangle4").unwrap()); - static MANGLE_TABLE_NAME_V6: Lazy = - Lazy::new(|| CString::new("mullvadmangle6").unwrap()); + static MANGLE_TABLE_NAME_V4: LazyLock = + LazyLock::new(|| CString::new("mullvadmangle4").unwrap()); + static MANGLE_TABLE_NAME_V6: LazyLock = + LazyLock::new(|| CString::new("mullvadmangle6").unwrap()); let tables = [ Table::new(&*MANGLE_TABLE_NAME_V4, ProtoFamily::Ipv4), Table::new(&*MANGLE_TABLE_NAME_V6, ProtoFamily::Ipv6), diff --git a/talpid-core/src/firewall/mod.rs b/talpid-core/src/firewall/mod.rs index 1e6f2ae24765..b03e3bc10207 100644 --- a/talpid-core/src/firewall/mod.rs +++ b/talpid-core/src/firewall/mod.rs @@ -1,8 +1,8 @@ use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; -use once_cell::sync::Lazy; use std::{ fmt, net::{IpAddr, Ipv4Addr, Ipv6Addr}, + sync::LazyLock, }; use talpid_types::net::{AllowedEndpoint, AllowedTunnelTraffic}; @@ -25,7 +25,7 @@ mod imp; pub use self::imp::Error; /// When "allow local network" is enabled the app will allow traffic to and from these networks. -pub(crate) static ALLOWED_LAN_NETS: Lazy<[IpNetwork; 6]> = Lazy::new(|| { +pub(crate) static ALLOWED_LAN_NETS: LazyLock<[IpNetwork; 6]> = LazyLock::new(|| { [ IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(10, 0, 0, 0), 8).unwrap()), IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(172, 16, 0, 0), 12).unwrap()), @@ -37,7 +37,7 @@ pub(crate) static ALLOWED_LAN_NETS: Lazy<[IpNetwork; 6]> = Lazy::new(|| { }); /// When "allow local network" is enabled the app will allow traffic to these networks. #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] -pub(crate) static ALLOWED_LAN_MULTICAST_NETS: Lazy<[IpNetwork; 8]> = Lazy::new(|| { +pub(crate) static ALLOWED_LAN_MULTICAST_NETS: LazyLock<[IpNetwork; 8]> = LazyLock::new(|| { [ // Local network broadcast. Not routable IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(255, 255, 255, 255), 32).unwrap()), @@ -58,23 +58,24 @@ pub(crate) static ALLOWED_LAN_MULTICAST_NETS: Lazy<[IpNetwork; 8]> = Lazy::new(| ] }); #[cfg(any(target_os = "linux", target_os = "macos"))] -static IPV6_LINK_LOCAL: Lazy = - Lazy::new(|| Ipv6Network::new(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0), 10).unwrap()); +static IPV6_LINK_LOCAL: LazyLock = + LazyLock::new(|| Ipv6Network::new(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0), 10).unwrap()); /// The allowed target addresses of outbound DHCPv6 requests #[cfg(any(target_os = "linux", target_os = "macos"))] -static DHCPV6_SERVER_ADDRS: Lazy<[Ipv6Addr; 2]> = Lazy::new(|| { +static DHCPV6_SERVER_ADDRS: LazyLock<[Ipv6Addr; 2]> = LazyLock::new(|| { [ Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 1, 2), Ipv6Addr::new(0xff05, 0, 0, 0, 0, 0, 1, 3), ] }); #[cfg(any(target_os = "linux", target_os = "macos"))] -static ROUTER_SOLICITATION_OUT_DST_ADDR: Lazy = - Lazy::new(|| Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 0, 2)); +static ROUTER_SOLICITATION_OUT_DST_ADDR: LazyLock = + LazyLock::new(|| Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 0, 2)); #[cfg(any(target_os = "linux", target_os = "macos"))] -static SOLICITED_NODE_MULTICAST: Lazy = - Lazy::new(|| Ipv6Network::new(Ipv6Addr::new(0xff02, 0, 0, 0, 0, 1, 0xFF00, 0), 104).unwrap()); -static LOOPBACK_NETS: Lazy<[IpNetwork; 2]> = Lazy::new(|| { +static SOLICITED_NODE_MULTICAST: LazyLock = LazyLock::new(|| { + Ipv6Network::new(Ipv6Addr::new(0xff02, 0, 0, 0, 0, 1, 0xFF00, 0), 104).unwrap() +}); +static LOOPBACK_NETS: LazyLock<[IpNetwork; 2]> = LazyLock::new(|| { [ IpNetwork::V4(ipnetwork::Ipv4Network::new(Ipv4Addr::new(127, 0, 0, 0), 8).unwrap()), IpNetwork::V6( diff --git a/talpid-core/src/offline/mod.rs b/talpid-core/src/offline/mod.rs index cb3d1d8b29ed..0e1d55c27375 100644 --- a/talpid-core/src/offline/mod.rs +++ b/talpid-core/src/offline/mod.rs @@ -1,5 +1,5 @@ use futures::channel::mpsc::UnboundedSender; -use once_cell::sync::Lazy; +use std::sync::LazyLock; #[cfg(not(target_os = "android"))] use talpid_routing::RouteManagerHandle; #[cfg(target_os = "android")] @@ -23,7 +23,7 @@ mod imp; mod imp; /// Disables offline monitor -static FORCE_DISABLE_OFFLINE_MONITOR: Lazy = Lazy::new(|| { +static FORCE_DISABLE_OFFLINE_MONITOR: LazyLock = LazyLock::new(|| { std::env::var("TALPID_DISABLE_OFFLINE_MONITOR") .map(|v| v != "0") .unwrap_or(false) diff --git a/talpid-core/src/resolver.rs b/talpid-core/src/resolver.rs index 30942d34fecc..97f1f4b79c00 100644 --- a/talpid-core/src/resolver.rs +++ b/talpid-core/src/resolver.rs @@ -28,12 +28,12 @@ use hickory_server::{ server::{Request, RequestHandler, ResponseHandler, ResponseInfo}, ServerFuture, }; -use once_cell::sync::Lazy; +use std::sync::LazyLock; const ALLOWED_RECORD_TYPES: &[RecordType] = &[RecordType::A, RecordType::CNAME]; const CAPTIVE_PORTAL_DOMAINS: &[&str] = &["captive.apple.com", "netcts.cdn-apple.com"]; -static ALLOWED_DOMAINS: Lazy> = Lazy::new(|| { +static ALLOWED_DOMAINS: LazyLock> = LazyLock::new(|| { CAPTIVE_PORTAL_DOMAINS .iter() .map(|domain| LowerName::from(Name::from_str(domain).unwrap())) diff --git a/talpid-core/src/split_tunnel/macos/process.rs b/talpid-core/src/split_tunnel/macos/process.rs index c85a4805f9b1..db664d6855c2 100644 --- a/talpid-core/src/split_tunnel/macos/process.rs +++ b/talpid-core/src/split_tunnel/macos/process.rs @@ -7,7 +7,6 @@ use futures::channel::oneshot; use libc::{proc_listallpids, proc_pidpath}; -use once_cell::sync::Lazy; use serde::Deserialize; use std::{ collections::{HashMap, HashSet}, @@ -16,7 +15,7 @@ use std::{ path::PathBuf, process::Stdio, ptr, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, time::Duration, }; use talpid_platform_metadata::MacosVersion; @@ -26,8 +25,8 @@ use tokio::io::{AsyncBufReadExt, BufReader}; const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(3); const EARLY_FAIL_TIMEOUT: Duration = Duration::from_millis(500); -static MIN_OS_VERSION: Lazy = - Lazy::new(|| MacosVersion::from_raw_version("13.0.0").unwrap()); +static MIN_OS_VERSION: LazyLock = + LazyLock::new(|| MacosVersion::from_raw_version("13.0.0").unwrap()); #[derive(thiserror::Error, Debug)] pub enum Error { diff --git a/talpid-dbus/Cargo.toml b/talpid-dbus/Cargo.toml index b81af1360220..4e5880bdb818 100644 --- a/talpid-dbus/Cargo.toml +++ b/talpid-dbus/Cargo.toml @@ -12,7 +12,6 @@ workspace = true [target.'cfg(target_os = "linux")'.dependencies] dbus = "0.9" thiserror = { workspace = true } -once_cell = { workspace = true } log = { workspace = true } libc = "0.2" tokio = { workspace = true, features = ["rt"] } diff --git a/talpid-dbus/src/lib.rs b/talpid-dbus/src/lib.rs index d077c245e57d..e2c8a64d709a 100644 --- a/talpid-dbus/src/lib.rs +++ b/talpid-dbus/src/lib.rs @@ -2,13 +2,13 @@ //! DBus system connection pub use dbus; use dbus::blocking::SyncConnection; -use once_cell::sync::Lazy; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, LazyLock, Mutex}; pub mod network_manager; pub mod systemd; pub mod systemd_resolved; -static DBUS_CONNECTION: Lazy>>> = Lazy::new(|| Mutex::new(None)); +static DBUS_CONNECTION: LazyLock>>> = + LazyLock::new(|| Mutex::new(None)); /// Reuse or create a system DBus connection. pub fn get_connection() -> Result, dbus::Error> { diff --git a/talpid-dbus/src/systemd_resolved.rs b/talpid-dbus/src/systemd_resolved.rs index 31e24008df6f..b678d5bf20a6 100644 --- a/talpid-dbus/src/systemd_resolved.rs +++ b/talpid-dbus/src/systemd_resolved.rs @@ -7,8 +7,13 @@ use dbus::{ message::{MatchRule, SignalArgs}, }; use libc::{AF_INET, AF_INET6}; -use once_cell::sync::Lazy; -use std::{fs, io, net::IpAddr, path::Path, sync::Arc, time::Duration}; +use std::{ + fs, io, + net::IpAddr, + path::Path, + sync::{Arc, LazyLock}, + time::Duration, +}; pub type Result = std::result::Result; @@ -57,7 +62,7 @@ pub enum Error { AsyncTaskError(#[source] tokio::task::JoinError), } -static RESOLVED_STUB_PATHS: Lazy> = Lazy::new(|| { +static RESOLVED_STUB_PATHS: LazyLock> = LazyLock::new(|| { vec![ Path::new("/run/systemd/resolve/stub-resolv.conf"), Path::new("/run/systemd/resolve/resolv.conf"), diff --git a/talpid-openvpn/Cargo.toml b/talpid-openvpn/Cargo.toml index dcdbfafdac4d..4450d56a039d 100644 --- a/talpid-openvpn/Cargo.toml +++ b/talpid-openvpn/Cargo.toml @@ -14,7 +14,6 @@ workspace = true async-trait = "0.1" thiserror = { workspace = true } futures = "0.3.15" -once_cell = { workspace = true } log = { workspace = true } shell-escape = "0.1" talpid-routing = { path = "../talpid-routing" } @@ -34,6 +33,7 @@ prost = { workspace = true } widestring = "1.0" winreg = { version = "0.51", features = ["transactions"] } talpid-windows = { path = "../talpid-windows" } +once_cell = { workspace = true } [target.'cfg(windows)'.dependencies.windows-sys] workspace = true diff --git a/talpid-openvpn/src/lib.rs b/talpid-openvpn/src/lib.rs index c8057e536b13..03f91187b6b2 100644 --- a/talpid-openvpn/src/lib.rs +++ b/talpid-openvpn/src/lib.rs @@ -3,11 +3,11 @@ #![deny(missing_docs)] use crate::proxy::ProxyMonitor; -#[cfg(windows)] -use once_cell::sync::Lazy; use process::openvpn::{OpenVpnCommand, OpenVpnProcHandle}; #[cfg(target_os = "linux")] use std::collections::{HashMap, HashSet}; +#[cfg(windows)] +use std::sync::LazyLock; #[cfg(target_os = "windows")] use std::{ffi::OsString, sync::Arc}; use std::{ @@ -39,10 +39,11 @@ mod process; mod proxy; #[cfg(windows)] -static ADAPTER_ALIAS: Lazy = Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_ALIAS: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); #[cfg(windows)] -static ADAPTER_TUNNEL_TYPE: Lazy = - Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_TUNNEL_TYPE: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); #[cfg(windows)] const ADAPTER_GUID: GUID = GUID { diff --git a/talpid-routing/Cargo.toml b/talpid-routing/Cargo.toml index 94e9b3cc8f49..2c8b99a00b09 100644 --- a/talpid-routing/Cargo.toml +++ b/talpid-routing/Cargo.toml @@ -22,7 +22,6 @@ talpid-types = { path = "../talpid-types" } [target.'cfg(target_os = "linux")'.dependencies] libc = "0.2" -once_cell = { workspace = true } rtnetlink = "0.11" netlink-packet-route = { version = "0.13", features = ["rich_nlas"] } netlink-sys = "0.8.3" diff --git a/talpid-routing/src/unix/linux.rs b/talpid-routing/src/unix/linux.rs index 785105ad56fa..92b4513301d3 100644 --- a/talpid-routing/src/unix/linux.rs +++ b/talpid-routing/src/unix/linux.rs @@ -31,14 +31,14 @@ use netlink_packet_route::{ rule::{nlas::Nla as RuleNla, RuleHeader, RuleMessage}, NetlinkMessage, NetlinkPayload, RtnlMessage, }; -use once_cell::sync::Lazy; use rtnetlink::{ constants::{RTMGRP_IPV4_ROUTE, RTMGRP_IPV6_ROUTE, RTMGRP_LINK, RTMGRP_NOTIFY}, sys::SocketAddr, Handle, IpVersion, }; +use std::sync::LazyLock; -static SUPPRESS_RULE_V4: Lazy = Lazy::new(|| RuleMessage { +static SUPPRESS_RULE_V4: LazyLock = LazyLock::new(|| RuleMessage { header: RuleHeader { family: AF_INET as u8, action: FR_ACT_TO_TBL, @@ -49,7 +49,7 @@ static SUPPRESS_RULE_V4: Lazy = Lazy::new(|| RuleMessage { RuleNla::Table(RT_TABLE_MAIN as u32), ], }); -static SUPPRESS_RULE_V6: Lazy = Lazy::new(|| { +static SUPPRESS_RULE_V6: LazyLock = LazyLock::new(|| { let mut v6_rule = SUPPRESS_RULE_V4.clone(); v6_rule.header.family = AF_INET6 as u8; v6_rule diff --git a/talpid-wireguard/src/lib.rs b/talpid-wireguard/src/lib.rs index 6cc9e0be0d7f..9e93d71ef943 100644 --- a/talpid-wireguard/src/lib.rs +++ b/talpid-wireguard/src/lib.rs @@ -6,14 +6,14 @@ use self::config::Config; #[cfg(windows)] use futures::channel::mpsc; use futures::future::{abortable, AbortHandle as FutureAbortHandle, BoxFuture, Future}; -#[cfg(target_os = "linux")] -use once_cell::sync::Lazy; #[cfg(target_os = "android")] use std::borrow::Cow; #[cfg(target_os = "linux")] use std::env; #[cfg(windows)] use std::io; +#[cfg(target_os = "linux")] +use std::sync::LazyLock; use std::{ convert::Infallible, net::IpAddr, @@ -193,7 +193,7 @@ impl Drop for ObfuscatorHandle { #[cfg(target_os = "linux")] /// Overrides the preference for the kernel module for WireGuard. -static FORCE_USERSPACE_WIREGUARD: Lazy = Lazy::new(|| { +static FORCE_USERSPACE_WIREGUARD: LazyLock = LazyLock::new(|| { env::var("TALPID_FORCE_USERSPACE_WIREGUARD") .map(|v| v != "0") .unwrap_or(false) diff --git a/talpid-wireguard/src/logging.rs b/talpid-wireguard/src/logging.rs index a4d8c7f240b8..dcb33b11e303 100644 --- a/talpid-wireguard/src/logging.rs +++ b/talpid-wireguard/src/logging.rs @@ -1,8 +1,7 @@ -use once_cell::sync::Lazy; use parking_lot::Mutex; -use std::{collections::HashMap, fmt, fs, io::Write, path::Path}; +use std::{collections::HashMap, fmt, fs, io::Write, path::Path, sync::LazyLock}; -static LOG_MUTEX: Lazy> = Lazy::new(|| Mutex::new(LogState::default())); +static LOG_MUTEX: LazyLock> = LazyLock::new(|| Mutex::new(LogState::default())); #[derive(Default)] struct LogState { diff --git a/talpid-wireguard/src/wireguard_nt/mod.rs b/talpid-wireguard/src/wireguard_nt/mod.rs index 254c503dcff8..35937bcb8c24 100644 --- a/talpid-wireguard/src/wireguard_nt/mod.rs +++ b/talpid-wireguard/src/wireguard_nt/mod.rs @@ -7,7 +7,7 @@ use super::{ use bitflags::bitflags; use futures::SinkExt; use ipnetwork::IpNetwork; -use once_cell::sync::{Lazy, OnceCell}; +use once_cell::sync::OnceCell; #[cfg(daita)] use std::{ffi::c_uchar, path::PathBuf}; use std::{ @@ -21,7 +21,7 @@ use std::{ path::Path, pin::Pin, ptr, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, }; use talpid_types::{BoxedError, ErrorExt}; use talpid_windows::net; @@ -42,8 +42,10 @@ use windows_sys::{ mod daita; static WG_NT_DLL: OnceCell = OnceCell::new(); -static ADAPTER_TYPE: Lazy = Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); -static ADAPTER_ALIAS: Lazy = Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_TYPE: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_ALIAS: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); const ADAPTER_GUID: GUID = GUID { data1: 0x514a3988, @@ -553,7 +555,7 @@ impl Drop for WgNtTunnel { } } -static LOG_CONTEXT: Lazy>> = Lazy::new(|| Mutex::new(None)); +static LOG_CONTEXT: LazyLock>> = LazyLock::new(|| Mutex::new(None)); struct LoggerHandle { dll: &'static WgNtDll, @@ -1159,11 +1161,11 @@ mod tests { p0_allowed_ip_0: WgAllowedIp, } - static WG_PRIVATE_KEY: Lazy = - Lazy::new(wireguard::PrivateKey::new_from_random); - static WG_PUBLIC_KEY: Lazy = - Lazy::new(|| wireguard::PrivateKey::new_from_random().public_key()); - static WG_CONFIG: Lazy = Lazy::new(|| Config { + static WG_PRIVATE_KEY: LazyLock = + LazyLock::new(wireguard::PrivateKey::new_from_random); + static WG_PUBLIC_KEY: LazyLock = + LazyLock::new(|| wireguard::PrivateKey::new_from_random().public_key()); + static WG_CONFIG: LazyLock = LazyLock::new(|| Config { tunnel: wireguard::TunnelConfig { private_key: WG_PRIVATE_KEY.clone(), addresses: vec![], @@ -1185,7 +1187,7 @@ mod tests { quantum_resistant: false, }); - static WG_STRUCT_CONFIG: Lazy = Lazy::new(|| Interface { + static WG_STRUCT_CONFIG: LazyLock = LazyLock::new(|| Interface { interface: WgInterface { flags: WgInterfaceFlag::HAS_PRIVATE_KEY | WgInterfaceFlag::REPLACE_PEERS, listen_port: 0, diff --git a/test/Cargo.lock b/test/Cargo.lock index 7632b6d903b3..9ed097627167 100644 --- a/test/Cargo.lock +++ b/test/Cargo.lock @@ -1858,7 +1858,6 @@ dependencies = [ "log", "mullvad-fs", "mullvad-types", - "once_cell", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -1892,7 +1891,6 @@ dependencies = [ "mullvad-paths", "mullvad-types", "nix 0.23.2", - "once_cell", "parity-tokio-ipc", "prost", "prost-types", @@ -1925,7 +1923,6 @@ dependencies = [ "itertools 0.12.1", "log", "mullvad-types", - "once_cell", "rand 0.8.5", "serde_json", "talpid-types", @@ -1940,7 +1937,6 @@ dependencies = [ "intersection-derive", "ipnetwork", "log", - "once_cell", "regex", "serde", "talpid-types", @@ -3223,7 +3219,6 @@ dependencies = [ "dbus", "libc", "log", - "once_cell", "thiserror", "tokio", ] @@ -3379,7 +3374,6 @@ dependencies = [ "hyper", "hyper-rustls", "log", - "once_cell", "rustls-pemfile 0.2.1", "serde", "serde_json", diff --git a/test/test-manager/src/logging.rs b/test/test-manager/src/logging.rs index 3d1aa1315677..9bc14cb09edc 100644 --- a/test/test-manager/src/logging.rs +++ b/test/test-manager/src/logging.rs @@ -24,7 +24,7 @@ struct StoredRecord { impl Logger { pub fn get_or_init() -> Self { - static LOGGER: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { + static LOGGER: std::sync::LazyLock = std::sync::LazyLock::new(|| { let mut logger = env_logger::Builder::new(); logger.filter_module("h2", log::LevelFilter::Info); logger.filter_module("tower", log::LevelFilter::Info); diff --git a/test/test-manager/src/package.rs b/test/test-manager/src/package.rs index f3fd53567386..36a5bf7431ee 100644 --- a/test/test-manager/src/package.rs +++ b/test/test-manager/src/package.rs @@ -1,11 +1,11 @@ use crate::config::{Architecture, OsType, PackageType, VmConfig}; use anyhow::{Context, Result}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use regex::Regex; use std::path::{Path, PathBuf}; -static VERSION_REGEX: Lazy = - Lazy::new(|| Regex::new(r"\d{4}\.\d+(-beta\d+)?(-dev)?-([0-9a-z])+").unwrap()); +static VERSION_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"\d{4}\.\d+(-beta\d+)?(-dev)?-([0-9a-z])+").unwrap()); #[derive(Debug, Clone)] pub struct Manifest { diff --git a/test/test-manager/src/vm/network/linux.rs b/test/test-manager/src/vm/network/linux.rs index c767a35072c9..985a5bd6b119 100644 --- a/test/test-manager/src/vm/network/linux.rs +++ b/test/test-manager/src/vm/network/linux.rs @@ -1,5 +1,5 @@ use ipnetwork::Ipv4Network; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use std::{ ffi::OsStr, io, @@ -13,8 +13,8 @@ use tokio::{ }; /// (Contained) test subnet for the test runner: 172.29.1.1/24 -pub static TEST_SUBNET: Lazy = - Lazy::new(|| Ipv4Network::new(Ipv4Addr::new(172, 29, 1, 1), 24).unwrap()); +pub static TEST_SUBNET: LazyLock = + LazyLock::new(|| Ipv4Network::new(Ipv4Addr::new(172, 29, 1, 1), 24).unwrap()); /// Range of IPs returned by the DNS server: TEST_SUBNET_DHCP_FIRST to TEST_SUBNET_DHCP_LAST pub const TEST_SUBNET_DHCP_FIRST: Ipv4Addr = Ipv4Addr::new(172, 29, 1, 2); /// Range of IPs returned by the DNS server: TEST_SUBNET_DHCP_FIRST to TEST_SUBNET_DHCP_LAST diff --git a/test/test-rpc/Cargo.toml b/test/test-rpc/Cargo.toml index 24596a09afde..c39a2a19756a 100644 --- a/test/test-rpc/Cargo.toml +++ b/test/test-rpc/Cargo.toml @@ -17,7 +17,6 @@ tokio-serde = { workspace = true } tarpc = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } -once_cell = { workspace = true } bytes = { workspace = true } thiserror = { workspace = true } log = { workspace = true } diff --git a/test/test-rpc/src/net.rs b/test/test-rpc/src/net.rs index 124b4f9ad36f..a646d47011cb 100644 --- a/test/test-rpc/src/net.rs +++ b/test/test-rpc/src/net.rs @@ -1,6 +1,6 @@ use futures::channel::oneshot; use hyper::{Client, Uri}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{net::SocketAddr, time::Duration}; use tokio_rustls::rustls::ClientConfig; @@ -9,7 +9,7 @@ use crate::{AmIMullvad, Error}; const LE_ROOT_CERT: &[u8] = include_bytes!("../../../mullvad-api/le_root_cert.pem"); -static CLIENT_CONFIG: Lazy = Lazy::new(|| { +static CLIENT_CONFIG: LazyLock = LazyLock::new(|| { ClientConfig::builder() .with_safe_default_cipher_suites() .with_safe_default_kx_groups() diff --git a/test/test-runner/src/forward.rs b/test/test-runner/src/forward.rs index a4c80ae18900..450a648c8195 100644 --- a/test/test-runner/src/forward.rs +++ b/test/test-runner/src/forward.rs @@ -1,4 +1,4 @@ -use once_cell::sync::Lazy; +use std::sync::LazyLock; use std::{ collections::HashMap, net::SocketAddr, @@ -10,8 +10,8 @@ use std::{ use test_rpc::net::SockHandleId; use tokio::net::{TcpListener, TcpStream}; -static SERVERS: Lazy>> = - Lazy::new(|| Mutex::new(HashMap::new())); +static SERVERS: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::new())); /// Spawn a TCP forwarder that sends TCP via `via_addr` pub async fn start_server( diff --git a/test/test-runner/src/logging.rs b/test/test-runner/src/logging.rs index ffe21de9855b..b3464feec864 100644 --- a/test/test-runner/src/logging.rs +++ b/test/test-runner/src/logging.rs @@ -1,5 +1,5 @@ use log::{Level, LevelFilter, Metadata, Record, SetLoggerError}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use std::{ ffi::OsStr, path::{Path, PathBuf}, @@ -22,7 +22,7 @@ const EXCLUDE_LOG_FILE_CONTAIN: &str = ".old"; /// Maximum number of lines that each log file may contain const TRUNCATE_LOG_FILE_LINES: usize = 100; -pub static LOGGER: Lazy = Lazy::new(|| { +pub static LOGGER: LazyLock = LazyLock::new(|| { let (sender, listener) = channel(MAX_OUTPUT_BUFFER); StdOutBuffer(Mutex::new(listener), sender) });