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

@@ -34,6 +34,10 @@ pub trait PeerPacketFilter {
#[auto_impl::auto_impl(Arc)]
pub trait NicPacketFilter {
async fn try_process_packet_from_nic(&self, data: &mut ZCPacket) -> bool;
fn id(&self) -> String {
format!("{:p}", self)
}
}
type BoxPeerPacketFilter = Box<dyn PeerPacketFilter + Send + Sync>;

View File

@@ -2,7 +2,7 @@ use std::{
fmt::Debug,
net::Ipv4Addr,
sync::{Arc, Weak},
time::SystemTime,
time::{Instant, SystemTime},
};
use anyhow::Context;
@@ -120,7 +120,7 @@ pub struct PeerManager {
global_ctx: ArcGlobalCtx,
nic_channel: PacketRecvChan,
tasks: Arc<Mutex<JoinSet<()>>>,
tasks: Mutex<JoinSet<()>>,
packet_recv: Arc<Mutex<Option<PacketRecvChanReceiver>>>,
@@ -249,7 +249,7 @@ impl PeerManager {
global_ctx,
nic_channel,
tasks: Arc::new(Mutex::new(JoinSet::new())),
tasks: Mutex::new(JoinSet::new()),
packet_recv: Arc::new(Mutex::new(Some(packet_recv))),
@@ -735,6 +735,10 @@ impl PeerManager {
self.get_route().list_routes().await
}
pub async fn get_route_peer_info_last_update_time(&self) -> Instant {
self.get_route().get_peer_info_last_update_time().await
}
pub async fn dump_route(&self) -> String {
self.get_route().dump().await
}
@@ -767,6 +771,16 @@ impl PeerManager {
}
}
pub async fn remove_nic_packet_process_pipeline(&self, id: String) -> Result<(), Error> {
let mut pipelines = self.nic_packet_process_pipeline.write().await;
if let Some(pos) = pipelines.iter().position(|x| x.id() == id) {
pipelines.remove(pos);
Ok(())
} else {
Err(Error::NotFound)
}
}
fn get_next_hop_policy(is_first_latency: bool) -> NextHopPolicy {
if is_first_latency {
NextHopPolicy::LeastCost

View File

@@ -1030,6 +1030,8 @@ struct PeerRouteServiceImpl {
cached_local_conn_map: std::sync::Mutex<RouteConnBitmap>,
last_update_my_foreign_network: AtomicCell<Option<std::time::Instant>>,
peer_info_last_update: AtomicCell<std::time::Instant>,
}
impl Debug for PeerRouteServiceImpl {
@@ -1076,6 +1078,8 @@ impl PeerRouteServiceImpl {
cached_local_conn_map: std::sync::Mutex::new(RouteConnBitmap::new()),
last_update_my_foreign_network: AtomicCell::new(None),
peer_info_last_update: AtomicCell::new(std::time::Instant::now()),
}
}
@@ -1225,6 +1229,8 @@ impl PeerRouteServiceImpl {
}
fn update_route_table_and_cached_local_conn_bitmap(&self) {
self.update_peer_info_last_update();
// update route table first because we want to filter out unreachable peers.
self.update_route_table();
@@ -1347,6 +1353,9 @@ impl PeerRouteServiceImpl {
if my_conn_info_updated || my_peer_info_updated {
self.update_foreign_network_owner_map();
}
if my_peer_info_updated {
self.update_peer_info_last_update();
}
my_peer_info_updated || my_conn_info_updated || my_foreign_network_updated
}
@@ -1547,6 +1556,15 @@ impl PeerRouteServiceImpl {
}
return false;
}
fn update_peer_info_last_update(&self) {
tracing::debug!(?self, "update_peer_info_last_update");
self.peer_info_last_update.store(std::time::Instant::now());
}
fn get_peer_info_last_update(&self) -> std::time::Instant {
self.peer_info_last_update.load()
}
}
impl Drop for PeerRouteServiceImpl {
@@ -2195,6 +2213,10 @@ impl Route for PeerRoute {
.get(&peer_id)
.and_then(|x| x.feature_flag.clone())
}
async fn get_peer_info_last_update_time(&self) -> Instant {
self.service_impl.get_peer_info_last_update()
}
}
impl PeerPacketFilter for Arc<PeerRoute> {}

View File

@@ -26,7 +26,7 @@ pub trait PeerRpcManagerTransport: Send + Sync + 'static {
pub struct PeerRpcManager {
tspt: Arc<Box<dyn PeerRpcManagerTransport>>,
bidirect_rpc: BidirectRpcManager,
tasks: Arc<Mutex<JoinSet<()>>>,
tasks: Mutex<JoinSet<()>>,
}
impl std::fmt::Debug for PeerRpcManager {
@@ -43,7 +43,7 @@ impl PeerRpcManager {
tspt: Arc::new(Box::new(tspt)),
bidirect_rpc: BidirectRpcManager::new(),
tasks: Arc::new(Mutex::new(JoinSet::new())),
tasks: Mutex::new(JoinSet::new()),
}
}

View File

@@ -99,6 +99,8 @@ pub trait Route {
async fn get_feature_flag(&self, peer_id: PeerId) -> Option<PeerFeatureFlag>;
async fn get_peer_info_last_update_time(&self) -> std::time::Instant;
async fn dump(&self) -> String {
"this route implementation does not support dump".to_string()
}