migrate from lazy_static to once_cell across project
parent
f67457e0a4
commit
ebeac3db76
|
@ -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",
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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<Peer> = vec![Peer {
|
||||
static BASE_PEERS: Lazy<Vec<Peer>> = 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<Cidr> = vec![Cidr {
|
||||
},
|
||||
}]
|
||||
});
|
||||
static BASE_CIDRS: Lazy<Vec<Cidr>> = 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();
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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<Peer>) {
|
||||
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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
static PEER_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap());
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DatabasePeer {
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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<ColorfulTheme> = Lazy::new(ColorfulTheme::default);
|
||||
|
||||
pub fn ensure_interactive(prompt: &str) -> Result<(), io::Error> {
|
||||
if atty::is(atty::Stream::Stdin) {
|
||||
|
|
|
@ -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<Timestring> 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();
|
||||
}
|
||||
static HOSTNAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^([a-z0-9]-?)*[a-z0-9]$").unwrap());
|
||||
|
||||
impl Hostname {
|
||||
pub fn is_valid(name: &str) -> bool {
|
||||
|
|
Loading…
Reference in New Issue