Top Description Inners Fields Constructors Methods
io.netty5.resolver.dns

public Class DnsNameResolver

extends InetNameResolver
Class Inheritance
Imports
io.netty5.bootstrap.Bootstrap, io.netty5.buffer.Buffer, io.netty5.channel.AddressedEnvelope, .Channel, .ChannelFactory, .ChannelHandler, .ChannelHandlerContext, .ChannelInitializer, .ChannelOption, .EventLoop, .FixedReadHandleFactory, io.netty5.channel.socket.DatagramPacket, .DatagramChannel, .SocketChannel, io.netty5.handler.codec.CorruptedFrameException, io.netty5.handler.codec.dns.DatagramDnsQueryEncoder, .DatagramDnsResponse, .DatagramDnsResponseDecoder, .DefaultDnsRawRecord, .DnsQuestion, .DnsRawRecord, .DnsRecord, .DnsRecordType, .DnsResponse, .TcpDnsQueryEncoder, .TcpDnsResponseDecoder, io.netty5.resolver.DefaultHostsFileEntriesResolver, .HostsFileEntries, .HostsFileEntriesResolver, .InetNameResolver, .ResolvedAddressTypes, io.netty5.util.NetUtil, .ReferenceCounted, io.netty5.util.concurrent.EventExecutor, .FastThreadLocal, .Future, .Promise, io.netty5.util.internal.EmptyArrays, .PlatformDependent, .StringUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.net.IDN, .Inet4Address, .Inet6Address, .InetAddress, .InetSocketAddress, .NetworkInterface, .ProtocolFamily, .SocketAddress, .SocketException, .StandardProtocolFamily, java.util.ArrayList, .Collection, .Collections, .Comparator, .Enumeration, .Iterator, .List, java.util.concurrent.TimeUnit

A DNS-based InetNameResolver.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
private final AuthoritativeDnsServerCache
pack-priv final Channel
pack-priv final Promise<Channel>
private final DnsCnameCache
private final boolean
private static final DatagramDnsResponseDecoder
private static final DatagramDnsQueryEncoder
private final boolean
private static final UnixResolverOptions
pack-priv static final ResolvedAddressTypes
pack-priv static final String[]
private final DnsQueryLifecycleObserverFactory
private final DnsServerAddressStreamProvider
private static final DnsRecord[]
private final HostsFileEntriesResolver
private static final ProtocolFamily[]
private static final DnsRecordType[]
private static final ProtocolFamily[]
private static final DnsRecordType[]
private static final ProtocolFamily[]
private static final DnsRecordType[]
private static final ProtocolFamily[]
private static final DnsRecordType[]
private static final String
private static final InetAddress
private static final InternalLogger
private final int
private final int
private final FastThreadLocal<DnsServerAddressStream>
private final Comparator<InetSocketAddress>
private final int
private final boolean
private final ProtocolFamily
pack-priv final DnsQueryContextManager
queryContextManager

Manages the DnsQueryContexts in progress and their query IDs.

private final long
private final boolean
private final DnsCache
private final ResolvedAddressTypes
private final ProtocolFamily[]
private final DnsRecordType[]
private final String[]
private final ChannelFactory<? extends SocketChannel>
private final boolean
private final boolean
private static final TcpDnsQueryEncoder
private static final String

Constructor Summary

