mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 09:09:17 +00:00
store DnsServer in GlobalCtx, load routes from DnsServer in ProxyCidrsMonitor
This commit is contained in:
@@ -32,7 +32,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use crossbeam::atomic::AtomicCell;
|
use crossbeam::atomic::AtomicCell;
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
|
use parking_lot::RwLock;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
|
use crate::dns::server::DnsServer;
|
||||||
use socket2::Protocol;
|
use socket2::Protocol;
|
||||||
|
|
||||||
pub type NetworkIdentity = crate::common::config::NetworkIdentity;
|
pub type NetworkIdentity = crate::common::config::NetworkIdentity;
|
||||||
@@ -202,6 +204,8 @@ pub struct GlobalCtx {
|
|||||||
|
|
||||||
hostname: Mutex<String>,
|
hostname: Mutex<String>,
|
||||||
|
|
||||||
|
dns: RwLock<Option<Arc<DnsServer>>>,
|
||||||
|
|
||||||
stun_info_collection: Mutex<Arc<dyn StunInfoCollectorTrait>>,
|
stun_info_collection: Mutex<Arc<dyn StunInfoCollectorTrait>>,
|
||||||
|
|
||||||
running_listeners: Mutex<Vec<url::Url>>,
|
running_listeners: Mutex<Vec<url::Url>>,
|
||||||
@@ -298,6 +302,8 @@ impl GlobalCtx {
|
|||||||
stun_info_collector.clone(),
|
stun_info_collector.clone(),
|
||||||
)))),
|
)))),
|
||||||
|
|
||||||
|
dns: RwLock::new(None),
|
||||||
|
|
||||||
hostname: Mutex::new(hostname),
|
hostname: Mutex::new(hostname),
|
||||||
|
|
||||||
stun_info_collection: Mutex::new(stun_info_collector),
|
stun_info_collection: Mutex::new(stun_info_collector),
|
||||||
@@ -416,6 +422,14 @@ impl GlobalCtx {
|
|||||||
self.ip_collector.lock().unwrap().as_ref().unwrap().clone()
|
self.ip_collector.lock().unwrap().as_ref().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_dns(&self) -> Option<Arc<DnsServer>> {
|
||||||
|
self.dns.read().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_dns(&self, dns: Option<Arc<DnsServer>>) {
|
||||||
|
*self.dns.write() = dns;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_hostname(&self) -> String {
|
pub fn get_hostname(&self) -> String {
|
||||||
return self.hostname.lock().unwrap().clone();
|
return self.hostname.lock().unwrap().clone();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ mod node;
|
|||||||
mod node_mgr;
|
mod node_mgr;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
mod peer_mgr;
|
mod peer_mgr;
|
||||||
mod server;
|
pub mod server;
|
||||||
mod utils;
|
mod utils;
|
||||||
pub mod zone;
|
pub mod zone;
|
||||||
|
|||||||
@@ -68,12 +68,16 @@ impl DnsNode {
|
|||||||
|
|
||||||
let server = Arc::new(DnsServer::new(self.peer_mgr.clone(), rpc));
|
let server = Arc::new(DnsServer::new(self.peer_mgr.clone(), rpc));
|
||||||
|
|
||||||
|
self.peer_mgr
|
||||||
|
.get_global_ctx_ref()
|
||||||
|
.set_dns(Some(server.clone()));
|
||||||
tokio::join!(
|
tokio::join!(
|
||||||
self.peer_mgr
|
self.peer_mgr
|
||||||
.add_nic_packet_process_pipeline(Box::new(server.clone())),
|
.add_nic_packet_process_pipeline(Box::new(server.clone())),
|
||||||
server.run()
|
server.run()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
self.peer_mgr.get_global_ctx_ref().set_dns(None);
|
||||||
let _ = self
|
let _ = self
|
||||||
.peer_mgr
|
.peer_mgr
|
||||||
.remove_nic_packet_process_pipeline(server.id())
|
.remove_nic_packet_process_pipeline(server.id())
|
||||||
|
|||||||
@@ -177,8 +177,8 @@ impl DnsServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn routes(&self) -> HashSet<IpAddr> {
|
pub fn addresses(&self) -> HashSet<SocketAddr> {
|
||||||
self.addresses.read().iter().map(|a| a.addr.ip()).collect()
|
self.addresses.read().iter().map(|a| a.addr).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn reload_listeners(
|
async fn reload_listeners(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
use std::net::IpAddr;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
@@ -54,6 +55,13 @@ impl ProxyCidrsMonitor {
|
|||||||
proxy_cidrs = routes.into_iter().collect();
|
proxy_cidrs = routes.into_iter().collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(dns) = global_ctx.get_dns() {
|
||||||
|
proxy_cidrs.extend(dns.addresses().into_iter().filter_map(|a| match a.ip() {
|
||||||
|
IpAddr::V4(ip) => Some(cidr::Ipv4Cidr::new_host(ip)),
|
||||||
|
_ => None,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate diff
|
// Calculate diff
|
||||||
if cur_proxy_cidrs == &proxy_cidrs {
|
if cur_proxy_cidrs == &proxy_cidrs {
|
||||||
return (proxy_cidrs, Vec::new(), Vec::new());
|
return (proxy_cidrs, Vec::new(), Vec::new());
|
||||||
|
|||||||
Reference in New Issue
Block a user