mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
system: rename SystemConfig to SystemConfigurator, add Clone to SystemConfigurator
This commit is contained in:
@@ -6,13 +6,13 @@ use std::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{OSConfig, SystemConfig};
|
use super::{OSConfig, SystemConfigurator};
|
||||||
|
|
||||||
const MAC_RESOLVER_FILE_HEADER: &str = "# Added by easytier\n";
|
const MAC_RESOLVER_FILE_HEADER: &str = "# Added by easytier\n";
|
||||||
const ETC_RESOLVER: &str = "/etc/resolver";
|
const ETC_RESOLVER: &str = "/etc/resolver";
|
||||||
const ETC_RESOLV_CONF: &str = "/etc/resolv.conf";
|
const ETC_RESOLV_CONF: &str = "/etc/resolv.conf";
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct DarwinConfigurator {}
|
pub struct DarwinConfigurator {}
|
||||||
impl DarwinConfigurator {
|
impl DarwinConfigurator {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
@@ -104,12 +104,12 @@ impl DarwinConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemConfig for DarwinConfigurator {
|
impl SystemConfigurator for DarwinConfigurator {
|
||||||
fn set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
fn set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
||||||
self.do_set_dns(cfg)
|
self.do_set_dns(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close(&self) -> io::Result<()> {
|
fn clean(&self) -> io::Result<()> {
|
||||||
self.do_close()
|
self.do_close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ pub struct OSConfig {
|
|||||||
pub match_domains: Vec<String>,
|
pub match_domains: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SystemConfig: Send + Sync {
|
pub trait SystemConfigurator: Send + Sync + Clone {
|
||||||
fn set_dns(&self, cfg: &OSConfig) -> std::io::Result<()>;
|
fn set_dns(&self, cfg: &OSConfig) -> std::io::Result<()>;
|
||||||
fn close(&self) -> std::io::Result<()>;
|
fn clean(&self) -> std::io::Result<()>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use winreg::RegKey;
|
|||||||
|
|
||||||
use crate::common::ifcfg::RegistryManager;
|
use crate::common::ifcfg::RegistryManager;
|
||||||
|
|
||||||
use super::{OSConfig, SystemConfig};
|
use super::{OSConfig, SystemConfigurator};
|
||||||
|
|
||||||
pub fn is_windows_10_or_better() -> io::Result<bool> {
|
pub fn is_windows_10_or_better() -> io::Result<bool> {
|
||||||
let hklm = winreg::enums::HKEY_LOCAL_MACHINE;
|
let hklm = winreg::enums::HKEY_LOCAL_MACHINE;
|
||||||
@@ -19,6 +19,7 @@ pub fn is_windows_10_or_better() -> io::Result<bool> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 假设 interface_guid 是你的网络接口 GUID
|
// 假设 interface_guid 是你的网络接口 GUID
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct InterfaceControl {
|
pub struct InterfaceControl {
|
||||||
interface_guid: String,
|
interface_guid: String,
|
||||||
}
|
}
|
||||||
@@ -125,6 +126,7 @@ impl InterfaceControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct WindowsDNSManager {
|
pub struct WindowsDNSManager {
|
||||||
tun_dev_name: String,
|
tun_dev_name: String,
|
||||||
interface_control: InterfaceControl,
|
interface_control: InterfaceControl,
|
||||||
@@ -146,7 +148,7 @@ impl WindowsDNSManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemConfig for WindowsDNSManager {
|
impl SystemConfigurator for WindowsDNSManager {
|
||||||
fn set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
fn set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
||||||
self.set_primary_dns(
|
self.set_primary_dns(
|
||||||
&cfg.nameservers
|
&cfg.nameservers
|
||||||
@@ -158,7 +160,7 @@ impl SystemConfig for WindowsDNSManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close(&self) -> io::Result<()> {
|
fn clean(&self) -> io::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use super::{
|
|||||||
server::Server,
|
server::Server,
|
||||||
MAGIC_DNS_INSTANCE_ADDR,
|
MAGIC_DNS_INSTANCE_ADDR,
|
||||||
};
|
};
|
||||||
use crate::dns::system::{OSConfig, SystemConfig};
|
use crate::dns::system::{OSConfig, SystemConfigurator};
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
ifcfg::{IfConfiger, IfConfiguerTrait},
|
ifcfg::{IfConfiger, IfConfiguerTrait},
|
||||||
@@ -69,7 +69,7 @@ pub(super) struct MagicDnsServerInstanceData {
|
|||||||
// zone -> (tunnel remote addr -> route)
|
// zone -> (tunnel remote addr -> route)
|
||||||
route_infos: DashMap<String, MultiMap<url::Url, Route>>,
|
route_infos: DashMap<String, MultiMap<url::Url, Route>>,
|
||||||
|
|
||||||
system_config: Option<Box<dyn SystemConfig>>,
|
system_config: Option<Box<dyn SystemConfigurator>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MagicDnsServerInstanceData {
|
impl MagicDnsServerInstanceData {
|
||||||
@@ -492,7 +492,7 @@ pub struct MagicDnsServerInstance {
|
|||||||
|
|
||||||
fn get_system_config(
|
fn get_system_config(
|
||||||
_tun_name: Option<&str>,
|
_tun_name: Option<&str>,
|
||||||
) -> Result<Option<Box<dyn SystemConfig>>, anyhow::Error> {
|
) -> Result<Option<Box<dyn SystemConfigurator>>, anyhow::Error> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
use crate::dns::system::windows::WindowsDNSManager;
|
use crate::dns::system::windows::WindowsDNSManager;
|
||||||
@@ -583,7 +583,7 @@ impl MagicDnsServerInstance {
|
|||||||
|
|
||||||
pub async fn clean_env(&self) {
|
pub async fn clean_env(&self) {
|
||||||
if let Some(configer) = &self.data.system_config {
|
if let Some(configer) = &self.data.system_config {
|
||||||
let ret = configer.close();
|
let ret = configer.clean();
|
||||||
if let Err(e) = ret {
|
if let Err(e) = ret {
|
||||||
tracing::error!("Failed to close system config: {:?}", e);
|
tracing::error!("Failed to close system config: {:?}", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user