Package io.netty.resolver.dns
Class DnsNameResolver
- java.lang.Object
-
- io.netty.resolver.SimpleNameResolver<java.net.InetAddress>
-
- io.netty.resolver.InetNameResolver
-
- io.netty.resolver.dns.DnsNameResolver
-
- All Implemented Interfaces:
NameResolver<java.net.InetAddress>,java.io.Closeable,java.lang.AutoCloseable
public class DnsNameResolver extends InetNameResolver
A DNS-basedInetNameResolver.
-
-
Field Summary
Fields Modifier and Type Field Description static AttributeKey<java.lang.Boolean>DNS_PIPELINE_ATTRIBUTEAn attribute used to mark all channels created by theDnsNameResolver.
-
Constructor Summary
Constructors Constructor Description DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsCache resolveCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, java.lang.String[] searchDomains, int ndots, boolean decodeIdn)Deprecated.DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsCache resolveCache, DnsCache authoritativeDnsServerCache, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, java.lang.String[] searchDomains, int ndots, boolean decodeIdn)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthoritativeDnsServerCacheauthoritativeDnsServerCache()Returns the cache used for authoritative DNS servers for a domain.voidclose()Closes the internal datagram channel used for sending and receiving DNS messages, and clears all DNS resource records from the cache.DnsCnameCachecnameCache()Returns theDnsCnameCache.protected voiddoResolve(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache)Hook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.protected voiddoResolve(java.lang.String inetHost, Promise<java.net.InetAddress> promise)Invoked bySimpleNameResolver.resolve(String)to perform the actual name resolution.protected voiddoResolveAll(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache)Hook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.protected voiddoResolveAll(java.lang.String inetHost, Promise<java.util.List<java.net.InetAddress>> promise)Invoked bySimpleNameResolver.resolveAll(String)to perform the actual name resolution.protected EventLoopexecutor()Returns theEventExecutorwhich is used to notify the listeners of theFuturereturned bySimpleNameResolver.resolve(String).HostsFileEntriesResolverhostsFileEntriesResolver()Returns the component that tries to resolve hostnames against the hosts file prior to asking to remotes DNS servers.booleanisOptResourceEnabled()Returns the automatic inclusion of a optional records that tries to give the remote DNS server a hint about how much data the resolver can read per response is enabled.booleanisRecursionDesired()Returnstrueif and only if this resolver sends a DNS query with the RD (recursion desired) flag set.static booleanisTimeoutError(java.lang.Throwable cause)Returnstrueif theThrowablewas caused by an timeout.static booleanisTransportOrTimeoutError(java.lang.Throwable cause)Returnstrueif theThrowablewas caused by an timeout or transport error.intmaxPayloadSize()Returns the capacity of the datagram packet buffer (in bytes).intmaxQueriesPerResolve()Returns the maximum allowed number of DNS queries to send when resolving a host name.protected DnsServerAddressStreamnewRedirectDnsServerStream(java.lang.String hostname, java.util.List<java.net.InetSocketAddress> nameservers)Creates a newDnsServerAddressStreamto following a redirected DNS query.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(DnsQuestion question)Sends a DNS query with the specified question.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)Sends a DNS query with the specified question.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)Sends a DNS query with the specified question with additional records.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question)Sends a DNS query with the specified question using the specified name server list.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)Sends a DNS query with the specified question using the specified name server list.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)Sends a DNS query with the specified question with additional records using the specified name server list.Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>>query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)Sends a DNS query with the specified question with additional records using the specified name server list.DnsServerAddressStreamqueryDnsServerAddressStream()Returns the dns server address stream used for DNS queries (not resolve).longqueryTimeoutMillis()Returns the timeout of each DNS query performed by this resolver (in milliseconds).Future<java.net.InetAddress>resolve(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals)Resolves the specified name into an address.Future<java.net.InetAddress>resolve(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals, Promise<java.net.InetAddress> promise)Resolves the specified name into an address.Future<java.util.List<DnsRecord>>resolveAll(DnsQuestion question)Resolves theDnsRecords that are matched by the specifiedDnsQuestion.Future<java.util.List<DnsRecord>>resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)Resolves theDnsRecords that are matched by the specifiedDnsQuestion.Future<java.util.List<DnsRecord>>resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<DnsRecord>> promise)Resolves theDnsRecords that are matched by the specifiedDnsQuestion.Future<java.util.List<java.net.InetAddress>>resolveAll(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals)Resolves the specified host name and port into a list of address.Future<java.util.List<java.net.InetAddress>>resolveAll(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<java.net.InetAddress>> promise)Resolves the specified host name and port into a list of address.DnsCacheresolveCache()Returns the resolution cache.ResolvedAddressTypesresolvedAddressTypes()Returns theResolvedAddressTypesresolved bySimpleNameResolver.resolve(String).-
Methods inherited from class io.netty.resolver.InetNameResolver
asAddressResolver
-
Methods inherited from class io.netty.resolver.SimpleNameResolver
resolve, resolve, resolveAll, resolveAll
-
-
-
-
Field Detail
-
DNS_PIPELINE_ATTRIBUTE
public static final AttributeKey<java.lang.Boolean> DNS_PIPELINE_ATTRIBUTE
An attribute used to mark all channels created by theDnsNameResolver.
-
-
Constructor Detail
-
DnsNameResolver
@Deprecated public DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsCache resolveCache, DnsCache authoritativeDnsServerCache, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, java.lang.String[] searchDomains, int ndots, boolean decodeIdn)
Deprecated.Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.- Parameters:
eventLoop- theEventLoopwhich will perform the communication with the DNS serverschannelFactory- theChannelFactorythat will create aDatagramChannelresolveCache- the DNS resolved entries cacheauthoritativeDnsServerCache- the cache used to find the authoritative DNS server for a domaindnsQueryLifecycleObserverFactory- used to generate new instances ofDnsQueryLifecycleObserverwhich can be used to track metrics for DNS servers.queryTimeoutMillis- timeout of each DNS query in millis.0disables the timeout. If not set or a negative number is set, the default timeout is used.resolvedAddressTypes- the preferred address typesrecursionDesired- if recursion desired flag must be setmaxQueriesPerResolve- the maximum allowed number of DNS queries for a given name resolutiontraceEnabled- if trace is enabledmaxPayloadSize- the capacity of the datagram packet bufferoptResourceEnabled- if automatic inclusion of a optional records is enabledhostsFileEntriesResolver- theHostsFileEntriesResolverused to check for local aliasesdnsServerAddressStreamProvider- TheDnsServerAddressStreamProviderused to determine the name servers for each hostname lookup.searchDomains- the list of search domain (can be null, if so, will try to default to the underlying platform ones)ndots- the ndots valuedecodeIdn-trueif domain / host names should be decoded to unicode when received. See rfc3492.
-
DnsNameResolver
@Deprecated public DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsCache resolveCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, java.lang.String[] searchDomains, int ndots, boolean decodeIdn)
Deprecated.Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.- Parameters:
eventLoop- theEventLoopwhich will perform the communication with the DNS serverschannelFactory- theChannelFactorythat will create aDatagramChannelresolveCache- the DNS resolved entries cacheauthoritativeDnsServerCache- the cache used to find the authoritative DNS server for a domaindnsQueryLifecycleObserverFactory- used to generate new instances ofDnsQueryLifecycleObserverwhich can be used to track metrics for DNS servers.queryTimeoutMillis- timeout of each DNS query in millis.0disables the timeout. If not set or a negative number is set, the default timeout is used.resolvedAddressTypes- the preferred address typesrecursionDesired- if recursion desired flag must be setmaxQueriesPerResolve- the maximum allowed number of DNS queries for a given name resolutiontraceEnabled- if trace is enabledmaxPayloadSize- the capacity of the datagram packet bufferoptResourceEnabled- if automatic inclusion of a optional records is enabledhostsFileEntriesResolver- theHostsFileEntriesResolverused to check for local aliasesdnsServerAddressStreamProvider- TheDnsServerAddressStreamProviderused to determine the name servers for each hostname lookup.searchDomains- the list of search domain (can be null, if so, will try to default to the underlying platform ones)ndots- the ndots valuedecodeIdn-trueif domain / host names should be decoded to unicode when received. See rfc3492.
-
-
Method Detail
-
newRedirectDnsServerStream
protected DnsServerAddressStream newRedirectDnsServerStream(java.lang.String hostname, java.util.List<java.net.InetSocketAddress> nameservers)
Creates a newDnsServerAddressStreamto following a redirected DNS query. By overriding this it provides the opportunity to sort the name servers before following a redirected DNS query.- Parameters:
hostname- the hostname.nameservers- The addresses of the DNS servers which are used in the event of a redirect. This may contain resolved and unresolved addresses so the usedDnsServerAddressStreammust allow unresolved addresses if you want to include these as well.- Returns:
- A
DnsServerAddressStreamwhich will be used to follow the DNS redirect ornullif none should be followed.
-
resolveCache
public DnsCache resolveCache()
Returns the resolution cache.
-
cnameCache
public DnsCnameCache cnameCache()
Returns theDnsCnameCache.
-
authoritativeDnsServerCache
public AuthoritativeDnsServerCache authoritativeDnsServerCache()
Returns the cache used for authoritative DNS servers for a domain.
-
queryTimeoutMillis
public long queryTimeoutMillis()
Returns the timeout of each DNS query performed by this resolver (in milliseconds). The default value is 5 seconds.
-
queryDnsServerAddressStream
public DnsServerAddressStream queryDnsServerAddressStream()
Returns the dns server address stream used for DNS queries (not resolve).
-
resolvedAddressTypes
public ResolvedAddressTypes resolvedAddressTypes()
Returns theResolvedAddressTypesresolved bySimpleNameResolver.resolve(String). The default value depends on the value of the system property"java.net.preferIPv6Addresses".
-
isRecursionDesired
public boolean isRecursionDesired()
Returnstrueif and only if this resolver sends a DNS query with the RD (recursion desired) flag set. The default value istrue.
-
maxQueriesPerResolve
public int maxQueriesPerResolve()
Returns the maximum allowed number of DNS queries to send when resolving a host name. The default value is8.
-
maxPayloadSize
public int maxPayloadSize()
Returns the capacity of the datagram packet buffer (in bytes). The default value is4096bytes.
-
isOptResourceEnabled
public boolean isOptResourceEnabled()
Returns the automatic inclusion of a optional records that tries to give the remote DNS server a hint about how much data the resolver can read per response is enabled.
-
hostsFileEntriesResolver
public HostsFileEntriesResolver hostsFileEntriesResolver()
Returns the component that tries to resolve hostnames against the hosts file prior to asking to remotes DNS servers.
-
close
public void close()
Closes the internal datagram channel used for sending and receiving DNS messages, and clears all DNS resource records from the cache. Attempting to send a DNS query or to resolve a domain name will fail once this method has been called.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceNameResolver<java.net.InetAddress>- Overrides:
closein classSimpleNameResolver<java.net.InetAddress>
-
executor
protected EventLoop executor()
Description copied from class:SimpleNameResolverReturns theEventExecutorwhich is used to notify the listeners of theFuturereturned bySimpleNameResolver.resolve(String).- Overrides:
executorin classSimpleNameResolver<java.net.InetAddress>
-
resolve
public final Future<java.net.InetAddress> resolve(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals)
Resolves the specified name into an address.- Parameters:
inetHost- the name to resolveadditionals- additional records (OPT)- Returns:
- the address as the result of the resolution
-
resolve
public final Future<java.net.InetAddress> resolve(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals, Promise<java.net.InetAddress> promise)
Resolves the specified name into an address.- Parameters:
inetHost- the name to resolveadditionals- additional records (OPT)promise- thePromisewhich will be fulfilled when the name resolution is finished- Returns:
- the address as the result of the resolution
-
resolveAll
public final Future<java.util.List<java.net.InetAddress>> resolveAll(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals)
Resolves the specified host name and port into a list of address.- Parameters:
inetHost- the name to resolveadditionals- additional records (OPT)- Returns:
- the list of the address as the result of the resolution
-
resolveAll
public final Future<java.util.List<java.net.InetAddress>> resolveAll(java.lang.String inetHost, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<java.net.InetAddress>> promise)
Resolves the specified host name and port into a list of address.- Parameters:
inetHost- the name to resolveadditionals- additional records (OPT)promise- thePromisewhich will be fulfilled when the name resolution is finished- Returns:
- the list of the address as the result of the resolution
-
doResolve
protected void doResolve(java.lang.String inetHost, Promise<java.net.InetAddress> promise) throws java.lang.ExceptionDescription copied from class:SimpleNameResolverInvoked bySimpleNameResolver.resolve(String)to perform the actual name resolution.- Specified by:
doResolvein classSimpleNameResolver<java.net.InetAddress>- Throws:
java.lang.Exception
-
resolveAll
public final Future<java.util.List<DnsRecord>> resolveAll(DnsQuestion question)
Resolves theDnsRecords that are matched by the specifiedDnsQuestion. Unlikequery(DnsQuestion), this method handles redirection, CNAMEs and multiple name servers. If the specifiedDnsQuestionisAorAAAA, this method looks up the configuredHostsFileEntriesbefore sending a query to the name servers. If a match is found in theHostsFileEntries, a syntheticAorAAAArecord will be returned.- Parameters:
question- the question- Returns:
- the list of the
DnsRecords as the result of the resolution
-
resolveAll
public final Future<java.util.List<DnsRecord>> resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)
Resolves theDnsRecords that are matched by the specifiedDnsQuestion. Unlikequery(DnsQuestion), this method handles redirection, CNAMEs and multiple name servers. If the specifiedDnsQuestionisAorAAAA, this method looks up the configuredHostsFileEntriesbefore sending a query to the name servers. If a match is found in theHostsFileEntries, a syntheticAorAAAArecord will be returned.- Parameters:
question- the questionadditionals- additional records (OPT)- Returns:
- the list of the
DnsRecords as the result of the resolution
-
resolveAll
public final Future<java.util.List<DnsRecord>> resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<DnsRecord>> promise)
Resolves theDnsRecords that are matched by the specifiedDnsQuestion. Unlikequery(DnsQuestion), this method handles redirection, CNAMEs and multiple name servers. If the specifiedDnsQuestionisAorAAAA, this method looks up the configuredHostsFileEntriesbefore sending a query to the name servers. If a match is found in theHostsFileEntries, a syntheticAorAAAArecord will be returned.
-
doResolve
protected void doResolve(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache) throws java.lang.ExceptionHook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.- Throws:
java.lang.Exception
-
doResolveAll
protected void doResolveAll(java.lang.String inetHost, Promise<java.util.List<java.net.InetAddress>> promise) throws java.lang.ExceptionDescription copied from class:SimpleNameResolverInvoked bySimpleNameResolver.resolveAll(String)to perform the actual name resolution.- Specified by:
doResolveAllin classSimpleNameResolver<java.net.InetAddress>- Throws:
java.lang.Exception
-
doResolveAll
protected void doResolveAll(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache) throws java.lang.ExceptionHook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.- Throws:
java.lang.Exception
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(DnsQuestion question)
Sends a DNS query with the specified question.
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records.
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
Sends a DNS query with the specified question.
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question)
Sends a DNS query with the specified question using the specified name server list.
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, java.lang.Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records using the specified name server list.
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
Sends a DNS query with the specified question using the specified name server list.
-
query
public Future<AddressedEnvelope<DnsResponse,java.net.InetSocketAddress>> query(java.net.InetSocketAddress nameServerAddr, DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<AddressedEnvelope<? extends DnsResponse,java.net.InetSocketAddress>> promise)
Sends a DNS query with the specified question with additional records using the specified name server list.
-
isTransportOrTimeoutError
public static boolean isTransportOrTimeoutError(java.lang.Throwable cause)
Returnstrueif theThrowablewas caused by an timeout or transport error. These methods can be used on theFuture.cause()that is returned by the various methods exposed by thisDnsNameResolver.
-
isTimeoutError
public static boolean isTimeoutError(java.lang.Throwable cause)
Returnstrueif theThrowablewas caused by an timeout. These methods can be used on theFuture.cause()that is returned by the various methods exposed by thisDnsNameResolver.
-
-