Skip to main content

Server

Struct Server 

Source
pub struct Server<T: RequestHandler> { /* private fields */ }
Expand description

A Futures based implementation of a DNS server

Implementations§

Source§

impl<T: RequestHandler> Server<T>

Source

pub fn new(handler: T) -> Self

Creates a new ServerFuture with the specified Handler.

Source

pub fn with_access( handler: T, denied_networks: impl IntoIterator<Item = IpNet>, allowed_networks: impl IntoIterator<Item = IpNet>, ) -> Self

Creates a new ServerFuture with the specified Handler and denied/allowed networks

Source

pub fn register_socket(&mut self, socket: UdpSocket)

Register a UDP socket. Should be bound before calling this function.

Source

pub fn register_listener( &mut self, listener: TcpListener, timeout: Duration, response_buffer_size: usize, )

Register a TcpListener to the Server. This should already be bound to either an IPv6 or an IPv4 address.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • listener - a bound TCP socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • response_buffer_size - size of the buffer for outgoing responses per connection
Source

pub fn register_tls_listener_with_tls_config( &mut self, listener: TcpListener, handshake_timeout: Duration, tls_config: Arc<ServerConfig>, ) -> Result<()>

Available on crate feature __tls only.

Register a TlsListener to the Server. The TlsListener should already be bound to either an IPv6 or an IPv4 address.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

The TLS ServerConfig should be configured with TLS 1.3 support and the DoT ALPN protocol enabled.

§Arguments
  • listener - a bound TCP (needs to be on a different port from standard TCP connections) socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • tls_config - rustls server config
Source

pub fn register_tls_listener( &mut self, listener: TcpListener, timeout: Duration, server_cert_resolver: Arc<dyn ResolvesServerCert>, ) -> Result<()>

Available on crate feature __tls only.

Register a TlsListener to the Server by providing a rustls ResolvesServerCert. The TlsListener should already be bound to either an IPv6 or an IPv4 address.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • listener - a bound TCP (needs to be on a different port from standard TCP connections) socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • server_cert_resolver - resolver for the certificate and key used to announce to clients
Source

pub fn register_https_listener( &mut self, listener: TcpListener, handshake_timeout: Duration, server_cert_resolver: Arc<dyn ResolvesServerCert>, dns_hostname: Option<String>, http_endpoint: String, ) -> Result<()>

Available on crate feature __https only.

Register a TcpListener for HTTPS (h2) to the Server for supporting DoH (DNS-over-HTTPS). The TcpListener should already be bound to either an IPv6 or an IPv4 address.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • listener - a bound TCP (needs to be on a different port from standard TCP connections) socket
  • handshake_timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • server_cert_resolver - resolver for the certificate and key used to announce to clients
  • dns_hostname - the DNS hostname of the H2 server.
  • http_endpoint - the HTTP endpoint of the H2 server.
Source

pub fn register_https_listener_with_tls_config( &mut self, listener: TcpListener, handshake_timeout: Duration, tls_config: Arc<ServerConfig>, dns_hostname: Option<String>, http_endpoint: String, ) -> Result<()>

Available on crate feature __https only.

Register a TcpListener for HTTPS (h2) for supporting DoH with the given TLS config.

The TcpListener should already be bound to either an IPv6 or an IPv4 address.

The TLS ServerConfig should be configured with TLS 1.3 support and the DoH ALPN protocol enabled.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • listener - a bound TCP (needs to be on a different port from standard TCP connections) socket
  • handshake_timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • tls_config - a customized ServerConfig to use for TLS.
  • dns_hostname - the DNS hostname of the H2 server.
  • http_endpoint - the HTTP endpoint of the H2 server.
Source

pub fn register_quic_listener( &mut self, socket: UdpSocket, _timeout: Duration, server_cert_resolver: Arc<dyn ResolvesServerCert>, ) -> Result<()>

Available on crate feature __quic only.

Register a UdpSocket to the Server for supporting DoQ (DNS-over-QUIC). The UdpSocket should already be bound to either an IPv6 or an IPv4 address.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • socket - a bound UDP socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • server_cert_resolver - resolver for certificate and key used to announce to clients
  • dns_hostname - the DNS hostname of the DoQ server.
Source

pub fn register_quic_listener_and_tls_config( &mut self, socket: UdpSocket, _timeout: Duration, tls_config: Arc<ServerConfig>, ) -> Result<(), NetError>

Available on crate feature __quic only.

Register a UdpSocket for supporting DoQ (DNS-over-QUIC) with the provided TLS config.

The UdpSocket should already be bound to either an IPv6 or an IPv4 address.

The TLS ServerConfig should be configured with TLS 1.3 support and the DoQ ALPN protocol enabled.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • socket - a bound UDP socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • tls_config - a customized ServerConfig to use for TLS.
  • dns_hostname - the DNS hostname of the DoQ server.
Source

pub fn register_h3_listener( &mut self, socket: UdpSocket, _timeout: Duration, server_cert_resolver: Arc<dyn ResolvesServerCert>, dns_hostname: Option<String>, ) -> Result<()>

Available on crate feature __h3 only.

Register a UdpSocket to the Server for supporting DoH3 (DNS-over-HTTP/3). The UdpSocket should already be bound to either an IPv6 or an IPv4 address.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • listener - a bound TCP (needs to be on a different port from standard TCP connections) socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • server_cert_resolver - resolver for certificate and key used to announce to clients
Source

pub fn register_h3_listener_with_tls_config( &mut self, socket: UdpSocket, _timeout: Duration, tls_config: Arc<ServerConfig>, dns_hostname: Option<String>, ) -> Result<(), NetError>

Available on crate feature __h3 only.

Register a UdpSocket for supporting DoH3 (DNS-over-HTTP/3) with the specified TLS config.

The UdpSocket should already be bound to either an IPv6 or an IPv4 address.

The TLS ServerConfig should be configured with TLS 1.3 support and the DoH3 ALPN protocol enabled.

To make the server more resilient to DOS issues, there is a timeout. Care should be taken to not make this too low depending on use cases.

§Arguments
  • listener - a bound TCP (needs to be on a different port from standard TCP connections) socket
  • timeout - timeout duration of incoming requests, any connection that does not send requests within this time period will be closed. In the future it should be possible to create long-lived queries, but these should be from trusted sources only, this would require some type of whitelisting.
  • tls_config - a customized ServerConfig to use for TLS.
Source

pub async fn shutdown_gracefully(&mut self) -> Result<(), NetError>

Triggers a graceful shutdown the server. All background tasks will stop accepting new connections and the returned future will complete once all tasks have terminated.

Source

pub fn shutdown_token(&self) -> &CancellationToken

Returns a reference to the CancellationToken used to gracefully shut down the server.

Once cancellation is requested, all background tasks will stop accepting new connections, and block_until_done() will complete once all tasks have terminated.

Source

pub async fn block_until_done(&mut self) -> Result<(), NetError>

This will run until all background tasks complete. If one or more tasks return an error, one will be chosen as the returned error for this future.

Auto Trait Implementations§

§

impl<T> Freeze for Server<T>

§

impl<T> !RefUnwindSafe for Server<T>

§

impl<T> Send for Server<T>

§

impl<T> Sync for Server<T>

§

impl<T> Unpin for Server<T>

§

impl<T> UnsafeUnpin for Server<T>

§

impl<T> !UnwindSafe for Server<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more