magic dns (#813)

This patch implements:

1. A dns server that handles .et.net. zone in local and forward all other queries to system dns server.

2. A dns server instance which is a singleton in one machine, using one specific tcp port to be exclusive with each other. this instance is responsible for config system dns and run the dns server to handle dns queries.

3. A dns client instance that all easytier instance will run one, this instance will try to connect to dns server instance, and update the dns record in the dns server instance.

this pr only implements the system config for windows. linux & mac will do later.
This commit is contained in:
Sijie.Sun
2025-05-16 09:24:24 +08:00
committed by GitHub
parent 99430983bc
commit 28fe6257be
40 changed files with 2800 additions and 229 deletions

View File

@@ -63,7 +63,7 @@ pub struct GlobalCtx {
ip_collector: Arc<IPCollector>,
hostname: String,
hostname: Mutex<String>,
stun_info_collection: Box<dyn StunInfoCollectorTrait>,
@@ -122,7 +122,7 @@ impl GlobalCtx {
ip_collector: Arc::new(IPCollector::new(net_ns, stun_info_collection.clone())),
hostname,
hostname: Mutex::new(hostname),
stun_info_collection: Box::new(stun_info_collection),
@@ -219,7 +219,11 @@ impl GlobalCtx {
}
pub fn get_hostname(&self) -> String {
return self.hostname.clone();
return self.hostname.lock().unwrap().clone();
}
pub fn set_hostname(&self, hostname: String) {
*self.hostname.lock().unwrap() = hostname;
}
pub fn get_stun_info_collector(&self) -> impl StunInfoCollectorTrait + '_ {
@@ -300,7 +304,10 @@ impl GlobalCtx {
#[cfg(test)]
pub mod tests {
use crate::common::{config::TomlConfigLoader, new_peer_id};
use crate::{
common::{config::TomlConfigLoader, new_peer_id, stun::MockStunInfoCollector},
proto::common::NatType,
};
use super::*;
@@ -340,7 +347,12 @@ pub mod tests {
let config_fs = TomlConfigLoader::default();
config_fs.set_inst_name(format!("test_{}", config_fs.get_id()));
config_fs.set_network_identity(network_identy.unwrap_or(NetworkIdentity::default()));
std::sync::Arc::new(GlobalCtx::new(config_fs))
let ctx = Arc::new(GlobalCtx::new(config_fs));
ctx.replace_stun_info_collector(Box::new(MockStunInfoCollector {
udp_nat_type: NatType::Unknown,
}));
ctx
}
pub fn get_mock_global_ctx() -> ArcGlobalCtx {