AccessConstructor and Description
public
DnsNameResolver(EventLoop
the EventLoop which will perform the communication with the DNS servers
eventLoop
,
ChannelFactory<? extends DatagramChannel>
the ChannelFactory that will create a DatagramChannel
channelFactory
,
final DnsCache
the DNS resolved entries cache
resolveCache
,
final DnsCache
the cache used to find the authoritative DNS server for a domain
authoritativeDnsServerCache
,
DnsQueryLifecycleObserverFactory
used to generate new instances of DnsQueryLifecycleObserver which can be used to track metrics for DNS servers.
dnsQueryLifecycleObserverFactory
,
long
timeout of each DNS query in millis
queryTimeoutMillis
,
ResolvedAddressTypes
the preferred address types
resolvedAddressTypes
,
boolean
if recursion desired flag must be set
recursionDesired
,
int
the maximum allowed number of DNS queries for a given name resolution
maxQueriesPerResolve
,
int
the capacity of the datagram packet buffer
maxPayloadSize
,
boolean
if automatic inclusion of a optional records is enabled
optResourceEnabled
,
HostsFileEntriesResolver
the HostsFileEntriesResolver used to check for local aliases
hostsFileEntriesResolver
,
DnsServerAddressStreamProvider
The DnsServerAddressStreamProvider used to determine the name servers for each hostname lookup.
dnsServerAddressStreamProvider
,
String[]
the list of search domain (can be null, if so, will try to default to the underlying platform ones)
searchDomains
,
int
the ndots value
ndots
,
boolean
true if domain / host names should be decoded to unicode when received. See rfc3492.
decodeIdn
)

Deprecated Use DnsNameResolverBuilder.
Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
public
DnsNameResolver(EventLoop
the EventLoop which will perform the communication with the DNS servers
eventLoop
,
ChannelFactory<? extends DatagramChannel>
the ChannelFactory that will create a DatagramChannel
channelFactory
,
final DnsCache
the DNS resolved entries cache
resolveCache
,
final AuthoritativeDnsServerCache
the cache used to find the authoritative DNS server for a domain
authoritativeDnsServerCache
,
DnsQueryLifecycleObserverFactory
used to generate new instances of DnsQueryLifecycleObserver which can be used to track metrics for DNS servers.
dnsQueryLifecycleObserverFactory
,
long
timeout of each DNS query in millis
queryTimeoutMillis
,
ResolvedAddressTypes
the preferred address types
resolvedAddressTypes
,
boolean
if recursion desired flag must be set
recursionDesired
,
int
the maximum allowed number of DNS queries for a given name resolution
maxQueriesPerResolve
,
int
the capacity of the datagram packet buffer
maxPayloadSize
,
boolean
if automatic inclusion of a optional records is enabled
optResourceEnabled
,
HostsFileEntriesResolver
the HostsFileEntriesResolver used to check for local aliases
hostsFileEntriesResolver
,
DnsServerAddressStreamProvider
The DnsServerAddressStreamProvider used to determine the name servers for each hostname lookup.
dnsServerAddressStreamProvider
,
String[]
the list of search domain (can be null, if so, will try to default to the underlying platform ones)
searchDomains
,
int
the ndots value
ndots
,
boolean
true if domain / host names should be decoded to unicode when received. See rfc3492.
decodeIdn
)

Deprecated Use DnsNameResolverBuilder.
Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
pack-priv
DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, ChannelFactory<? extends SocketChannel> socketChannelFactory, final DnsCache resolveCache, final DnsCnameCache cnameCache, final 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, boolean completeOncePreferredResolved)

pack-priv
DnsNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, ChannelFactory<? extends SocketChannel> socketChannelFactory, final DnsCache resolveCache, final DnsCnameCache cnameCache, final AuthoritativeDnsServerCache authoritativeDnsServerCache, SocketAddress localAddress, DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory, long queryTimeoutMillis, ResolvedAddressTypes resolvedAddressTypes, boolean recursionDesired, int maxQueriesPerResolve, int maxPayloadSize, boolean optResourceEnabled, HostsFileEntriesResolver hostsFileEntriesResolver, DnsServerAddressStreamProvider dnsServerAddressStreamProvider, String[] searchDomains, int ndots, boolean decodeIdn, boolean completeOncePreferredResolved)

Method Summary

Modifier and TypeMethod and Description
private static boolean
anyInterfaceSupportsIpV6()

Returns true if any NetworkInterface supports IPv6, false otherwise.

