- java.lang.Object
-
- io.netty5.resolver.SimpleNameResolver<InetAddress>
-
- io.netty5.resolver.InetNameResolver
-
- io.netty5.resolver.dns.DnsNameResolver
-
- All Implemented Interfaces:
NameResolver<InetAddress>
,Closeable
,AutoCloseable
public class DnsNameResolver extends InetNameResolver
A DNS-basedInetNameResolver
.
-
-
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, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, 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, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, String[] searchDomains, int ndots, boolean decodeIdn)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthoritativeDnsServerCache
authoritativeDnsServerCache()
Returns the cache used for authoritative DNS servers for a domain.void
close()
Closes the internal datagram channel used for sending and receiving DNS messages, and clears all DNS resource records from the cache.DnsCnameCache
cnameCache()
Returns theDnsCnameCache
.protected void
doResolve(String inetHost, DnsRecord[] additionals, Promise<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 void
doResolve(String inetHost, Promise<InetAddress> promise)
Invoked bySimpleNameResolver.resolve(String)
to perform the actual name resolution.protected void
doResolveAll(String inetHost, DnsRecord[] additionals, Promise<List<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 void
doResolveAll(String inetHost, Promise<List<InetAddress>> promise)
Invoked bySimpleNameResolver.resolveAll(String)
to perform the actual name resolution.protected EventLoop
executor()
Returns theEventExecutor
which is used to notify the listeners of theFuture
returned bySimpleNameResolver.resolve(String)
.HostsFileEntriesResolver
hostsFileEntriesResolver()
Returns the component that tries to resolve hostnames against the hosts file prior to asking to remotes DNS servers.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.boolean
isRecursionDesired()
Returnstrue
if and only if this resolver sends a DNS query with the RD (recursion desired) flag set.static boolean
isTimeoutError(Throwable cause)
Returnstrue
if theThrowable
was caused by an timeout.static boolean
isTransportOrTimeoutError(Throwable cause)
Returnstrue
if theThrowable
was caused by an timeout or transport error.int
maxPayloadSize()
Returns the capacity of the datagram packet buffer (in bytes).int
maxQueriesPerResolve()
Returns the maximum allowed number of DNS queries to send when resolving a host name.protected DnsServerAddressStream
newRedirectDnsServerStream(String hostname, List<InetSocketAddress> nameservers)
Creates a newDnsServerAddressStream
to following a redirected DNS query.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(DnsQuestion question)
Sends a DNS query with the specified question.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,InetSocketAddress>> promise)
Sends a DNS query with the specified question.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(DnsQuestion question, Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(InetSocketAddress nameServerAddr, DnsQuestion question)
Sends a DNS query with the specified question using the specified name server list.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(InetSocketAddress nameServerAddr, DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,InetSocketAddress>> promise)
Sends a DNS query with the specified question using the specified name server list.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(InetSocketAddress nameServerAddr, DnsQuestion question, Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records using the specified name server list.Future<AddressedEnvelope<DnsResponse,InetSocketAddress>>
query(InetSocketAddress nameServerAddr, DnsQuestion question, Iterable<DnsRecord> additionals, Promise<AddressedEnvelope<? extends DnsResponse,InetSocketAddress>> promise)
Sends a DNS query with the specified question with additional records using the specified name server list.long
queryTimeoutMillis()
Returns the timeout of each DNS query performed by this resolver (in milliseconds).Future<InetAddress>
resolve(String inetHost, Iterable<DnsRecord> additionals)
Resolves the specified name into an address.Future<InetAddress>
resolve(String inetHost, Iterable<DnsRecord> additionals, Promise<InetAddress> promise)
Resolves the specified name into an address.Future<List<DnsRecord>>
resolveAll(DnsQuestion question)
Resolves theDnsRecord
s that are matched by the specifiedDnsQuestion
.Future<List<DnsRecord>>
resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals)
Resolves theDnsRecord
s that are matched by the specifiedDnsQuestion
.Future<List<DnsRecord>>
resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals, Promise<List<DnsRecord>> promise)
Resolves theDnsRecord
s that are matched by the specifiedDnsQuestion
.Future<List<InetAddress>>
resolveAll(String inetHost, Iterable<DnsRecord> additionals)
Resolves the specified host name and port into a list of address.Future<List<InetAddress>>
resolveAll(String inetHost, Iterable<DnsRecord> additionals, Promise<List<InetAddress>> promise)
Resolves the specified host name and port into a list of address.DnsCache
resolveCache()
Returns the resolution cache.ResolvedAddressTypes
resolvedAddressTypes()
Returns theResolvedAddressTypes
resolved bySimpleNameResolver.resolve(String)
.-
Methods inherited from class io.netty5.resolver.InetNameResolver
asAddressResolver
-
Methods inherited from class io.netty5.resolver.SimpleNameResolver
resolve, resolve, resolveAll, resolveAll
-
-
-
-
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, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, 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
- theEventLoop
which will perform the communication with the DNS serverschannelFactory
- theChannelFactory
that will create aDatagramChannel
resolveCache
- the DNS resolved entries cacheauthoritativeDnsServerCache
- the cache used to find the authoritative DNS server for a domaindnsQueryLifecycleObserverFactory
- used to generate new instances ofDnsQueryLifecycleObserver
which can be used to track metrics for DNS servers.queryTimeoutMillis
- timeout of each DNS query in millisresolvedAddressTypes
- the preferred address typesrecursionDesired
- if recursion desired flag must be setmaxQueriesPerResolve
- the maximum allowed number of DNS queries for a given name resolutionmaxPayloadSize
- the capacity of the datagram packet bufferoptResourceEnabled
- if automatic inclusion of a optional records is enabledhostsFileEntriesResolver
- theHostsFileEntriesResolver
used to check for local aliasesdnsServerAddressStreamProvider
- TheDnsServerAddressStreamProvider
used 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
-true
if 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, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, 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
- theEventLoop
which will perform the communication with the DNS serverschannelFactory
- theChannelFactory
that will create aDatagramChannel
resolveCache
- the DNS resolved entries cacheauthoritativeDnsServerCache
- the cache used to find the authoritative DNS server for a domaindnsQueryLifecycleObserverFactory
- used to generate new instances ofDnsQueryLifecycleObserver
which can be used to track metrics for DNS servers.queryTimeoutMillis
- timeout of each DNS query in millisresolvedAddressTypes
- the preferred address typesrecursionDesired
- if recursion desired flag must be setmaxQueriesPerResolve
- the maximum allowed number of DNS queries for a given name resolutionmaxPayloadSize
- the capacity of the datagram packet bufferoptResourceEnabled
- if automatic inclusion of a optional records is enabledhostsFileEntriesResolver
- theHostsFileEntriesResolver
used to check for local aliasesdnsServerAddressStreamProvider
- TheDnsServerAddressStreamProvider
used 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
-true
if domain / host names should be decoded to unicode when received. See rfc3492.
-
-
Method Detail
-
newRedirectDnsServerStream
protected DnsServerAddressStream newRedirectDnsServerStream(String hostname, List<InetSocketAddress> nameservers)
Creates a newDnsServerAddressStream
to 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 usedDnsServerAddressStream
must allow unresolved addresses if you want to include these as well.- Returns:
- A
DnsServerAddressStream
which will be used to follow the DNS redirect ornull
if 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.
-
resolvedAddressTypes
public ResolvedAddressTypes resolvedAddressTypes()
Returns theResolvedAddressTypes
resolved bySimpleNameResolver.resolve(String)
. The default value depends on the value of the system property"java.net.preferIPv6Addresses"
.
-
isRecursionDesired
public boolean isRecursionDesired()
Returnstrue
if 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 is4096
bytes.
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceNameResolver<InetAddress>
- Overrides:
close
in classSimpleNameResolver<InetAddress>
-
executor
protected EventLoop executor()
Description copied from class:SimpleNameResolver
Returns theEventExecutor
which is used to notify the listeners of theFuture
returned bySimpleNameResolver.resolve(String)
.- Overrides:
executor
in classSimpleNameResolver<InetAddress>
-
resolve
public final Future<InetAddress> resolve(String inetHost, 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<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals, Promise<InetAddress> promise)
Resolves the specified name into an address.- Parameters:
inetHost
- the name to resolveadditionals
- additional records (OPT
)promise
- thePromise
which will be fulfilled when the name resolution is finished- Returns:
- the address as the result of the resolution
-
resolveAll
public final Future<List<InetAddress>> resolveAll(String inetHost, 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<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals, Promise<List<InetAddress>> promise)
Resolves the specified host name and port into a list of address.- Parameters:
inetHost
- the name to resolveadditionals
- additional records (OPT
)promise
- thePromise
which 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(String inetHost, Promise<InetAddress> promise) throws Exception
Description copied from class:SimpleNameResolver
Invoked bySimpleNameResolver.resolve(String)
to perform the actual name resolution.- Specified by:
doResolve
in classSimpleNameResolver<InetAddress>
- Throws:
Exception
-
resolveAll
public final Future<List<DnsRecord>> resolveAll(DnsQuestion question)
Resolves theDnsRecord
s that are matched by the specifiedDnsQuestion
. Unlikequery(DnsQuestion)
, this method handles redirection, CNAMEs and multiple name servers. If the specifiedDnsQuestion
isA
orAAAA
, this method looks up the configuredHostsFileEntries
before sending a query to the name servers. If a match is found in theHostsFileEntries
, a syntheticA
orAAAA
record will be returned.- Parameters:
question
- the question- Returns:
- the list of the
DnsRecord
s as the result of the resolution
-
resolveAll
public final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals)
Resolves theDnsRecord
s that are matched by the specifiedDnsQuestion
. Unlikequery(DnsQuestion)
, this method handles redirection, CNAMEs and multiple name servers. If the specifiedDnsQuestion
isA
orAAAA
, this method looks up the configuredHostsFileEntries
before sending a query to the name servers. If a match is found in theHostsFileEntries
, a syntheticA
orAAAA
record will be returned.- Parameters:
question
- the questionadditionals
- additional records (OPT
)- Returns:
- the list of the
DnsRecord
s as the result of the resolution
-
resolveAll
public final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals, Promise<List<DnsRecord>> promise)
Resolves theDnsRecord
s that are matched by the specifiedDnsQuestion
. Unlikequery(DnsQuestion)
, this method handles redirection, CNAMEs and multiple name servers. If the specifiedDnsQuestion
isA
orAAAA
, this method looks up the configuredHostsFileEntries
before sending a query to the name servers. If a match is found in theHostsFileEntries
, a syntheticA
orAAAA
record will be returned.
-
doResolve
protected void doResolve(String inetHost, DnsRecord[] additionals, Promise<InetAddress> promise, DnsCache resolveCache) throws Exception
Hook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.- Throws:
Exception
-
doResolveAll
protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception
Description copied from class:SimpleNameResolver
Invoked bySimpleNameResolver.resolveAll(String)
to perform the actual name resolution.- Specified by:
doResolveAll
in classSimpleNameResolver<InetAddress>
- Throws:
Exception
-
doResolveAll
protected void doResolveAll(String inetHost, DnsRecord[] additionals, Promise<List<InetAddress>> promise, DnsCache resolveCache) throws Exception
Hook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.- Throws:
Exception
-
query
public Future<AddressedEnvelope<DnsResponse,InetSocketAddress>> query(DnsQuestion question)
Sends a DNS query with the specified question.
-
query
public Future<AddressedEnvelope<DnsResponse,InetSocketAddress>> query(DnsQuestion question, Iterable<DnsRecord> additionals)
Sends a DNS query with the specified question with additional records.
-
query
public Future<AddressedEnvelope<DnsResponse,InetSocketAddress>> query(DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,InetSocketAddress>> promise)
Sends a DNS query with the specified question.
-
query
public Future<AddressedEnvelope<DnsResponse,InetSocketAddress>> query(InetSocketAddress nameServerAddr, DnsQuestion question)
Sends a DNS query with the specified question using the specified name server list.
-
query
public Future<AddressedEnvelope<DnsResponse,InetSocketAddress>> query(InetSocketAddress nameServerAddr, DnsQuestion question, 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,InetSocketAddress>> query(InetSocketAddress nameServerAddr, DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse,InetSocketAddress>> promise)
Sends a DNS query with the specified question using the specified name server list.
-
query
public Future<AddressedEnvelope<DnsResponse,InetSocketAddress>> query(InetSocketAddress nameServerAddr, DnsQuestion question, Iterable<DnsRecord> additionals, Promise<AddressedEnvelope<? extends DnsResponse,InetSocketAddress>> promise)
Sends a DNS query with the specified question with additional records using the specified name server list.
-
isTransportOrTimeoutError
public static boolean isTransportOrTimeoutError(Throwable cause)
Returnstrue
if theThrowable
was caused by an timeout or transport error. These methods can be used on theAsynchronousResult.cause()
that is returned by the various methods exposed by thisDnsNameResolver
.
-
isTimeoutError
public static boolean isTimeoutError(Throwable cause)
Returnstrue
if theThrowable
was caused by an timeout. These methods can be used on theAsynchronousResult.cause()
that is returned by the various methods exposed by thisDnsNameResolver
.
-
-