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
A DNS-based
InetNameResolver.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classprivate static interfaceprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AuthoritativeDnsServerCacheprivate final DnsCnameCacheprivate final booleanprivate static final DatagramDnsResponseDecoderprivate static final DatagramDnsQueryEncoderprivate final booleanprivate static final UnixResolverOptions(package private) static final ResolvedAddressTypes(package private) static final java.lang.String[]static final AttributeKey<java.lang.Boolean> An attribute used to mark all channels created by theDnsNameResolver.private final DnsQueryLifecycleObserverFactoryprivate final DnsServerAddressStreamProviderprivate static final java.lang.Stringprivate static final DnsRecord[]private final HostsFileEntriesResolverprivate final java.util.Map<DnsQuestion, Promise<AddressedEnvelope<? extends DnsResponse, java.net.InetSocketAddress>>> private static final SocketProtocolFamily[]private static final DnsRecordType[]private static final SocketProtocolFamily[]private static final DnsRecordType[]private static final SocketProtocolFamily[]private static final DnsRecordType[]private static final SocketProtocolFamily[]private static final DnsRecordType[]private static final java.lang.Stringprivate static final InternalLoggerprivate final intprivate final intprivate final intprivate final java.util.Comparator<java.net.InetSocketAddress> private final intprivate static final ChannelHandlerprivate final booleanprivate final SocketProtocolFamilyprivate final DnsQueryContextManagerManages theDnsQueryContexts in progress and their query IDs.private final DnsServerAddressStreamprivate final DnsQueryProtectionprivate final longprivate final booleanprivate static final GenericFutureListener<Future<? super AddressedEnvelope<? extends DnsResponse, java.net.InetSocketAddress>>> private static final java.lang.StringSystem property to control RFC 6761 localhost resolution.private final DnsCacheCache fordoResolve(String, Promise)anddoResolveAll(String, Promise).private final DnsNameResolver.DnsResolveChannelProviderprivate final ResolvedAddressTypesprivate final SocketProtocolFamily[](package private) static booleanThe runtime value ofRESOLVE_LOCALHOST_WITHOUT_DNS_PROPERTY.private final DnsRecordType[]private final booleanprivate final java.lang.String[]private final Bootstrapprivate final booleanprivate final booleanprivate static final java.lang.String -
Constructor Summary
ConstructorsConstructorDescriptionDnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, ChannelFactory<? extends SocketChannel> socketChannelFactory, boolean retryWithTcpOnTimeout, DnsCache resolveCache, DnsCnameCache cnameCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, java.net.SocketAddress localAddress, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, DnsServerAddressStream queryDnsServerAddressStream, java.lang.String[] searchDomains, int ndots, boolean decodeIdn, boolean completeOncePreferredResolved, int maxNumConsolidation, DnsNameResolverChannelStrategy datagramChannelStrategy) DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, ChannelFactory<? extends SocketChannel> socketChannelFactory, boolean retryWithTcpOnTimeout, DnsCache resolveCache, DnsCnameCache cnameCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, java.net.SocketAddress localAddress, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, DnsServerAddressStream queryDnsServerAddressStream, java.lang.String[] searchDomains, int ndots, boolean decodeIdn, boolean completeOncePreferredResolved, int maxNumConsolidation, DnsNameResolverChannelStrategy datagramChannelStrategy, boolean caseRandomizationEnabled, boolean dnsCookiesEnabled) 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
Modifier and TypeMethodDescription(package private) static java.lang.Class<? extends java.net.InetAddress> private static booleanReturnstrueif anyNetworkInterfacesupportsIPv6,falseotherwise.Returns the cache used for authoritative DNS servers for a domain.private static Promise<AddressedEnvelope<DnsResponse, java.net.InetSocketAddress>> voidclose()Closes the internal datagram channel used for sending and receiving DNS messages, and clears all DNS resource records from the cache.Returns theDnsCnameCache.(package private) final DnsQueryLifecycleObserverFactory(package private) final Future<AddressedEnvelope<DnsResponse, java.net.InetSocketAddress>> doQuery(Channel channel, java.net.InetSocketAddress nameServerAddr, DnsQuestion question, DnsQueryLifecycleObserver queryLifecycleObserver, DnsRecord[] additionals, boolean flush, Promise<AddressedEnvelope<? extends DnsResponse, java.net.InetSocketAddress>> promise) private voiddoQueryNow(Channel channel, java.net.InetSocketAddress nameServerAddr, DnsQuestion question, DnsQueryLifecycleObserver queryLifecycleObserver, DnsRecord[] additionals, boolean flush, int payloadSize, Promise<AddressedEnvelope<DnsResponse, java.net.InetSocketAddress>> promise) 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 voidInvoked 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.(package private) static booleandoResolveAllCached(java.lang.String hostname, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache, java.lang.String[] searchDomains, int ndots, SocketProtocolFamily[] resolvedInternetProtocolFamilies) private voiddoResolveAllNow(ChannelFuture f, java.lang.String hostname, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache) private voiddoResolveAllUncached(Channel channel, java.lang.String hostname, DnsRecord[] additionals, Promise<?> originalPromise, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache, boolean completeEarlyIfPossible) private voiddoResolveAllUncached0(Channel channel, java.lang.String hostname, DnsRecord[] additionals, Promise<?> originalPromise, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache, boolean completeEarlyIfPossible) private booleandoResolveCached(java.lang.String hostname, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache) private voiddoResolveNow(ChannelFuture f, java.lang.String hostname, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache) private voiddoResolveUncached(Channel channel, java.lang.String hostname, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache, boolean completeEarlyIfPossible) protected EventLoopexecutor()Returns theEventExecutorwhich is used to notify the listeners of theFuturereturned bySimpleNameResolver.resolve(String).private java.net.InetAddressprivate static java.util.List<java.lang.String> private static booleanhasEntries(java.util.List<? extends DnsCacheEntry> cachedEntries) private static java.lang.Stringhostname(java.lang.String inetHost) Returns the component that tries to resolve hostnames against the hosts file prior to asking to remotes DNS servers.booleanReturnstrueif the case of the name in the questions of UDP queries is randomized ("0x20").(package private) final booleanbooleanReturnstrueif a client cookie as defined by RFC 7873 is sent with UDP queries and validated in the responses.private static booleanisLocalHostAddress(java.lang.String hostname) Checks whether the given hostname refers to the current computer.booleanReturns 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.booleanReturnstrueif 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.private java.net.InetAddressintReturns the capacity of the datagram packet buffer (in bytes).intReturns the maximum allowed number of DNS queries to send when resolving a host name.(package private) final intndots()(package private) final DnsServerAddressStreamnewNameServerAddressStream(java.lang.String hostname) private static DnsNameResolver.DnsResolveChannelProvidernewProvider(DnsNameResolverChannelStrategy channelStrategy, Bootstrap bootstrap, java.net.SocketAddress localAddress) protected DnsServerAddressStreamnewRedirectDnsServerStream(java.lang.String hostname, java.util.List<java.net.InetSocketAddress> nameservers) Creates a newDnsServerAddressStreamto following a redirected DNS query.(package private) java.net.InetSocketAddressnewRedirectServerAddress(java.net.InetAddress server) private java.net.InetSocketAddress(package private) final SocketProtocolFamily(package private) static SocketProtocolFamilypreferredAddressType(ResolvedAddressTypes resolvedAddressTypes) 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.Returns the dns server address stream used for DNS queries (not resolve).longReturns the timeout of each DNS query performed by this resolver (in milliseconds).private static ChannelFutureregisterOrBind(Bootstrap bootstrap, java.net.SocketAddress localAddress) final Future<java.net.InetAddress> Resolves the specified name into an address.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.resolveAll(DnsQuestion question) Resolves theDnsRecords that are matched by the specifiedDnsQuestion.resolveAll(DnsQuestion question, DnsRecord[] additionals, Promise<java.util.List<DnsRecord>> promise) resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals) Resolves theDnsRecords that are matched by the specifiedDnsQuestion.resolveAll(DnsQuestion question, java.lang.Iterable<DnsRecord> additionals, Promise<java.util.List<DnsRecord>> promise) Resolves theDnsRecords that are matched by the specifiedDnsQuestion.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.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.private voidresolveAllNow(ChannelFuture f, java.lang.String hostname, DnsQuestion question, DnsRecord[] additionals, Promise<java.util.List<DnsRecord>> promise) Returns the resolution cache.Returns theResolvedAddressTypesresolved bySimpleNameResolver.resolve(String).(package private) SocketProtocolFamily[]private java.util.List<java.net.InetAddress> resolveHostsFileEntries(java.lang.String hostname) private java.net.InetAddressresolveHostsFileEntry(java.lang.String hostname) (package private) final DnsRecordType[](package private) final java.lang.String[](package private) final boolean(package private) final booleanprivate static DnsRecord[]private static java.net.UnknownHostExceptiontoException(ChannelFuture f, java.lang.String hostname, DnsQuestion question, DnsRecord[] additionals) private static voidtryFailure(Promise<?> promise, java.lang.Throwable cause) (package private) static <T> booleantrySuccess(Promise<T> promise, T result) private static voidvalidateAdditional(DnsRecord record, boolean validateType) Methods inherited from class InetNameResolver
asAddressResolverMethods inherited from class SimpleNameResolver
resolve, resolve, resolveAll, resolveAllMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DNS_PIPELINE_ATTRIBUTE
An attribute used to mark all channels created by theDnsNameResolver. -
logger
-
LOCALHOST
private static final java.lang.String LOCALHOST- See Also:
-
DOT_LOCALHOST
private static final java.lang.String DOT_LOCALHOST- See Also:
-
WINDOWS_HOST_NAME
private static final java.lang.String WINDOWS_HOST_NAME -
EMPTY_ADDITIONALS
-
IPV4_ONLY_RESOLVED_RECORD_TYPES
-
IPV4_ONLY_RESOLVED_PROTOCOL_FAMILIES
-
IPV4_PREFERRED_RESOLVED_RECORD_TYPES
-
IPV4_PREFERRED_RESOLVED_PROTOCOL_FAMILIES
-
IPV6_ONLY_RESOLVED_RECORD_TYPES
-
IPV6_ONLY_RESOLVED_PROTOCOL_FAMILIES
-
IPV6_PREFERRED_RESOLVED_RECORD_TYPES
-
IPV6_PREFERRED_RESOLVED_PROTOCOL_FAMILIES
-
NOOP_HANDLER
-
RESOLVE_LOCALHOST_WITHOUT_DNS_PROPERTY
private static final java.lang.String RESOLVE_LOCALHOST_WITHOUT_DNS_PROPERTYSystem property to control RFC 6761 localhost resolution.When
true(the default),localhostand*.localhostare resolved to the loopback address without querying DNS servers. Whenfalse, only the pre-#16749 rules apply (Windowslocalhostand the Windows machine hostname). Set tofalsewhen*.localhosthostnames must resolve via DNS to non-loopback addresses.- See Also:
-
resolveLocalhostWithoutDns
static boolean resolveLocalhostWithoutDnsThe runtime value ofRESOLVE_LOCALHOST_WITHOUT_DNS_PROPERTY. -
DEFAULT_RESOLVE_ADDRESS_TYPES
-
DEFAULT_SEARCH_DOMAINS
static final java.lang.String[] DEFAULT_SEARCH_DOMAINS -
DEFAULT_OPTIONS
-
DATAGRAM_DECODER
-
DATAGRAM_ENCODER
-
RELEASE_LISTENER
private static final GenericFutureListener<Future<? super AddressedEnvelope<? extends DnsResponse, java.net.InetSocketAddress>>> RELEASE_LISTENER -
nameServerComparator
private final java.util.Comparator<java.net.InetSocketAddress> nameServerComparator -
queryContextManager
Manages theDnsQueryContexts in progress and their query IDs. -
resolveCache
Cache fordoResolve(String, Promise)anddoResolveAll(String, Promise). -
authoritativeDnsServerCache
-
cnameCache
-
queryDnsServerAddressStream
-
queryTimeoutMillis
private final long queryTimeoutMillis -
maxQueriesPerResolve
private final int maxQueriesPerResolve -
resolvedAddressTypes
-
resolvedInternetProtocolFamilies
-
recursionDesired
private final boolean recursionDesired -
maxPayloadSize
private final int maxPayloadSize -
optResourceEnabled
private final boolean optResourceEnabled -
hostsFileEntriesResolver
-
dnsServerAddressStreamProvider
-
searchDomains
private final java.lang.String[] searchDomains -
ndots
private final int ndots -
supportsAAAARecords
private final boolean supportsAAAARecords -
supportsARecords
private final boolean supportsARecords -
preferredAddressType
-
resolveRecordTypes
-
decodeIdn
private final boolean decodeIdn -
dnsQueryLifecycleObserverFactory
-
completeOncePreferredResolved
private final boolean completeOncePreferredResolved -
queryProtection
-
resolveChannelProvider
-
socketBootstrap
-
retryWithTcpOnTimeout
private final boolean retryWithTcpOnTimeout -
maxNumConsolidation
private final int maxNumConsolidation -
inflightLookups
private final java.util.Map<DnsQuestion, Promise<AddressedEnvelope<? extends DnsResponse, java.net.InetSocketAddress>>> inflightLookups
-
-
Constructor Details
-
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.
-
DnsNameResolver
DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, ChannelFactory<? extends SocketChannel> socketChannelFactory, boolean retryWithTcpOnTimeout, DnsCache resolveCache, DnsCnameCache cnameCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, java.net.SocketAddress localAddress, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, DnsServerAddressStream queryDnsServerAddressStream, java.lang.String[] searchDomains, int ndots, boolean decodeIdn, boolean completeOncePreferredResolved, int maxNumConsolidation, DnsNameResolverChannelStrategy datagramChannelStrategy) -
DnsNameResolver
DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, ChannelFactory<? extends SocketChannel> socketChannelFactory, boolean retryWithTcpOnTimeout, DnsCache resolveCache, DnsCnameCache cnameCache, AuthoritativeDnsServerCache authoritativeDnsServerCache, java.net.SocketAddress localAddress, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, boolean traceEnabled, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, DnsServerAddressStream queryDnsServerAddressStream, java.lang.String[] searchDomains, int ndots, boolean decodeIdn, boolean completeOncePreferredResolved, int maxNumConsolidation, DnsNameResolverChannelStrategy datagramChannelStrategy, boolean caseRandomizationEnabled, boolean dnsCookiesEnabled)
-
-
Method Details
-
anyInterfaceSupportsIpV6
private static boolean anyInterfaceSupportsIpV6()Returnstrueif anyNetworkInterfacesupportsIPv6,falseotherwise. -
getSearchDomainsHack
private static java.util.List<java.lang.String> getSearchDomainsHack() throws java.lang.Exception- Throws:
java.lang.Exception
-
newProvider
private static DnsNameResolver.DnsResolveChannelProvider newProvider(DnsNameResolverChannelStrategy channelStrategy, Bootstrap bootstrap, java.net.SocketAddress localAddress) -
preferredAddressType
-
newRedirectServerAddress
java.net.InetSocketAddress newRedirectServerAddress(java.net.InetAddress server) -
dnsQueryLifecycleObserverFactory
-
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
Returns the resolution cache. -
cnameCache
Returns theDnsCnameCache. -
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
Returns the dns server address stream used for DNS queries (not resolve). -
resolvedAddressTypes
Returns theResolvedAddressTypesresolved bySimpleNameResolver.resolve(String). The default value depends on the value of the system property"java.net.preferIPv6Addresses". -
resolvedInternetProtocolFamiliesUnsafe
SocketProtocolFamily[] resolvedInternetProtocolFamiliesUnsafe() -
searchDomains
final java.lang.String[] searchDomains() -
ndots
final int ndots() -
supportsAAAARecords
final boolean supportsAAAARecords() -
supportsARecords
final boolean supportsARecords() -
preferredAddressType
-
resolveRecordTypes
-
isDecodeIdn
final boolean isDecodeIdn() -
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. -
isCaseRandomizationEnabled
public boolean isCaseRandomizationEnabled()Returnstrueif the case of the name in the questions of UDP queries is randomized ("0x20"). -
isDnsCookiesEnabled
public boolean isDnsCookiesEnabled()Returnstrueif a client cookie as defined by RFC 7873 is sent with UDP queries and validated in the responses. -
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
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
Description copied from class:SimpleNameResolverReturns theEventExecutorwhich is used to notify the listeners of theFuturereturned bySimpleNameResolver.resolve(String).- Overrides:
executorin classSimpleNameResolver<java.net.InetAddress>
-
resolveHostsFileEntry
private java.net.InetAddress resolveHostsFileEntry(java.lang.String hostname) -
resolveHostsFileEntries
private java.util.List<java.net.InetAddress> resolveHostsFileEntries(java.lang.String hostname) -
isLocalHostAddress
private static boolean isLocalHostAddress(java.lang.String hostname) Checks whether the given hostname refers to the current computer. This is the case for:- localhost.
- any domain within .localhost.
- the hostname of the local computer on Windows
According to RFC 6761 Section 6.3, localhost and subdomains of localhost should be resolved to the loopback address by name resolution libraries without querying DNS servers. The hostname of the local machine can usually be resolved from the hosts file, but on Windows, this is no longer possible.
RFC 6761 behavior for
localhostand*.localhostcan be disabled via theio.netty.resolver.dns.resolveLocalhostWithoutDnssystem property.- Parameters:
hostname- the hostname that's being looked up- Returns:
- true if the hostname should point to the loopback address. False otherwise.
- See Also:
-
getLocalHostAddress
private java.net.InetAddress getLocalHostAddress() -
resolve
-
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.Exception Description 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
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. -
resolveAll
-
resolveAllNow
private void resolveAllNow(ChannelFuture f, java.lang.String hostname, DnsQuestion question, DnsRecord[] additionals, Promise<java.util.List<DnsRecord>> promise) -
toException
private static java.net.UnknownHostException toException(ChannelFuture f, java.lang.String hostname, DnsQuestion question, DnsRecord[] additionals) -
toArray
-
validateAdditional
-
loopbackAddress
private java.net.InetAddress loopbackAddress() -
doResolve
protected void doResolve(java.lang.String inetHost, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache) throws java.lang.Exception Hook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.- Throws:
java.lang.Exception
-
doResolveNow
private void doResolveNow(ChannelFuture f, java.lang.String hostname, DnsRecord[] additionals, Promise<java.net.InetAddress> promise, DnsCache resolveCache) -
doResolveCached
-
addressType
-
trySuccess
-
tryFailure
-
doResolveUncached
-
doResolveAll
protected void doResolveAll(java.lang.String inetHost, Promise<java.util.List<java.net.InetAddress>> promise) throws java.lang.Exception Description 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.Exception Hook designed for extensibility so one can pass a different cache on each resolution attempt instead of using the global one.- Throws:
java.lang.Exception
-
doResolveAllNow
private void doResolveAllNow(ChannelFuture f, java.lang.String hostname, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache) -
hasEntries
-
doResolveAllCached
static boolean doResolveAllCached(java.lang.String hostname, DnsRecord[] additionals, Promise<java.util.List<java.net.InetAddress>> promise, DnsCache resolveCache, java.lang.String[] searchDomains, int ndots, SocketProtocolFamily[] resolvedInternetProtocolFamilies) -
doResolveAllUncached
-
doResolveAllUncached0
-
hostname
private static java.lang.String hostname(java.lang.String inetHost) -
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. -
nextNameServerAddress
private java.net.InetSocketAddress nextNameServerAddress() -
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. -
doQuery
final Future<AddressedEnvelope<DnsResponse, java.net.InetSocketAddress>> doQuery(Channel channel, java.net.InetSocketAddress nameServerAddr, DnsQuestion question, DnsQueryLifecycleObserver queryLifecycleObserver, DnsRecord[] additionals, boolean flush, Promise<AddressedEnvelope<? extends DnsResponse, java.net.InetSocketAddress>> promise) -
doQueryNow
private void doQueryNow(Channel channel, java.net.InetSocketAddress nameServerAddr, DnsQuestion question, DnsQueryLifecycleObserver queryLifecycleObserver, DnsRecord[] additionals, boolean flush, int payloadSize, Promise<AddressedEnvelope<DnsResponse, java.net.InetSocketAddress>> promise) -
cast
private static Promise<AddressedEnvelope<DnsResponse, java.net.InetSocketAddress>> cast(Promise<?> promise) -
newNameServerAddressStream
-
registerOrBind
private static ChannelFuture registerOrBind(Bootstrap bootstrap, java.net.SocketAddress localAddress)
-
DnsNameResolverBuilder.