use crate::Result;
#[async_trait::async_trait]
pub trait Server: Send + Sync + Sized {
async fn from_config(config: ServerConfig) -> Result<Self>;
async fn run(self) -> Result<()>;
}
#[cfg(feature = "admin")]
pub mod admin;
pub mod config;
#[cfg(feature = "doh")]
pub mod doh;
#[cfg(feature = "doq")]
pub mod doq;
#[cfg(feature = "dot")]
pub mod dot;
pub mod handler;
pub mod launcher;
#[cfg(feature = "metrics")]
pub mod monitoring;
pub mod tcp;
#[cfg(any(feature = "doh", feature = "dot"))]
pub mod tls;
pub mod udp;
#[cfg(feature = "admin")]
pub use admin::{AdminServer, AdminState};
pub use config::ServerConfig;
#[cfg(feature = "doh")]
pub use doh::DohServer;
#[cfg(feature = "doq")]
pub use doq::DoqServer;
#[cfg(feature = "dot")]
pub use dot::DotServer;
pub use handler::{ClientInfo, DefaultHandler, Protocol, RequestContext, RequestHandler};
pub use launcher::ServerLauncher;
#[cfg(feature = "metrics")]
pub use monitoring::MonitoringServer;
pub use tcp::TcpServer;
#[cfg(any(feature = "doh", feature = "dot"))]
pub use tls::TlsConfig;
pub use udp::UdpServer;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_server_config_accessible() {
let config = ServerConfig::default();
assert!(config.udp_addr.is_some());
assert!(config.tcp_addr.is_some());
}
#[test]
fn test_server_config_builder_pattern() {
use std::net::SocketAddr;
let addr: SocketAddr = "127.0.0.1:5353".parse().unwrap();
let config = ServerConfig::default()
.with_udp_addr(addr)
.with_timeout(std::time::Duration::from_secs(10))
.with_max_connections(500);
assert_eq!(config.udp_addr, Some(addr));
assert_eq!(config.timeout, std::time::Duration::from_secs(10));
assert_eq!(config.max_connections, 500);
}
#[test]
#[cfg(feature = "admin")]
fn test_admin_state_creation() {
use crate::config::Config;
use std::sync::Arc;
use tokio::sync::RwLock;
let config = Arc::new(RwLock::new(Config::new()));
let registry = Arc::new(crate::plugin::Registry::new());
let state = AdminState::new(config, Arc::clone(®istry));
let _ = state;
}
#[test]
#[cfg(any(feature = "doh", feature = "dot"))]
fn test_tls_config_accessible() {
assert!(std::mem::size_of::<TlsConfig>() > 0);
}
#[tokio::test]
async fn test_default_handler_creation() {
let _handler = DefaultHandler;
}
#[test]
fn test_all_server_types_accessible() {
assert!(std::mem::size_of::<UdpServer>() > 0);
assert!(std::mem::size_of::<TcpServer>() > 0);
#[cfg(feature = "doh")]
assert!(std::mem::size_of::<DohServer>() > 0);
#[cfg(feature = "dot")]
assert!(std::mem::size_of::<DotServer>() > 0);
#[cfg(feature = "admin")]
assert!(std::mem::size_of::<AdminServer>() > 0);
#[cfg(feature = "metrics")]
assert!(std::mem::size_of::<MonitoringServer>() > 0);
}
}