mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-01 00:39:24 +00:00
fix magic-dns feature gate
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
use super::env_parser;
|
||||||
|
use crate::{
|
||||||
|
common::stun::StunInfoCollector,
|
||||||
|
proto::{
|
||||||
|
acl::Acl,
|
||||||
|
common::{CompressionAlgoPb, PortForwardConfigPb, SecureModeConfig, SocketType},
|
||||||
|
},
|
||||||
|
tunnel::generate_digest_from_str,
|
||||||
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use base64::{prelude::BASE64_STANDARD, Engine as _};
|
use base64::{prelude::BASE64_STANDARD, Engine as _};
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
@@ -13,23 +22,15 @@ use std::{
|
|||||||
use strum::{Display, EnumString, VariantArray};
|
use strum::{Display, EnumString, VariantArray};
|
||||||
use tokio::io::AsyncReadExt as _;
|
use tokio::io::AsyncReadExt as _;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
common::stun::StunInfoCollector,
|
|
||||||
dns::config::DnsConfig,
|
|
||||||
proto::{
|
|
||||||
acl::Acl,
|
|
||||||
common::{CompressionAlgoPb, PortForwardConfigPb, SecureModeConfig, SocketType},
|
|
||||||
},
|
|
||||||
tunnel::generate_digest_from_str,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::env_parser;
|
|
||||||
|
|
||||||
pub type Flags = crate::proto::common::FlagsInConfig;
|
pub type Flags = crate::proto::common::FlagsInConfig;
|
||||||
|
|
||||||
pub fn gen_default_flags() -> Flags {
|
pub fn gen_default_flags() -> Flags {
|
||||||
#[allow(deprecated)]
|
|
||||||
Flags {
|
Flags {
|
||||||
|
#[allow(deprecated)]
|
||||||
|
quic_listen_port: u32::MAX,
|
||||||
|
#[allow(deprecated)]
|
||||||
|
tld_dns_zone: "".to_string(),
|
||||||
|
|
||||||
default_protocol: "tcp".to_string(),
|
default_protocol: "tcp".to_string(),
|
||||||
dev_name: "".to_string(),
|
dev_name: "".to_string(),
|
||||||
enable_encryption: true,
|
enable_encryption: true,
|
||||||
@@ -64,9 +65,6 @@ pub fn gen_default_flags() -> Flags {
|
|||||||
multi_thread_count: 2,
|
multi_thread_count: 2,
|
||||||
encryption_algorithm: EncryptionAlgorithm::default().to_string(),
|
encryption_algorithm: EncryptionAlgorithm::default().to_string(),
|
||||||
disable_sym_hole_punching: false,
|
disable_sym_hole_punching: false,
|
||||||
tld_dns_zone: "".to_string(),
|
|
||||||
|
|
||||||
quic_listen_port: u32::MAX,
|
|
||||||
need_p2p: false,
|
need_p2p: false,
|
||||||
instance_recv_bps_limit: u64::MAX,
|
instance_recv_bps_limit: u64::MAX,
|
||||||
}
|
}
|
||||||
@@ -119,8 +117,17 @@ impl Default for EncryptionAlgorithm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "magic-dns")] {
|
||||||
|
use crate::dns::config::{DnsConfig, DnsConfigLoaderExt};
|
||||||
|
} else {
|
||||||
|
#[auto_impl::auto_impl(Box, &)]
|
||||||
|
pub trait DnsConfigLoaderExt {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[auto_impl::auto_impl(Box, &)]
|
#[auto_impl::auto_impl(Box, &)]
|
||||||
pub trait ConfigLoader: Send + Sync {
|
pub trait ConfigLoader: Send + Sync + DnsConfigLoaderExt {
|
||||||
fn get_id(&self) -> uuid::Uuid;
|
fn get_id(&self) -> uuid::Uuid;
|
||||||
fn set_id(&self, id: uuid::Uuid);
|
fn set_id(&self, id: uuid::Uuid);
|
||||||
|
|
||||||
@@ -203,15 +210,9 @@ pub trait ConfigLoader: Send + Sync {
|
|||||||
}
|
}
|
||||||
fn set_credential_file(&self, _path: Option<std::path::PathBuf>) {}
|
fn set_credential_file(&self, _path: Option<std::path::PathBuf>) {}
|
||||||
|
|
||||||
fn get_dns(&self) -> DnsConfig;
|
|
||||||
fn set_dns(&self, dns: DnsConfig);
|
|
||||||
|
|
||||||
fn get_hostname(&self) -> String;
|
fn get_hostname(&self) -> String;
|
||||||
fn set_hostname(&self, hostname: &str);
|
fn set_hostname(&self, hostname: &str);
|
||||||
|
|
||||||
fn get_fqdn(&self) -> String;
|
|
||||||
fn set_fqdn(&self, fqdn: &str);
|
|
||||||
|
|
||||||
fn dump(&self) -> String;
|
fn dump(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,6 +451,7 @@ struct Config {
|
|||||||
peer: Option<Vec<PeerConfig>>,
|
peer: Option<Vec<PeerConfig>>,
|
||||||
proxy_network: Option<Vec<ProxyNetworkConfig>>,
|
proxy_network: Option<Vec<ProxyNetworkConfig>>,
|
||||||
|
|
||||||
|
#[cfg(feature = "magic-dns")]
|
||||||
dns: DnsConfig,
|
dns: DnsConfig,
|
||||||
|
|
||||||
vpn_portal_config: Option<VpnPortalConfig>,
|
vpn_portal_config: Option<VpnPortalConfig>,
|
||||||
@@ -535,6 +537,28 @@ impl TomlConfigLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DnsConfigLoaderExt for TomlConfigLoader {
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "magic-dns")] {
|
||||||
|
fn get_dns(&self) -> DnsConfig {
|
||||||
|
self.config.lock().unwrap().dns.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_dns(&self, dns: DnsConfig) {
|
||||||
|
self.config.lock().unwrap().dns = dns;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_fqdn(&self) -> String {
|
||||||
|
self.config.lock().unwrap().dns.get_fqdn().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_fqdn(&self, fqdn: &str) {
|
||||||
|
self.config.lock().unwrap().dns.set_fqdn(fqdn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ConfigLoader for TomlConfigLoader {
|
impl ConfigLoader for TomlConfigLoader {
|
||||||
fn get_id(&self) -> uuid::Uuid {
|
fn get_id(&self) -> uuid::Uuid {
|
||||||
let mut locked_config = self.config.lock().unwrap();
|
let mut locked_config = self.config.lock().unwrap();
|
||||||
@@ -849,14 +873,6 @@ impl ConfigLoader for TomlConfigLoader {
|
|||||||
self.config.lock().unwrap().credential_file = path;
|
self.config.lock().unwrap().credential_file = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dns(&self) -> DnsConfig {
|
|
||||||
self.config.lock().unwrap().dns.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_dns(&self, dns: DnsConfig) {
|
|
||||||
self.config.lock().unwrap().dns = dns;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_hostname(&self) -> String {
|
fn get_hostname(&self) -> String {
|
||||||
self.config.lock().unwrap().dns.get_name().to_string()
|
self.config.lock().unwrap().dns.get_name().to_string()
|
||||||
}
|
}
|
||||||
@@ -865,14 +881,6 @@ impl ConfigLoader for TomlConfigLoader {
|
|||||||
self.config.lock().unwrap().dns.set_name(hostname);
|
self.config.lock().unwrap().dns.set_name(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fqdn(&self) -> String {
|
|
||||||
self.config.lock().unwrap().dns.get_fqdn().to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_fqdn(&self, fqdn: &str) {
|
|
||||||
self.config.lock().unwrap().dns.set_fqdn(fqdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dump(&self) -> String {
|
fn dump(&self) -> String {
|
||||||
let default_flags_json = serde_json::to_string(&gen_default_flags()).unwrap();
|
let default_flags_json = serde_json::to_string(&gen_default_flags()).unwrap();
|
||||||
let default_flags_hashmap =
|
let default_flags_hashmap =
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::{hash_map::DefaultHasher, HashMap},
|
collections::{hash_map::DefaultHasher, HashMap},
|
||||||
hash::Hasher,
|
hash::Hasher,
|
||||||
|
iter,
|
||||||
net::{IpAddr, SocketAddr},
|
net::{IpAddr, SocketAddr},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
@@ -30,11 +31,16 @@ use crate::{
|
|||||||
},
|
},
|
||||||
tunnel::matches_protocol,
|
tunnel::matches_protocol,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "magic-dns")]
|
||||||
|
use crate::dns::{
|
||||||
|
config::{DnsExportConfig, DnsGlobalCtxExt},
|
||||||
|
server::DnsServer,
|
||||||
|
};
|
||||||
use crossbeam::atomic::AtomicCell;
|
use crossbeam::atomic::AtomicCell;
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
|
use itertools::Itertools;
|
||||||
use parking_lot::RwLock;
|
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;
|
||||||
@@ -204,7 +210,8 @@ pub struct GlobalCtx {
|
|||||||
|
|
||||||
hostname: Mutex<String>,
|
hostname: Mutex<String>,
|
||||||
|
|
||||||
dns: RwLock<Option<Arc<DnsServer>>>,
|
#[cfg(feature = "magic-dns")]
|
||||||
|
dns_server: RwLock<Option<Arc<DnsServer>>>,
|
||||||
|
|
||||||
stun_info_collection: Mutex<Arc<dyn StunInfoCollectorTrait>>,
|
stun_info_collection: Mutex<Arc<dyn StunInfoCollectorTrait>>,
|
||||||
|
|
||||||
@@ -239,7 +246,7 @@ impl std::fmt::Debug for GlobalCtx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ArcGlobalCtx = std::sync::Arc<GlobalCtx>;
|
pub type ArcGlobalCtx = Arc<GlobalCtx>;
|
||||||
|
|
||||||
impl GlobalCtx {
|
impl GlobalCtx {
|
||||||
fn derive_feature_flags(flags: &Flags, current: Option<PeerFeatureFlag>) -> PeerFeatureFlag {
|
fn derive_feature_flags(flags: &Flags, current: Option<PeerFeatureFlag>) -> PeerFeatureFlag {
|
||||||
@@ -302,7 +309,8 @@ impl GlobalCtx {
|
|||||||
stun_info_collector.clone(),
|
stun_info_collector.clone(),
|
||||||
)))),
|
)))),
|
||||||
|
|
||||||
dns: RwLock::new(None),
|
#[cfg(feature = "magic-dns")]
|
||||||
|
dns_server: RwLock::new(None),
|
||||||
|
|
||||||
hostname: Mutex::new(hostname),
|
hostname: Mutex::new(hostname),
|
||||||
|
|
||||||
@@ -422,14 +430,6 @@ 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();
|
||||||
}
|
}
|
||||||
@@ -680,6 +680,47 @@ impl GlobalCtx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "magic-dns")]
|
||||||
|
impl DnsGlobalCtxExt for GlobalCtx {
|
||||||
|
fn dns_server(&self) -> Option<Arc<DnsServer>> {
|
||||||
|
self.dns_server.read().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_dns_server(&self, dns: Option<Arc<DnsServer>>) {
|
||||||
|
*self.dns_server.write() = dns;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dns_self_zone(&self) -> crate::dns::config::zone::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();
|
||||||
|
|
||||||
|
crate::dns::config::zone::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 = crate::dns::config::zone::ZoneConfig> {
|
||||||
|
iter::once(self.dns_self_zone()).chain(self.config.get_dns().zones)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::common::global_ctx::GlobalCtx;
|
|
||||||
use crate::dns::config::policy::DnsPolicyConfig;
|
use crate::dns::config::policy::DnsPolicyConfig;
|
||||||
use crate::dns::config::zone::ZoneConfig;
|
use crate::dns::config::zone::ZoneConfig;
|
||||||
use crate::dns::config::{DNS_DEFAULT_ADDRESS, DNS_DEFAULT_TLD};
|
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::addr::NameServerAddrGroup;
|
||||||
use crate::dns::utils::parse;
|
use crate::dns::utils::parse;
|
||||||
use crate::proto::dns::GetExportConfigResponse;
|
use crate::proto::dns::GetExportConfigResponse;
|
||||||
@@ -9,10 +9,10 @@ use derivative::Derivative;
|
|||||||
use gethostname::gethostname;
|
use gethostname::gethostname;
|
||||||
use hickory_proto::rr::{LowerName, Name};
|
use hickory_proto::rr::{LowerName, Name};
|
||||||
use hickory_proto::xfer::Protocol;
|
use hickory_proto::xfer::Protocol;
|
||||||
use itertools::Itertools;
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Derivative, Debug, Clone, Deserialize, Serialize, PartialEq)]
|
#[derive(Derivative, Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||||
#[derivative(Default)]
|
#[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 type DnsExportConfig = GetExportConfigResponse;
|
||||||
|
|
||||||
pub trait DnsGlobalCtxExt {
|
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_self_zone(&self) -> ZoneConfig;
|
||||||
fn dns_export_config(&self) -> DnsExportConfig;
|
fn dns_export_config(&self) -> DnsExportConfig;
|
||||||
fn dns_iter_zones(&self) -> impl Iterator<Item = ZoneConfig>;
|
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;
|
mod dns;
|
||||||
pub use dns::*;
|
pub use dns::*;
|
||||||
mod policy;
|
mod policy;
|
||||||
mod zone;
|
pub mod zone;
|
||||||
|
|
||||||
pub static DNS_DEFAULT_TLD: LazyLock<LowerName> =
|
pub static DNS_DEFAULT_TLD: LazyLock<LowerName> =
|
||||||
LazyLock::new(|| LowerName::from_str("et.net.").unwrap());
|
LazyLock::new(|| LowerName::from_str("et.net.").unwrap());
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use crate::common::global_ctx::{ArcGlobalCtx, GlobalCtxEvent};
|
use crate::common::global_ctx::{ArcGlobalCtx, GlobalCtxEvent};
|
||||||
use crate::common::scoped_task::ScopedTask;
|
use crate::dns::config::{DnsGlobalCtxExt, DNS_SERVER_ELECTION_INTERVAL, DNS_SERVER_RPC_ADDR};
|
||||||
use crate::dns::config::{DNS_SERVER_ELECTION_INTERVAL, DNS_SERVER_RPC_ADDR};
|
|
||||||
use crate::dns::peer_mgr::DnsPeerMgr;
|
use crate::dns::peer_mgr::DnsPeerMgr;
|
||||||
use crate::dns::server::DnsServer;
|
use crate::dns::server::DnsServer;
|
||||||
use crate::instance::instance::ArcNicCtx;
|
use crate::instance::instance::ArcNicCtx;
|
||||||
@@ -114,14 +113,14 @@ impl DnsNode {
|
|||||||
|
|
||||||
server.register(&rpc);
|
server.register(&rpc);
|
||||||
|
|
||||||
self.global_ctx.set_dns(Some(server.clone()));
|
self.global_ctx.set_dns_server(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(token.child_token())
|
server.run(token.child_token())
|
||||||
);
|
);
|
||||||
|
|
||||||
self.global_ctx.set_dns(None);
|
self.global_ctx.set_dns_server(None);
|
||||||
let _ = self
|
let _ = self
|
||||||
.peer_mgr
|
.peer_mgr
|
||||||
.remove_nic_packet_process_pipeline(server.id())
|
.remove_nic_packet_process_pipeline(server.id())
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::common::config::ConfigLoader;
|
|
||||||
use crate::common::PeerId;
|
use crate::common::PeerId;
|
||||||
use crate::dns::config::{DnsExportConfig, DnsGlobalCtxExt};
|
use crate::dns::config::{DnsExportConfig, DnsGlobalCtxExt};
|
||||||
use crate::dns::utils::dirty::DirtyFlag;
|
use crate::dns::utils::dirty::DirtyFlag;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::common::config::ConfigLoader;
|
|
||||||
use crate::common::global_ctx::ArcGlobalCtx;
|
use crate::common::global_ctx::ArcGlobalCtx;
|
||||||
use crate::dns::node_mgr::DnsNodeMgr;
|
use crate::dns::node_mgr::DnsNodeMgr;
|
||||||
use crate::dns::system;
|
use crate::dns::system;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use hickory_proto::runtime::TokioRuntimeProvider;
|
|||||||
use hickory_proto::udp::UdpClientStream;
|
use hickory_proto::udp::UdpClientStream;
|
||||||
use tokio::sync::Notify;
|
use tokio::sync::Notify;
|
||||||
|
|
||||||
use crate::common::config::ConfigLoader;
|
|
||||||
use crate::common::global_ctx::tests::get_mock_global_ctx;
|
use crate::common::global_ctx::tests::get_mock_global_ctx;
|
||||||
use crate::connector::udp_hole_punch::tests::replace_stun_info_collector;
|
use crate::connector::udp_hole_punch::tests::replace_stun_info_collector;
|
||||||
use crate::dns::node::DnsNode;
|
use crate::dns::node::DnsNode;
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ mod tests {
|
|||||||
let addr = socket.local_addr()?;
|
let addr = socket.local_addr()?;
|
||||||
println!("listening on {}", addr);
|
println!("listening on {}", addr);
|
||||||
|
|
||||||
let mut server = ServerFuture::new(catalog.clone());
|
let mut server = ServerFuture::new(catalog);
|
||||||
server.register_socket(socket);
|
server.register_socket(socket);
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
if let Err(e) = server.block_until_done().await {
|
if let Err(e) = server.block_until_done().await {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use crate::connector::direct::DirectConnectorManager;
|
|||||||
use crate::connector::manual::{ConnectorManagerRpcService, ManualConnectorManager};
|
use crate::connector::manual::{ConnectorManagerRpcService, ManualConnectorManager};
|
||||||
use crate::connector::tcp_hole_punch::TcpHolePunchConnector;
|
use crate::connector::tcp_hole_punch::TcpHolePunchConnector;
|
||||||
use crate::connector::udp_hole_punch::UdpHolePunchConnector;
|
use crate::connector::udp_hole_punch::UdpHolePunchConnector;
|
||||||
|
#[cfg(feature = "magic-dns")]
|
||||||
use crate::dns::node::DnsNode;
|
use crate::dns::node::DnsNode;
|
||||||
use crate::gateway::icmp_proxy::IcmpProxy;
|
use crate::gateway::icmp_proxy::IcmpProxy;
|
||||||
#[cfg(feature = "kcp")]
|
#[cfg(feature = "kcp")]
|
||||||
@@ -1383,8 +1384,6 @@ impl Instance {
|
|||||||
.await
|
.await
|
||||||
.with_context(|| "add ip failed")?;
|
.with_context(|| "add ip failed")?;
|
||||||
|
|
||||||
self.dns.start();
|
|
||||||
|
|
||||||
Self::use_new_nic_ctx(nic_ctx.clone(), new_nic_ctx).await;
|
Self::use_new_nic_ctx(nic_ctx.clone(), new_nic_ctx).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use crate::common::global_ctx::{ArcGlobalCtx, GlobalCtxEvent};
|
use crate::common::global_ctx::{ArcGlobalCtx, GlobalCtxEvent};
|
||||||
use crate::common::scoped_task::ScopedTask;
|
use crate::common::scoped_task::ScopedTask;
|
||||||
@@ -55,11 +54,15 @@ impl ProxyCidrsMonitor {
|
|||||||
proxy_cidrs = routes.into_iter().collect();
|
proxy_cidrs = routes.into_iter().collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(dns) = global_ctx.get_dns() {
|
#[cfg(feature = "magic-dns")]
|
||||||
proxy_cidrs.extend(dns.addresses().into_iter().filter_map(|a| match a.ip() {
|
{
|
||||||
IpAddr::V4(ip) => Some(cidr::Ipv4Cidr::new_host(ip)),
|
use crate::dns::config::DnsGlobalCtxExt;
|
||||||
_ => None,
|
if let Some(dns) = global_ctx.dns_server() {
|
||||||
}))
|
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
|
||||||
|
|||||||
@@ -18,6 +18,20 @@ use tokio::{
|
|||||||
task::JoinSet,
|
task::JoinSet,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
create_packet_recv_chan,
|
||||||
|
encrypt::{Encryptor, NullCipher},
|
||||||
|
foreign_network_client::ForeignNetworkClient,
|
||||||
|
foreign_network_manager::{ForeignNetworkManager, GlobalForeignNetworkAccessor},
|
||||||
|
peer_conn::PeerConnId,
|
||||||
|
peer_map::PeerMap,
|
||||||
|
peer_ospf_route::PeerRoute,
|
||||||
|
peer_rpc::PeerRpcManager,
|
||||||
|
peer_task::ExternalTaskSignal,
|
||||||
|
relay_peer_map::RelayPeerMap,
|
||||||
|
route_trait::{ArcRoute, Route},
|
||||||
|
BoxNicPacketFilter, BoxPeerPacketFilter, PacketRecvChan, PacketRecvChanReceiver,
|
||||||
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
compressor::{Compressor as _, DefaultCompressor},
|
compressor::{Compressor as _, DefaultCompressor},
|
||||||
@@ -58,21 +72,6 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
|
||||||
create_packet_recv_chan,
|
|
||||||
encrypt::{Encryptor, NullCipher},
|
|
||||||
foreign_network_client::ForeignNetworkClient,
|
|
||||||
foreign_network_manager::{ForeignNetworkManager, GlobalForeignNetworkAccessor},
|
|
||||||
peer_conn::PeerConnId,
|
|
||||||
peer_map::PeerMap,
|
|
||||||
peer_ospf_route::PeerRoute,
|
|
||||||
peer_rpc::PeerRpcManager,
|
|
||||||
peer_task::ExternalTaskSignal,
|
|
||||||
relay_peer_map::RelayPeerMap,
|
|
||||||
route_trait::{ArcRoute, Route},
|
|
||||||
BoxNicPacketFilter, BoxPeerPacketFilter, PacketRecvChan, PacketRecvChanReceiver,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RpcTransport {
|
struct RpcTransport {
|
||||||
my_peer_id: PeerId,
|
my_peer_id: PeerId,
|
||||||
peers: Weak<PeerMap>,
|
peers: Weak<PeerMap>,
|
||||||
@@ -1986,7 +1985,6 @@ impl PeerManager {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ use super::{
|
|||||||
PeerPacketFilter,
|
PeerPacketFilter,
|
||||||
};
|
};
|
||||||
use crate::common::config::ConfigLoader;
|
use crate::common::config::ConfigLoader;
|
||||||
use crate::dns::config::DnsGlobalCtxExt;
|
|
||||||
use crate::utils::DeterministicDigest;
|
use crate::utils::DeterministicDigest;
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
@@ -73,6 +72,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use atomic_shim::AtomicU64;
|
use atomic_shim::AtomicU64;
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
static SERVICE_ID: u32 = 7;
|
static SERVICE_ID: u32 = 7;
|
||||||
@@ -170,9 +170,11 @@ fn is_foreign_network_info_newer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RoutePeerInfo {
|
impl RoutePeerInfo {
|
||||||
#[allow(deprecated)]
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
#[allow(deprecated)]
|
||||||
|
quic_port: None,
|
||||||
|
|
||||||
peer_id: 0,
|
peer_id: 0,
|
||||||
inst_id: Some(uuid::Uuid::nil().into()),
|
inst_id: Some(uuid::Uuid::nil().into()),
|
||||||
cost: 0,
|
cost: 0,
|
||||||
@@ -193,7 +195,6 @@ impl RoutePeerInfo {
|
|||||||
groups: Vec::new(),
|
groups: Vec::new(),
|
||||||
dns: Default::default(),
|
dns: Default::default(),
|
||||||
|
|
||||||
quic_port: None,
|
|
||||||
noise_static_pubkey: Vec::new(),
|
noise_static_pubkey: Vec::new(),
|
||||||
trusted_credential_pubkeys: Vec::new(),
|
trusted_credential_pubkeys: Vec::new(),
|
||||||
}
|
}
|
||||||
@@ -220,6 +221,14 @@ impl RoutePeerInfo {
|
|||||||
.and_then(|cfg| cfg.public_key().ok())
|
.and_then(|cfg| cfg.public_key().ok())
|
||||||
.map(|pk| pk.as_bytes().to_vec())
|
.map(|pk| pk.as_bytes().to_vec())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "magic-dns")] {
|
||||||
|
use crate::dns::config::DnsGlobalCtxExt;
|
||||||
|
let dns = global_ctx.dns_export_config().digest();
|
||||||
|
} else {
|
||||||
|
let dns = Default::default();
|
||||||
|
}
|
||||||
|
}
|
||||||
Self {
|
Self {
|
||||||
peer_id: my_peer_id,
|
peer_id: my_peer_id,
|
||||||
inst_id: Some(global_ctx.get_id().into()),
|
inst_id: Some(global_ctx.get_id().into()),
|
||||||
@@ -252,7 +261,7 @@ impl RoutePeerInfo {
|
|||||||
ipv6_addr: global_ctx.get_ipv6().map(|x| x.into()),
|
ipv6_addr: global_ctx.get_ipv6().map(|x| x.into()),
|
||||||
|
|
||||||
groups: global_ctx.get_acl_groups(my_peer_id),
|
groups: global_ctx.get_acl_groups(my_peer_id),
|
||||||
dns: global_ctx.dns_export_config().digest(),
|
dns,
|
||||||
|
|
||||||
noise_static_pubkey,
|
noise_static_pubkey,
|
||||||
|
|
||||||
@@ -320,7 +329,7 @@ impl From<RoutePeerInfo> for crate::proto::api::instance::Route {
|
|||||||
next_hop_peer_id: 0, // next_hop_peer_id is calculated in RouteTable.
|
next_hop_peer_id: 0, // next_hop_peer_id is calculated in RouteTable.
|
||||||
cost: 0, // cost is calculated in RouteTable.
|
cost: 0, // cost is calculated in RouteTable.
|
||||||
path_latency: 0, // path_latency is calculated in RouteTable.
|
path_latency: 0, // path_latency is calculated in RouteTable.
|
||||||
proxy_cidrs: val.proxy_cidrs.clone(),
|
proxy_cidrs: val.proxy_cidrs,
|
||||||
hostname: val.hostname.unwrap_or_default(),
|
hostname: val.hostname.unwrap_or_default(),
|
||||||
stun_info: {
|
stun_info: {
|
||||||
let mut stun_info = StunInfo::default();
|
let mut stun_info = StunInfo::default();
|
||||||
|
|||||||
Reference in New Issue
Block a user