1use std::{
2 net::{IpAddr, Ipv4Addr, SocketAddr},
3 sync::LazyLock,
4};
5
6pub const APP_NAME: &str = "SideDNS";
7pub const APP_DIR_NAME: &str = APP_NAME;
8pub const DAEMON_ENV: &str = "SIDEDNS_DAEMON_PROCESS";
9pub const CERT_NAME: &str = "SideDNS Local CA";
10
11pub const DNS_RECORD_TTL_SECONDS: u32 = 10;
12
13pub const DNS_LISTEN_ADDR: SocketAddr =
14 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 53, 53)), 53);
15
16pub const PROXY_LISTEN_ADDR: SocketAddr =
17 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 42)), 80);
18
19#[cfg(target_os = "windows")]
20pub const IPC_SOCKET_PATH: &str = r"\\.\pipe\sidedns";
21
22#[cfg(not(target_os = "windows"))]
23pub const IPC_SOCKET_PATH: &str = "/tmp/sidedns.sock";
24
25pub static DOMAIN_REGEX: LazyLock<regex::Regex> = LazyLock::new(|| {
26 regex::Regex::new(
27 r"(?i)^(?:localhost|(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63})$",
28 )
29 .unwrap()
30});
31
32pub static APP_DATA_DIR: LazyLock<std::path::PathBuf> = LazyLock::new(|| {
33 dirs::data_local_dir()
34 .unwrap_or_else(|| std::path::PathBuf::from("."))
35 .join(APP_DIR_NAME.to_lowercase())
36});
37
38pub static ROOT_CERTIFICATE_DIR: LazyLock<std::path::PathBuf> =
39 LazyLock::new(|| APP_DATA_DIR.join("Certificates"));