diff --git a/Cargo.lock b/Cargo.lock index 97f7069..425713a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,8 +141,8 @@ dependencies = [ "hostsfile", "indoc", "ipnet", - "lazy_static", "log", + "once_cell", "regex", "serde", "serde_json", @@ -920,10 +920,10 @@ dependencies = [ "hyper", "indoc", "ipnet", - "lazy_static", "libc", "libsqlite3-sys", "log", + "once_cell", "parking_lot", "pretty_env_logger", "publicip", @@ -953,7 +953,6 @@ dependencies = [ "dialoguer", "indoc", "ipnet", - "lazy_static", "libc", "log", "netlink-packet-core", @@ -961,6 +960,7 @@ dependencies = [ "netlink-request", "netlink-sys", "nix", + "once_cell", "publicip", "regex", "serde", diff --git a/client/Cargo.toml b/client/Cargo.toml index 9e94416..1c16c40 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -22,7 +22,6 @@ dialoguer = { version = "0.10", default-features = false } hostsfile = { path = "../hostsfile" } indoc = "1" ipnet = { version = "2.4", features = ["serde"] } -lazy_static = "1" log = "0.4" regex = { version = "1", default-features = false, features = ["std"] } serde = { version = "1.0", features = ["derive"] } @@ -32,6 +31,7 @@ ureq = { version = "2", default-features = false, features = ["json"] } wireguard-control = { path = "../wireguard-control" } [dev-dependencies] +once_cell = "1.17.1" tempfile = "3" [package.metadata.deb] diff --git a/client/src/data_store.rs b/client/src/data_store.rs index f15d024..20efc47 100644 --- a/client/src/data_store.rs +++ b/client/src/data_store.rs @@ -144,10 +144,10 @@ impl DataStore { #[cfg(test)] mod tests { use super::*; - use lazy_static::lazy_static; + use once_cell::sync::Lazy; use shared::{Cidr, CidrContents, Peer, PeerContents}; - lazy_static! { - static ref BASE_PEERS: Vec = vec![Peer { + static BASE_PEERS: Lazy> = Lazy::new(|| { + vec![Peer { id: 0, contents: PeerContents { name: "blah".parse().unwrap(), @@ -161,17 +161,19 @@ mod tests { persistent_keepalive_interval: None, invite_expires: None, candidates: vec![], - } - }]; - static ref BASE_CIDRS: Vec = vec![Cidr { + }, + }] + }); + static BASE_CIDRS: Lazy> = Lazy::new(|| { + vec![Cidr { id: 1, contents: CidrContents { name: "cidr".to_string(), cidr: "10.0.0.0/24".parse().unwrap(), - parent: None - } - }]; - } + parent: None, + }, + }] + }); fn setup_basic_store(dir: &Path) { let mut store = DataStore::open_with_path(dir.join("peer_store.json"), true).unwrap(); diff --git a/server/Cargo.toml b/server/Cargo.toml index 31eec0a..d7676dd 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -25,10 +25,10 @@ dialoguer = { version = "0.10", default-features = false } hyper = { version = "0.14", default-features = false, features = ["http1", "server", "runtime", "stream"] } indoc = "1" ipnet = { version = "2.4", features = ["serde"] } -lazy_static = "1" libc = "0.2" libsqlite3-sys = "0.25" log = "0.4" +once_cell = "1.17.1" parking_lot = "0.12" pretty_env_logger = "0.4" publicip = { path = "../publicip" } diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index afed99e..f7db98f 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -8,7 +8,7 @@ pub mod user; /// Inject the collected endpoints from the WG interface into a list of peers. /// This is essentially what adds NAT holepunching functionality. pub fn inject_endpoints(session: &Session, peers: &mut Vec) { - for mut peer in peers { + for peer in peers { if peer.contents.endpoint.is_none() { if let Some(endpoint) = session.context.endpoints.read().get(&peer.public_key) { peer.contents.endpoint = Some(endpoint.to_owned().into()); diff --git a/server/src/db/peer.rs b/server/src/db/peer.rs index c14c84c..1dd6b40 100644 --- a/server/src/db/peer.rs +++ b/server/src/db/peer.rs @@ -1,6 +1,6 @@ use super::DatabaseCidr; use crate::ServerError; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use regex::Regex; use rusqlite::{params, types::Type, Connection}; use shared::{IpNetExt, Peer, PeerContents, PERSISTENT_KEEPALIVE_INTERVAL_SECS}; @@ -42,11 +42,9 @@ pub static COLUMNS: &[&str] = &[ "candidates", ]; -lazy_static! { - /// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames. - /// Note that the full length also must be maximum 63 characters, which this regex does not check. - static ref PEER_NAME_REGEX: Regex = Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap(); -} +/// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames. +/// Note that the full length also must be maximum 63 characters, which this regex does not check. +static PEER_NAME_REGEX: Lazy = Lazy::new(|| Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap()); #[derive(Debug)] pub struct DatabasePeer { diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 3ecad0d..e84e3d2 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -14,9 +14,9 @@ colored = "2.0" dialoguer = { version = "0.10", default-features = false } indoc = "1" ipnet = { version = "2.4", features = ["serde"] } -lazy_static = "1" libc = "0.2" log = "0.4" +once_cell = "1.17.1" publicip = { path = "../publicip" } regex = "1" serde = { version = "1", features = ["derive"] } diff --git a/shared/src/prompts.rs b/shared/src/prompts.rs index 1b685ef..2a999f2 100644 --- a/shared/src/prompts.rs +++ b/shared/src/prompts.rs @@ -8,7 +8,7 @@ use anyhow::anyhow; use colored::*; use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select}; use ipnet::IpNet; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use publicip::Preference; use std::{ fmt::{Debug, Display}, @@ -20,9 +20,7 @@ use std::{ }; use wireguard_control::{InterfaceName, KeyPair}; -lazy_static! { - pub static ref THEME: ColorfulTheme = ColorfulTheme::default(); -} +pub static THEME: Lazy = Lazy::new(ColorfulTheme::default); pub fn ensure_interactive(prompt: &str) -> Result<(), io::Error> { if atty::is(atty::Stream::Stdin) { diff --git a/shared/src/types.rs b/shared/src/types.rs index 446de3f..7a33bc4 100644 --- a/shared/src/types.rs +++ b/shared/src/types.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Error}; use clap::Args; use ipnet::IpNet; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use std::{ @@ -758,11 +758,9 @@ impl From for Duration { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Hostname(String); -lazy_static! { - /// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames. - /// Note that the full length also must be maximum 63 characters, which this regex does not check. - static ref HOSTNAME_REGEX: Regex = Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap(); -} +/// Regex to match the requirements of hostname(7), needed to have peers also be reachable hostnames. +/// Note that the full length also must be maximum 63 characters, which this regex does not check. +static HOSTNAME_REGEX: Lazy = Lazy::new(|| Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap()); impl Hostname { pub fn is_valid(name: &str) -> bool {