Skip to main content

Crate libdoh

Crate libdoh 

Source
Expand description

A DNS-over-HTTPS server.

DoH serves RFC 8484 queries over HTTP/1.1 and HTTP/2, and optionally Oblivious DoH and a JSON API. With the tls feature, it can also handle TLS and reload certificates.

The server takes care of connections and timeouts, and a Resolver answers the queries. Forwarder sends them to a DNS server. Applications can write their own resolver, or wrap a Forwarder:

use std::net::SocketAddr;

use libdoh::{DnsResponse, DoH, DoHError, Forwarder, Globals, Query, Resolver};

struct LocalOnly(Forwarder);

impl Resolver for LocalOnly {
    fn allow_connection(&self, remote_addr: SocketAddr) -> bool {
        remote_addr.ip().is_loopback()
    }

    async fn resolve(&self, query: Query) -> Result<DnsResponse, DoHError> {
        self.0.resolve(query).await
    }
}

let forwarder = Forwarder::new("9.9.9.9:53".parse()?, 64);
let globals = Globals {
    max_clients: 512,
    ..Globals::default()
};
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await?;
DoH::new(globals, LocalOnly(forwarder)).serve(listener).await?;

Modules§

dns
odoh
reexports

Structs§

CachePolicy
The Cache-Control header of a response.
DnsResponse
A DNS response, and how long HTTP caches may keep it.
DoH
A DoH server that answers queries with a Resolver.
Forwarder
Forwards queries to a DNS server over UDP, and retries over TCP when the response is truncated.
Globals
Settings of a DoH server.
Query
A DNS query received over HTTP.

Enums§

CacheScope
Whether shared HTTP caches may store a response.
DoHError
DoHType
How a query reached the server.

Constants§

MAX_TIMEOUT_SECS
MIN_TIMEOUT_SECS

Traits§

Resolver
Answers the queries that a DoH server receives.