system: rename SystemConfig to SystemConfigurator, add Clone to SystemConfigurator

This commit is contained in:
Luna Yao
2026-02-23 05:24:29 +01:00
parent 4ed9cbc4a1
commit 918c9b9174
4 changed files with 15 additions and 13 deletions
+4 -4
View File
@@ -6,13 +6,13 @@ use std::{
path::Path,
};
use super::{OSConfig, SystemConfig};
use super::{OSConfig, SystemConfigurator};
const MAC_RESOLVER_FILE_HEADER: &str = "# Added by easytier\n";
const ETC_RESOLVER: &str = "/etc/resolver";
const ETC_RESOLV_CONF: &str = "/etc/resolv.conf";
#[derive(Default)]
#[derive(Clone, Default)]
pub struct DarwinConfigurator {}
impl DarwinConfigurator {
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<()> {
self.do_set_dns(cfg)
}
fn close(&self) -> io::Result<()> {
fn clean(&self) -> io::Result<()> {
self.do_close()
}
}
+2 -2
View File
@@ -14,7 +14,7 @@ pub struct OSConfig {
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 close(&self) -> std::io::Result<()>;
fn clean(&self) -> std::io::Result<()>;
}
+5 -3
View File
@@ -6,7 +6,7 @@ use winreg::RegKey;
use crate::common::ifcfg::RegistryManager;
use super::{OSConfig, SystemConfig};
use super::{OSConfig, SystemConfigurator};
pub fn is_windows_10_or_better() -> io::Result<bool> {
let hklm = winreg::enums::HKEY_LOCAL_MACHINE;
@@ -19,6 +19,7 @@ pub fn is_windows_10_or_better() -> io::Result<bool> {
}
// 假设 interface_guid 是你的网络接口 GUID
#[derive(Clone)]
pub struct InterfaceControl {
interface_guid: String,
}
@@ -125,6 +126,7 @@ impl InterfaceControl {
}
}
#[derive(Clone)]
pub struct WindowsDNSManager {
tun_dev_name: String,
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<()> {
self.set_primary_dns(
&cfg.nameservers
@@ -158,7 +160,7 @@ impl SystemConfig for WindowsDNSManager {
Ok(())
}
fn close(&self) -> io::Result<()> {
fn clean(&self) -> io::Result<()> {
Ok(())
}
}
@@ -11,7 +11,7 @@ use super::{
server::Server,
MAGIC_DNS_INSTANCE_ADDR,
};
use crate::dns::system::{OSConfig, SystemConfig};
use crate::dns::system::{OSConfig, SystemConfigurator};
use crate::{
common::{
ifcfg::{IfConfiger, IfConfiguerTrait},
@@ -69,7 +69,7 @@ pub(super) struct MagicDnsServerInstanceData {
// zone -> (tunnel remote addr -> route)
route_infos: DashMap<String, MultiMap<url::Url, Route>>,
system_config: Option<Box<dyn SystemConfig>>,
system_config: Option<Box<dyn SystemConfigurator>>,
}
impl MagicDnsServerInstanceData {
@@ -492,7 +492,7 @@ pub struct MagicDnsServerInstance {
fn get_system_config(
_tun_name: Option<&str>,
) -> Result<Option<Box<dyn SystemConfig>>, anyhow::Error> {
) -> Result<Option<Box<dyn SystemConfigurator>>, anyhow::Error> {
#[cfg(target_os = "windows")]
{
use crate::dns::system::windows::WindowsDNSManager;
@@ -583,7 +583,7 @@ impl MagicDnsServerInstance {
pub async fn clean_env(&self) {
if let Some(configer) = &self.data.system_config {
let ret = configer.close();
let ret = configer.clean();
if let Err(e) = ret {
tracing::error!("Failed to close system config: {:?}", e);
}