Package org.xbill.DNS
Class DohResolver
java.lang.Object
org.xbill.DNS.DohResolverCommon
org.xbill.DNS.DohResolver
- All Implemented Interfaces:
Resolver
Proof-of-concept DNS over HTTP (DoH)
resolver. This class is not suitable for high load scenarios because of the shortcomings of
Java's built-in HTTP clients. For more control, implement your own https://cloudflare-dns.com/dns-query: max streams=250, idle timeout=400s
https://dns.google/dns-query: max streams=100, idle timeout=240s
Resolver using e.g. OkHttp.
On Java 8, it uses HTTP/1.1, which is against the recommendation of RFC 8484 to use HTTP/2 and thus slower. On Java 11 or newer, HTTP/2 is always used, but the built-in HttpClient has its own issues with connection handling.
As of 2020-09-13, the following limits of public resolvers for HTTP/2 were observed:
- Since:
- 3.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.xbill.DNS.DohResolverCommon
APPLICATION_DNS_MESSAGE, defaultExecutor, lastRequest, maxConcurrentRequests, queryOPT, timeout, tsig, uriTemplate, usePost -
Constructor Summary
ConstructorsConstructorDescriptionDohResolver(String uriTemplate) Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s).DohResolver(String uriTemplate, int maxConcurrentRequests, Duration idleConnectionTimeout) Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s). -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprotected <T> CompletableFuture<T> sendAndGetMessageBytes(String url, byte[] queryBytes, long startTime) Asynchronously sends a message using the defaultForkJoinPool.commonPool().Asynchronously sends a message.voidsetEDNS(int version, int payloadSize, int flags, List<EDNSOption> options) Sets the EDNS information on outgoing messages.Methods inherited from class org.xbill.DNS.DohResolverCommon
getExecutor, getNanoTime, getTimeout, getUriTemplate, getUrl, isUsePost, prepareQuery, setExecutor, setIgnoreTruncation, setPort, setTCP, setTimeout, setTSIGKey, setUriTemplate, setUsePost, timeoutFailedFuture, timeoutFailedFuture, toString, verifyTSIGMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.xbill.DNS.Resolver
send, sendAsync, setEDNS, setEDNS, setTimeout, setTimeout
-
Field Details
-
sslSocketFactory
-
-
Constructor Details
-
DohResolver
Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s).- Parameters:
uriTemplate- the URI to use for resolving, e.g.https://dns.google/dns-query
-
DohResolver
Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s).- Parameters:
uriTemplate- the URI to use for resolving, e.g.https://dns.google/dns-querymaxConcurrentRequests- Maximum concurrent HTTP/2 streams for Java 11+ or HTTP/1.1 connections for Java 8. On Java 8 this cannot exceed the system propertyhttp.maxConnections.idleConnectionTimeout- Max. idle time for HTTP/2 connections until a request is serialized. Applies to Java 11+ only.- Since:
- 3.3
-
-
Method Details
-
setEDNS
Sets the EDNS information on outgoing messages.- Specified by:
setEDNSin interfaceResolver- Overrides:
setEDNSin classDohResolverCommon- Parameters:
version- The EDNS version to use. 0 indicates EDNS0 and -1 indicates no EDNS.payloadSize- ignoredflags- EDNS extended flags to be set in the OPT record.options- EDNS options to be set in the OPT record- See Also:
-
sendAsync
Description copied from interface:ResolverAsynchronously sends a message using the defaultForkJoinPool.commonPool().The default implementation calls the deprecated
Resolver.sendAsync(Message, ResolverListener). Implementors must override at least one of thesendAsyncmethods or a stack overflow will occur.- Parameters:
query- The query to send.- Returns:
- A future that completes when the query is finished.
-
sendAsync
Description copied from interface:ResolverAsynchronously sends a message.The default implementation calls the deprecated
Resolver.sendAsync(Message, ResolverListener). Implementors must override at least one of thesendAsyncmethods or a stack overflow will occur.- Parameters:
query- The query to send.executor- The service to use for async operations.- Returns:
- A future that completes when the query is finished.
-
sendAndGetMessageBytes
private DohResolver.SendAndGetMessageBytesResponse sendAndGetMessageBytes(String url, byte[] queryBytes, long startTime) throws IOException, URISyntaxException - Throws:
IOExceptionURISyntaxException
-
discardStream
- Throws:
IOException
-
failedFuture
- Specified by:
failedFuturein classDohResolverCommon
-