mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-01 08:49:16 +00:00
fix magic-dns feature gate
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::common::global_ctx::GlobalCtx;
|
||||
use crate::dns::config::policy::DnsPolicyConfig;
|
||||
use crate::dns::config::zone::ZoneConfig;
|
||||
use crate::dns::config::{DNS_DEFAULT_ADDRESS, DNS_DEFAULT_TLD};
|
||||
use crate::dns::server::DnsServer;
|
||||
use crate::dns::utils::addr::NameServerAddrGroup;
|
||||
use crate::dns::utils::parse;
|
||||
use crate::proto::dns::GetExportConfigResponse;
|
||||
@@ -9,10 +9,10 @@ use derivative::Derivative;
|
||||
use gethostname::gethostname;
|
||||
use hickory_proto::rr::{LowerName, Name};
|
||||
use hickory_proto::xfer::Protocol;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::iter;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Derivative, Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||
#[derivative(Default)]
|
||||
@@ -79,36 +79,21 @@ impl DnsConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[auto_impl::auto_impl(Box, &)]
|
||||
pub trait DnsConfigLoaderExt {
|
||||
fn get_dns(&self) -> DnsConfig;
|
||||
fn set_dns(&self, dns: DnsConfig);
|
||||
|
||||
fn get_fqdn(&self) -> String;
|
||||
fn set_fqdn(&self, fqdn: &str);
|
||||
}
|
||||
|
||||
pub type DnsExportConfig = GetExportConfigResponse;
|
||||
|
||||
pub trait DnsGlobalCtxExt {
|
||||
fn dns_server(&self) -> Option<Arc<DnsServer>>; // TODO: remove this
|
||||
fn set_dns_server(&self, dns: Option<Arc<DnsServer>>); // TODO: remove this
|
||||
fn dns_self_zone(&self) -> ZoneConfig;
|
||||
fn dns_export_config(&self) -> DnsExportConfig;
|
||||
fn dns_iter_zones(&self) -> impl Iterator<Item = ZoneConfig>;
|
||||
}
|
||||
|
||||
impl DnsGlobalCtxExt for GlobalCtx {
|
||||
fn dns_self_zone(&self) -> ZoneConfig {
|
||||
let fqdn = self.config.get_dns().get_fqdn();
|
||||
let ipv4 = self.get_ipv4().map(|ip| ip.address());
|
||||
let ipv6 = self.get_ipv6().map(|ip| ip.address());
|
||||
let ipv6 = ipv6.map(|a| vec![a]).unwrap_or_default();
|
||||
|
||||
ZoneConfig::dedicated(Some(self.get_id()), fqdn.clone(), ipv4, ipv6).unwrap()
|
||||
}
|
||||
|
||||
fn dns_export_config(&self) -> DnsExportConfig {
|
||||
DnsExportConfig {
|
||||
zones: self
|
||||
.dns_iter_zones()
|
||||
.filter(|z| z.policy.export.is_some()) // TODO: check policies of parent zones
|
||||
.map_into()
|
||||
.collect(),
|
||||
fqdn: self.config.get_dns().get_fqdn().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn dns_iter_zones(&self) -> impl Iterator<Item = ZoneConfig> {
|
||||
iter::once(self.dns_self_zone()).chain(self.config.get_dns().zones)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use url::Url;
|
||||
mod dns;
|
||||
pub use dns::*;
|
||||
mod policy;
|
||||
mod zone;
|
||||
pub mod zone;
|
||||
|
||||
pub static DNS_DEFAULT_TLD: LazyLock<LowerName> =
|
||||
LazyLock::new(|| LowerName::from_str("et.net.").unwrap());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::common::global_ctx::{ArcGlobalCtx, GlobalCtxEvent};
|
||||
use crate::common::scoped_task::ScopedTask;
|
||||
use crate::dns::config::{DNS_SERVER_ELECTION_INTERVAL, DNS_SERVER_RPC_ADDR};
|
||||
use crate::dns::config::{DnsGlobalCtxExt, DNS_SERVER_ELECTION_INTERVAL, DNS_SERVER_RPC_ADDR};
|
||||
use crate::dns::peer_mgr::DnsPeerMgr;
|
||||
use crate::dns::server::DnsServer;
|
||||
use crate::instance::instance::ArcNicCtx;
|
||||
@@ -114,14 +113,14 @@ impl DnsNode {
|
||||
|
||||
server.register(&rpc);
|
||||
|
||||
self.global_ctx.set_dns(Some(server.clone()));
|
||||
self.global_ctx.set_dns_server(Some(server.clone()));
|
||||
tokio::join!(
|
||||
self.peer_mgr
|
||||
.add_nic_packet_process_pipeline(Box::new(server.clone())),
|
||||
server.run(token.child_token())
|
||||
);
|
||||
|
||||
self.global_ctx.set_dns(None);
|
||||
self.global_ctx.set_dns_server(None);
|
||||
let _ = self
|
||||
.peer_mgr
|
||||
.remove_nic_packet_process_pipeline(server.id())
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::common::config::ConfigLoader;
|
||||
use crate::common::PeerId;
|
||||
use crate::dns::config::{DnsExportConfig, DnsGlobalCtxExt};
|
||||
use crate::dns::utils::dirty::DirtyFlag;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::common::config::ConfigLoader;
|
||||
use crate::common::global_ctx::ArcGlobalCtx;
|
||||
use crate::dns::node_mgr::DnsNodeMgr;
|
||||
use crate::dns::system;
|
||||
|
||||
@@ -12,7 +12,6 @@ use hickory_proto::runtime::TokioRuntimeProvider;
|
||||
use hickory_proto::udp::UdpClientStream;
|
||||
use tokio::sync::Notify;
|
||||
|
||||
use crate::common::config::ConfigLoader;
|
||||
use crate::common::global_ctx::tests::get_mock_global_ctx;
|
||||
use crate::connector::udp_hole_punch::tests::replace_stun_info_collector;
|
||||
use crate::dns::node::DnsNode;
|
||||
|
||||
@@ -369,7 +369,7 @@ mod tests {
|
||||
let addr = socket.local_addr()?;
|
||||
println!("listening on {}", addr);
|
||||
|
||||
let mut server = ServerFuture::new(catalog.clone());
|
||||
let mut server = ServerFuture::new(catalog);
|
||||
server.register_socket(socket);
|
||||
spawn(async move {
|
||||
if let Err(e) = server.block_until_done().await {
|
||||
|
||||
Reference in New Issue
Block a user