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