Rust

adapter

Module

Adapters: the transports a server listens on, on Tokio.

Contents

use utopia_dns::adapter::Bound;
Rust
pub struct Bound

The transports of a Tokio adapter, bound.

use utopia_dns::adapter::Http;
Rust
pub struct Http

DNS over HTTPS (RFC 8484): wire-format queries by GET (?dns= in base64url) or POST (application/dns-message), on HTTP/1.1, or HTTP/2 over TLS. Without a certificate it serves plain HTTP, behind a TLS-terminating proxy.

use utopia_dns::adapter::Tcp;
Rust
pub struct Tcp

TCP with 2-byte length prefixes (RFC 1035 §4.2.2, RFC 7766).

A connection is closed when it sends a zero-length or oversized frame, when its unanswered bytes exceed max_buffer_size, after idle_timeout without data, or when an answer exceeds 65535 bytes. Connections beyond max_clients are closed at once. With proxy_protocol, every connection must start with a PROXY protocol header, whose source address is the client's.

use utopia_dns::adapter::Tokio;
Rust
pub struct Tokio

The Tokio adapter: any number of UDP, TCP and DNS-over-HTTPS transports in one runtime. UDP and TCP transports can share a port number; each HTTP transport needs its own.

Packets are handled concurrently; frames on one TCP connection are answered in order. Worker start callbacks run once, with id 0, after every transport is bound.

Rust
use utopia_dns::adapter::{Tcp, Tokio, Transport, Udp};
use utopia_dns::resolver::Memory;
use utopia_dns::{Server, Zone};
let adapter = Tokio::new(vec![
    Transport::Udp(Udp::new("0.0.0.0", 5300)),
    Transport::Tcp(Tcp::new("0.0.0.0", 5300)),
])?;
Server::new(Memory::new(zone)).start(adapter).await;
Compiles in CI; needs a running service to execute.
Also implements Debug.
use utopia_dns::adapter::Udp;
Rust
pub struct Udp

UDP (RFC 1035 §4.2.1): answers are cut to 512 bytes.

use utopia_dns::adapter::Transport;
Rust
pub enum Transport

A transport of the Tokio adapter.

use utopia_dns::adapter::Adapter;
Rust
pub trait Adapter: Send + 'static

Serves packets: listens on transports and hands every packet to a Handler, sending back what it returns.

Implemented byTokio
Rust
pub type WorkerStart = Box<dyn Fn(usize) + Send + Sync>

A worker start callback: it gets the worker's id.

Rust
pub const CONTENT_TYPE: &str = "application/dns-message"

The media type of DNS messages over HTTP.