public AuthoritativeDnsServerCache
authoritativeDnsServerCache()

Returns the cache used for authoritative DNS servers for a domain.

private static Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>>
cast(Promise<?> promise)

public void
close()

Overrides io.netty5.resolver.SimpleNameResolver.close.

Implements io.netty5.resolver.NameResolver.close.

Closes the internal datagram channel used for sending and receiving DNS messages, and clears all DNS resource records from the cache.
public DnsCnameCache
cnameCache()

Returns the DnsCnameCache.

pack-priv final DnsQueryLifecycleObserverFactory
protected void
doResolve(String inetHost, Promise<InetAddress> promise)

Implements abstract io.netty5.resolver.SimpleNameResolver.doResolve.

Invoked by resolve(String) to perform the actual name resolution.
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
doResolveAll(String inetHost, Promise<List<InetAddress>> promise)

Implements abstract io.netty5.resolver.SimpleNameResolver.doResolveAll.

Invoked by resolveAll(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.

pack-priv static boolean
doResolveAllCached(String hostname, DnsRecord[] additionals, Promise<List<InetAddress>> promise, DnsCache resolveCache, ProtocolFamily[] resolvedInternetProtocolFamilies)

private void
doResolveAllUncached(final String hostname, final DnsRecord[] additionals, final Promise<?> originalPromise, final Promise<List<InetAddress>> promise, final DnsCache resolveCache, final boolean completeEarlyIfPossible)

private void
doResolveAllUncached0(String hostname, DnsRecord[] additionals, Promise<?> originalPromise, Promise<List<InetAddress>> promise, DnsCache resolveCache, boolean completeEarlyIfPossible)

private boolean
doResolveCached(String hostname, DnsRecord[] additionals, Promise<InetAddress> promise, DnsCache resolveCache)

private void
doResolveUncached(String hostname, DnsRecord[] additionals, final Promise<InetAddress> promise, DnsCache resolveCache)

protected EventLoop
executor()

Overrides io.netty5.resolver.SimpleNameResolver.executor.

Returns the EventExecutor which is used to notify the listeners of the Future returned by resolve(String).
pack-priv final void
private static String
hostname(String inetHost)

public HostsFileEntriesResolver
hostsFileEntriesResolver()

Returns the component that tries to resolve hostnames against the hosts file prior to asking to remotes DNS servers.

pack-priv final boolean
private static boolean
isLocalWindowsHost(String hostname)

Checks whether the given hostname is the localhost/host (computer) name on Windows OS.

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.

public boolean
isRecursionDesired()

Returns true if and only if this resolver sends a DNS query with the RD (recursion desired) flag set.

public static boolean
isTimeoutError(Throwable cause)

Returns true if the Throwable was caused by an timeout.

public static boolean
isTransportOrTimeoutError(Throwable cause)

Returns true if the Throwable was caused by an timeout or transport error.

private InetAddress
public int
maxPayloadSize()

Returns the capacity of the datagram packet buffer (in bytes).

public int
maxQueriesPerResolve()

Returns the maximum allowed number of DNS queries to send when resolving a host name.

pack-priv final int
pack-priv final DnsServerAddressStream
protected DnsServerAddressStream

Returns:

A DnsServerAddressStream which will be used to follow the DNS redirect or null if none should be followed.
newRedirectDnsServerStream
(String
the hostname.
hostname
,
List<InetSocketAddress>
The addresses of the DNS servers which are used in the event of a redirect. This may contain resolved and unresolved addresses so the used DnsServerAddressStream must allow unresolved addresses if you want to include these as well.
nameservers
)

Creates a new DnsServerAddressStream to following a redirected DNS query.

pack-priv InetSocketAddress
private InetSocketAddress
pack-priv static ProtocolFamily
pack-priv final ProtocolFamily
public Future<AddressedEnvelope<DnsResponse, InetSocketAddress>>
query(DnsQuestion question)

Sends a DNS query with the specified question.

public Future<AddressedEnvelope<DnsResponse, InetSocketAddress>>
query(DnsQuestion question, Iterable<DnsRecord> additionals)

Sends a DNS query with the specified question with additional records.

public Future<AddressedEnvelope<DnsResponse, InetSocketAddress>>
query(DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise)

Sends a DNS query with the specified question.

public Future<AddressedEnvelope<DnsResponse, InetSocketAddress>>
query(InetSocketAddress nameServerAddr, DnsQuestion question)

Sends a DNS query with the specified question using the specified name server list.

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.

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.

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.

pack-priv final Future<AddressedEnvelope<DnsResponse, InetSocketAddress>>
query0(InetSocketAddress nameServerAddr, DnsQuestion question, DnsRecord[] additionals, boolean flush, Promise<Void> writePromise, Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise)

public long
queryTimeoutMillis()

Returns the timeout of each DNS query performed by this resolver (in milliseconds).

public final Future<InetAddress>

Returns:

the address as the result of the resolution
resolve
(String
the name to resolve
inetHost
,
Iterable<DnsRecord>
additional records (OPT)
additionals
)

Resolves the specified name into an address.

public final Future<InetAddress>

Returns:

the address as the result of the resolution
resolve
(String
the name to resolve
inetHost
,
Iterable<DnsRecord>
additional records (OPT)
additionals
,
Promise<InetAddress>
the Promise which will be fulfilled when the name resolution is finished
promise
)

Resolves the specified name into an address.

public final Future<List<InetAddress>>

Returns:

the list of the address as the result of the resolution
resolveAll
(String
the name to resolve
inetHost
,
Iterable<DnsRecord>
additional records (OPT)
additionals
)

Resolves the specified host name and port into a list of address.

public final Future<List<InetAddress>>

Returns:

the list of the address as the result of the resolution
resolveAll
(String
the name to resolve
inetHost
,
Iterable<DnsRecord>
additional records (OPT)
additionals
,
Promise<List<InetAddress>>
the Promise which will be fulfilled when the name resolution is finished
promise
)

Resolves the specified host name and port into a list of address.

public final Future<List<DnsRecord>>

Returns:

the list of the DnsRecords as the result of the resolution
resolveAll
(DnsQuestion
the question
question
)

Resolves the DnsRecords that are matched by the specified DnsQuestion.

public final Future<List<DnsRecord>>

Returns:

the list of the DnsRecords as the result of the resolution
resolveAll
(DnsQuestion
the question
question
,
Iterable<DnsRecord>
additional records (OPT)
additionals
)

Resolves the DnsRecords that are matched by the specified DnsQuestion.

public final Future<List<DnsRecord>>

Returns:

the list of the DnsRecords as the result of the resolution
resolveAll
(DnsQuestion
the question
question
,
Iterable<DnsRecord>
additional records (OPT)
additionals
,
Promise<List<DnsRecord>>
the Promise which will be fulfilled when the resolution is finished
promise
)

Resolves the DnsRecords that are matched by the specified DnsQuestion.

private Future<List<DnsRecord>>
resolveAll(DnsQuestion question, DnsRecord[] additionals, Promise<List<DnsRecord>> promise)

public DnsCache
resolveCache()

Returns the resolution cache.

public ResolvedAddressTypes
pack-priv ProtocolFamily[]
private List<InetAddress>
private InetAddress
pack-priv final DnsRecordType[]
pack-priv final String[]
pack-priv final boolean
pack-priv final boolean
private static DnsRecord[]
toArray(Iterable<DnsRecord> additionals, boolean validateType)

private static void
tryFailure(Promise<?> promise, Throwable cause)

pack-priv static <T> boolean
trySuccess(Promise<T> promise, T result)

private static void
validateAdditional(DnsRecord record, boolean validateType)

Inherited from io.netty5.resolver.InetNameResolver:
asAddressResolver