Interface DnsTransport

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface DnsTransport
Sends a DNS query message to a recursive resolver and returns the raw response. The resolver only needs to pass DNSSEC records through; all validation happens locally.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    exchange(byte[] query)
    Sends a wire-format DNS query and reads its response.
    failover(List<DnsTransport> transports)
    Each of transports in turn: a query that fails with an IOException (a resolver that cannot be reached, times out or answers with an HTTP error) is sent to the next, and only when every one has failed does the query fail, with the last failure and the earlier ones suppressed in it.
    https(URI endpoint, Duration timeout)
    DNS over HTTPS (RFC 8484) to a resolver such as https://cloudflare-dns.com/dns-query or https://dns.google/dns-query.
    The nameservers of /etc/resolv.conf, or Google and Cloudflare public resolvers when that file is unavailable.
    udp(List<InetSocketAddress> servers, Duration timeout)
    UDP to each server in turn, retrying over TCP when a response is truncated.
  • Method Details

    • exchange

      byte[] exchange(byte[] query) throws IOException
      Sends a wire-format DNS query and reads its response.
      Parameters:
      query - the wire-format DNS query message
      Returns:
      the wire-format DNS response
      Throws:
      IOException - if the query fails or no DNS response can be read
    • udp

      static DnsTransport udp(List<InetSocketAddress> servers, Duration timeout)
      UDP to each server in turn, retrying over TCP when a response is truncated.
      Parameters:
      servers - the recursive DNS server addresses
      timeout - the per-attempt UDP/TCP query timeout
      Returns:
      the UDP transport with TCP fallback
    • https

      static DnsTransport https(URI endpoint, Duration timeout)
      DNS over HTTPS (RFC 8484) to a resolver such as https://cloudflare-dns.com/dns-query or https://dns.google/dns-query. The connection uses the JVM's default proxy settings.
      Parameters:
      endpoint - the DNS-over-HTTPS endpoint
      timeout - the HTTP connection and query timeout
      Returns:
      the DNS-over-HTTPS transport
    • failover

      static DnsTransport failover(List<DnsTransport> transports)
      Each of transports in turn: a query that fails with an IOException (a resolver that cannot be reached, times out or answers with an HTTP error) is sent to the next, and only when every one has failed does the query fail, with the last failure and the earlier ones suppressed in it. Each query starts at the transport that answered last, so a resolver that is down costs its timeout once rather than on every query; one that answers again is used again once the others fail. Responses are validated locally either way, so mixing resolvers within a lookup is safe.
      Parameters:
      transports - the transports to try, in order; at least one
      Returns:
      the failover transport
    • systemServers

      static List<InetSocketAddress> systemServers()
      The nameservers of /etc/resolv.conf, or Google and Cloudflare public resolvers when that file is unavailable.
      Returns:
      the nameservers of /etc/resolv.conf, or Google and Cloudflare public resolvers when that file is unavailable