2024-07-16 23:38:48 +00:00
|
|
|
pub mod actual;
|
|
|
|
|
pub mod cache;
|
|
|
|
|
mod dns;
|
|
|
|
|
pub mod fed;
|
2025-03-19 03:49:12 +00:00
|
|
|
#[cfg(test)]
|
2024-07-16 23:38:48 +00:00
|
|
|
mod tests;
|
2025-03-19 03:49:12 +00:00
|
|
|
mod well_known;
|
2024-07-16 22:00:54 +00:00
|
|
|
|
2025-01-22 02:16:51 +00:00
|
|
|
use std::sync::Arc;
|
2024-07-16 23:38:48 +00:00
|
|
|
|
2025-03-15 04:08:57 +00:00
|
|
|
use async_trait::async_trait;
|
2025-08-22 20:15:54 +05:00
|
|
|
use tuwunel_core::{Result, arrayvec::ArrayString, utils::MutexMap};
|
2024-07-16 22:00:54 +00:00
|
|
|
|
2024-07-16 23:38:48 +00:00
|
|
|
use self::{cache::Cache, dns::Resolver};
|
2024-07-16 22:00:54 +00:00
|
|
|
|
|
|
|
|
pub struct Service {
|
2024-07-16 23:38:48 +00:00
|
|
|
pub cache: Arc<Cache>,
|
|
|
|
|
pub resolver: Arc<Resolver>,
|
2025-01-22 06:57:18 +00:00
|
|
|
resolving: Resolving,
|
2025-08-22 20:15:54 +05:00
|
|
|
services: Arc<crate::services::OnceServices>,
|
2024-07-16 22:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-22 06:57:18 +00:00
|
|
|
type Resolving = MutexMap<NameBuf, ()>;
|
|
|
|
|
type NameBuf = ArrayString<256>;
|
|
|
|
|
|
2025-03-15 04:08:57 +00:00
|
|
|
#[async_trait]
|
2024-07-16 22:00:54 +00:00
|
|
|
impl crate::Service for Service {
|
2025-04-23 19:27:49 +00:00
|
|
|
#[allow(
|
|
|
|
|
clippy::as_conversions,
|
|
|
|
|
clippy::cast_sign_loss,
|
|
|
|
|
clippy::cast_possible_truncation
|
|
|
|
|
)]
|
2025-09-17 14:21:55 +05:00
|
|
|
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
|
|
|
|
|
let cache = Cache::new(args);
|
2024-07-16 22:00:54 +00:00
|
|
|
Ok(Arc::new(Self {
|
2024-07-16 23:38:48 +00:00
|
|
|
cache: cache.clone(),
|
|
|
|
|
resolver: Resolver::build(args.server, cache)?,
|
2025-01-22 06:57:18 +00:00
|
|
|
resolving: MutexMap::new(),
|
2025-08-22 20:15:54 +05:00
|
|
|
services: args.services.clone(),
|
2024-07-16 22:00:54 +00:00
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-15 04:08:57 +00:00
|
|
|
async fn clear_cache(&self) {
|
|
|
|
|
self.resolver.clear_cache();
|
|
|
|
|
self.cache.clear().await;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 22:00:54 +00:00
|
|
|
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
|
|
|
|
}
|