pub struct DnsServer { /* private fields */ }Expand description
DNS server for overlay networks
Implementations§
Source§impl DnsServer
impl DnsServer
Sourcepub fn new(listen_addr: SocketAddr, zone: &str) -> Result<Self, DnsError>
pub fn new(listen_addr: SocketAddr, zone: &str) -> Result<Self, DnsError>
Create a new DNS server for the given zone
§Errors
Returns DnsError::InvalidName if the zone name is invalid.
Sourcepub fn from_config(config: &DnsConfig) -> Result<Self, DnsError>
pub fn from_config(config: &DnsConfig) -> Result<Self, DnsError>
Sourcepub fn handle(&self) -> DnsHandle
pub fn handle(&self) -> DnsHandle
Get a handle for managing DNS records
The handle can be cloned and used to add/remove records even after the server has been started.
Sourcepub async fn add_record(
&self,
hostname: &str,
ip: IpAddr,
) -> Result<(), DnsError>
pub async fn add_record( &self, hostname: &str, ip: IpAddr, ) -> Result<(), DnsError>
Add a DNS record for a hostname to IP mapping
Creates an A record for IPv4 addresses and an AAAA record for IPv6 addresses.
§Errors
Returns DnsError::InvalidName if the hostname is invalid.
Sourcepub async fn remove_record(&self, hostname: &str) -> Result<bool, DnsError>
pub async fn remove_record(&self, hostname: &str) -> Result<bool, DnsError>
Remove DNS records for a hostname (both A and AAAA)
§Errors
Returns DnsError::InvalidName if the hostname is invalid.
Sourcepub async fn start(self) -> Result<DnsHandle, DnsError>
pub async fn start(self) -> Result<DnsHandle, DnsError>
Start the DNS server and return a handle for record management
This spawns the DNS server in a background task and returns a handle that can be used to add/remove records while the server is running.
§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub async fn start_background(&self) -> Result<DnsHandle, DnsError>
pub async fn start_background(&self) -> Result<DnsHandle, DnsError>
Start the DNS server in a background task without consuming self.
Unlike start(self), this method borrows self, allowing the DnsServer
to be wrapped in an Arc and shared (e.g., with ServiceManager) while
the server runs in the background.
§Errors
This method currently always succeeds but returns Result for API consistency.
Sourcepub fn listen_addr(&self) -> SocketAddr
pub fn listen_addr(&self) -> SocketAddr
Get the listen address
Sourcepub fn zone_origin(&self) -> &Name
pub fn zone_origin(&self) -> &Name
Get the zone origin