2015-12-14 15:27:49 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2015 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
package io.netty.resolver.dns;
|
|
|
|
|
|
|
|
import io.netty.channel.ChannelFactory;
|
|
|
|
import io.netty.channel.EventLoop;
|
|
|
|
import io.netty.channel.ReflectiveChannelFactory;
|
|
|
|
import io.netty.channel.socket.DatagramChannel;
|
|
|
|
import io.netty.channel.socket.InternetProtocolFamily;
|
|
|
|
import io.netty.resolver.HostsFileEntriesResolver;
|
2017-02-08 16:43:15 +01:00
|
|
|
import io.netty.resolver.ResolvedAddressTypes;
|
2016-04-12 14:22:41 +02:00
|
|
|
import io.netty.util.internal.UnstableApi;
|
2015-12-14 15:27:49 +01:00
|
|
|
|
2016-10-31 07:23:22 +01:00
|
|
|
import java.util.ArrayList;
|
2018-04-26 08:04:01 +02:00
|
|
|
import java.util.Arrays;
|
2015-12-14 15:27:49 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2017-03-31 02:02:16 +02:00
|
|
|
import static io.netty.resolver.dns.DnsServerAddressStreamProviders.platformDefault;
|
2015-12-14 15:27:49 +01:00
|
|
|
import static io.netty.util.internal.ObjectUtil.checkNotNull;
|
2017-02-02 10:32:33 +01:00
|
|
|
import static io.netty.util.internal.ObjectUtil.intValue;
|
2015-12-14 15:27:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A {@link DnsNameResolver} builder.
|
|
|
|
*/
|
2016-04-12 14:22:41 +02:00
|
|
|
@UnstableApi
|
2015-12-14 15:27:49 +01:00
|
|
|
public final class DnsNameResolverBuilder {
|
2018-04-26 08:04:01 +02:00
|
|
|
private EventLoop eventLoop;
|
2015-12-14 15:27:49 +01:00
|
|
|
private ChannelFactory<? extends DatagramChannel> channelFactory;
|
2016-01-07 17:49:15 +01:00
|
|
|
private DnsCache resolveCache;
|
2018-08-22 17:49:22 +02:00
|
|
|
private AuthoritativeDnsServerCache authoritativeDnsServerCache;
|
2016-01-07 17:49:15 +01:00
|
|
|
private Integer minTtl;
|
|
|
|
private Integer maxTtl;
|
|
|
|
private Integer negativeTtl;
|
2015-12-14 15:27:49 +01:00
|
|
|
private long queryTimeoutMillis = 5000;
|
2017-02-08 16:43:15 +01:00
|
|
|
private ResolvedAddressTypes resolvedAddressTypes = DnsNameResolver.DEFAULT_RESOLVE_ADDRESS_TYPES;
|
2015-12-14 15:27:49 +01:00
|
|
|
private boolean recursionDesired = true;
|
2016-05-27 21:34:36 +02:00
|
|
|
private int maxQueriesPerResolve = 16;
|
2015-12-14 15:27:49 +01:00
|
|
|
private boolean traceEnabled;
|
|
|
|
private int maxPayloadSize = 4096;
|
|
|
|
private boolean optResourceEnabled = true;
|
|
|
|
private HostsFileEntriesResolver hostsFileEntriesResolver = HostsFileEntriesResolver.DEFAULT;
|
2017-03-31 02:02:16 +02:00
|
|
|
private DnsServerAddressStreamProvider dnsServerAddressStreamProvider = platformDefault();
|
2017-04-07 03:09:28 +02:00
|
|
|
private DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory =
|
|
|
|
NoopDnsQueryLifecycleObserverFactory.INSTANCE;
|
2017-06-13 10:51:48 +02:00
|
|
|
private String[] searchDomains;
|
2017-06-21 22:48:45 +02:00
|
|
|
private int ndots = -1;
|
2017-01-18 10:00:01 +01:00
|
|
|
private boolean decodeIdn = true;
|
2015-12-14 15:27:49 +01:00
|
|
|
|
2018-04-26 08:04:01 +02:00
|
|
|
/**
|
|
|
|
* Creates a new builder.
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder() {
|
|
|
|
}
|
|
|
|
|
2015-12-14 15:27:49 +01:00
|
|
|
/**
|
|
|
|
* Creates a new builder.
|
|
|
|
*
|
2018-04-26 08:04:01 +02:00
|
|
|
* @param eventLoop the {@link EventLoop} which will perform the communication with the DNS
|
2015-12-14 15:27:49 +01:00
|
|
|
* servers.
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder(EventLoop eventLoop) {
|
2018-04-26 08:04:01 +02:00
|
|
|
eventLoop(eventLoop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link EventLoop} which will perform the communication with the DNS servers.
|
|
|
|
*
|
|
|
|
* @param eventLoop the {@link EventLoop}
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder eventLoop(EventLoop eventLoop) {
|
2015-12-14 15:27:49 +01:00
|
|
|
this.eventLoop = eventLoop;
|
2018-04-26 08:04:01 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ChannelFactory<? extends DatagramChannel> channelFactory() {
|
|
|
|
return this.channelFactory;
|
2015-12-14 15:27:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link ChannelFactory} that will create a {@link DatagramChannel}.
|
|
|
|
*
|
|
|
|
* @param channelFactory the {@link ChannelFactory}
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder channelFactory(ChannelFactory<? extends DatagramChannel> channelFactory) {
|
|
|
|
this.channelFactory = channelFactory;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link ChannelFactory} as a {@link ReflectiveChannelFactory} of this type.
|
|
|
|
* Use as an alternative to {@link #channelFactory(ChannelFactory)}.
|
|
|
|
*
|
2016-03-22 16:27:19 +01:00
|
|
|
* @param channelType the type
|
2015-12-14 15:27:49 +01:00
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder channelType(Class<? extends DatagramChannel> channelType) {
|
|
|
|
return channelFactory(new ReflectiveChannelFactory<DatagramChannel>(channelType));
|
|
|
|
}
|
|
|
|
|
2016-01-07 17:49:15 +01:00
|
|
|
/**
|
|
|
|
* Sets the cache for resolution results.
|
|
|
|
*
|
|
|
|
* @param resolveCache the DNS resolution results cache
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder resolveCache(DnsCache resolveCache) {
|
|
|
|
this.resolveCache = resolveCache;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-04-07 03:09:28 +02:00
|
|
|
/**
|
|
|
|
* Set the factory used to generate objects which can observe individual DNS queries.
|
|
|
|
* @param lifecycleObserverFactory the factory used to generate objects which can observe individual DNS queries.
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder dnsQueryLifecycleObserverFactory(DnsQueryLifecycleObserverFactory
|
|
|
|
lifecycleObserverFactory) {
|
|
|
|
this.dnsQueryLifecycleObserverFactory = checkNotNull(lifecycleObserverFactory, "lifecycleObserverFactory");
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-01-25 09:28:22 +01:00
|
|
|
/**
|
2017-04-19 22:37:03 +02:00
|
|
|
* Sets the cache for authoritative NS servers
|
2017-01-25 09:28:22 +01:00
|
|
|
*
|
2017-04-19 22:37:03 +02:00
|
|
|
* @param authoritativeDnsServerCache the authoritative NS servers cache
|
2017-01-25 09:28:22 +01:00
|
|
|
* @return {@code this}
|
2018-08-22 17:49:22 +02:00
|
|
|
* @deprecated Use {@link #authoritativeDnsServerCache(AuthoritativeDnsServerCache)}
|
2017-01-25 09:28:22 +01:00
|
|
|
*/
|
2018-08-22 17:49:22 +02:00
|
|
|
@Deprecated
|
2017-01-25 09:28:22 +01:00
|
|
|
public DnsNameResolverBuilder authoritativeDnsServerCache(DnsCache authoritativeDnsServerCache) {
|
2018-08-22 17:49:22 +02:00
|
|
|
this.authoritativeDnsServerCache = new AuthoritativeDnsServerCacheAdapter(authoritativeDnsServerCache);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the cache for authoritative NS servers
|
|
|
|
*
|
|
|
|
* @param authoritativeDnsServerCache the authoritative NS servers cache
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder authoritativeDnsServerCache(AuthoritativeDnsServerCache authoritativeDnsServerCache) {
|
2017-01-25 09:28:22 +01:00
|
|
|
this.authoritativeDnsServerCache = authoritativeDnsServerCache;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-12-14 15:27:49 +01:00
|
|
|
/**
|
|
|
|
* Sets the minimum and maximum TTL of the cached DNS resource records (in seconds). If the TTL of the DNS
|
|
|
|
* resource record returned by the DNS server is less than the minimum TTL or greater than the maximum TTL,
|
|
|
|
* this resolver will ignore the TTL from the DNS server and use the minimum TTL or the maximum TTL instead
|
|
|
|
* respectively.
|
|
|
|
* The default value is {@code 0} and {@link Integer#MAX_VALUE}, which practically tells this resolver to
|
|
|
|
* respect the TTL from the DNS server.
|
|
|
|
*
|
|
|
|
* @param minTtl the minimum TTL
|
|
|
|
* @param maxTtl the maximum TTL
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder ttl(int minTtl, int maxTtl) {
|
|
|
|
this.maxTtl = maxTtl;
|
|
|
|
this.minTtl = minTtl;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the TTL of the cache for the failed DNS queries (in seconds).
|
|
|
|
*
|
|
|
|
* @param negativeTtl the TTL for failed cached queries
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder negativeTtl(int negativeTtl) {
|
|
|
|
this.negativeTtl = negativeTtl;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the timeout of each DNS query performed by this resolver (in milliseconds).
|
|
|
|
*
|
|
|
|
* @param queryTimeoutMillis the query timeout
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder queryTimeoutMillis(long queryTimeoutMillis) {
|
|
|
|
this.queryTimeoutMillis = queryTimeoutMillis;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-02-08 16:43:15 +01:00
|
|
|
* Compute a {@link ResolvedAddressTypes} from some {@link InternetProtocolFamily}s.
|
|
|
|
* An empty input will return the default value, based on "java.net" System properties.
|
|
|
|
* Valid inputs are (), (IPv4), (IPv6), (Ipv4, IPv6) and (IPv6, IPv4).
|
|
|
|
* @param internetProtocolFamilies a valid sequence of {@link InternetProtocolFamily}s
|
|
|
|
* @return a {@link ResolvedAddressTypes}
|
2015-12-14 15:27:49 +01:00
|
|
|
*/
|
2017-02-08 16:43:15 +01:00
|
|
|
public static ResolvedAddressTypes computeResolvedAddressTypes(InternetProtocolFamily... internetProtocolFamilies) {
|
|
|
|
if (internetProtocolFamilies == null || internetProtocolFamilies.length == 0) {
|
|
|
|
return DnsNameResolver.DEFAULT_RESOLVE_ADDRESS_TYPES;
|
2015-12-14 15:27:49 +01:00
|
|
|
}
|
2017-02-08 16:43:15 +01:00
|
|
|
if (internetProtocolFamilies.length > 2) {
|
|
|
|
throw new IllegalArgumentException("No more than 2 InternetProtocolFamilies");
|
2015-12-14 15:27:49 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 16:43:15 +01:00
|
|
|
switch(internetProtocolFamilies[0]) {
|
|
|
|
case IPv4:
|
|
|
|
return (internetProtocolFamilies.length >= 2
|
|
|
|
&& internetProtocolFamilies[1] == InternetProtocolFamily.IPv6) ?
|
|
|
|
ResolvedAddressTypes.IPV4_PREFERRED: ResolvedAddressTypes.IPV4_ONLY;
|
|
|
|
case IPv6:
|
|
|
|
return (internetProtocolFamilies.length >= 2
|
|
|
|
&& internetProtocolFamilies[1] == InternetProtocolFamily.IPv4) ?
|
|
|
|
ResolvedAddressTypes.IPV6_PREFERRED: ResolvedAddressTypes.IPV6_ONLY;
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"Couldn't resolve ResolvedAddressTypes from InternetProtocolFamily array");
|
|
|
|
}
|
2015-12-14 15:27:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the list of the protocol families of the address resolved.
|
2017-02-08 16:43:15 +01:00
|
|
|
* You can use {@link DnsNameResolverBuilder#computeResolvedAddressTypes(InternetProtocolFamily...)}
|
|
|
|
* to get a {@link ResolvedAddressTypes} out of some {@link InternetProtocolFamily}s.
|
2015-12-14 15:27:49 +01:00
|
|
|
*
|
|
|
|
* @param resolvedAddressTypes the address types
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
2017-02-08 16:43:15 +01:00
|
|
|
public DnsNameResolverBuilder resolvedAddressTypes(ResolvedAddressTypes resolvedAddressTypes) {
|
|
|
|
this.resolvedAddressTypes = resolvedAddressTypes;
|
2015-12-14 15:27:49 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set.
|
|
|
|
*
|
|
|
|
* @param recursionDesired true if recursion is desired
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder recursionDesired(boolean recursionDesired) {
|
|
|
|
this.recursionDesired = recursionDesired;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the maximum allowed number of DNS queries to send when resolving a host name.
|
|
|
|
*
|
|
|
|
* @param maxQueriesPerResolve the max number of queries
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder maxQueriesPerResolve(int maxQueriesPerResolve) {
|
|
|
|
this.maxQueriesPerResolve = maxQueriesPerResolve;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if this resolver should generate the detailed trace information in an exception message so that
|
|
|
|
* it is easier to understand the cause of resolution failure.
|
|
|
|
*
|
|
|
|
* @param traceEnabled true if trace is enabled
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder traceEnabled(boolean traceEnabled) {
|
|
|
|
this.traceEnabled = traceEnabled;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the capacity of the datagram packet buffer (in bytes). The default value is {@code 4096} bytes.
|
|
|
|
*
|
|
|
|
* @param maxPayloadSize the capacity of the datagram packet buffer
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder maxPayloadSize(int maxPayloadSize) {
|
|
|
|
this.maxPayloadSize = maxPayloadSize;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable 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. Some DNSServer may not support this and so fail to answer
|
|
|
|
* queries. If you find problems you may want to disable this.
|
|
|
|
*
|
|
|
|
* @param optResourceEnabled if optional records inclusion is enabled
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder optResourceEnabled(boolean optResourceEnabled) {
|
|
|
|
this.optResourceEnabled = optResourceEnabled;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to first check
|
|
|
|
* if the hostname is locally aliased.
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder hostsFileEntriesResolver(HostsFileEntriesResolver hostsFileEntriesResolver) {
|
|
|
|
this.hostsFileEntriesResolver = hostsFileEntriesResolver;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-04-26 08:04:01 +02:00
|
|
|
protected DnsServerAddressStreamProvider nameServerProvider() {
|
|
|
|
return this.dnsServerAddressStreamProvider;
|
|
|
|
}
|
|
|
|
|
2017-02-02 10:32:33 +01:00
|
|
|
/**
|
|
|
|
* Set the {@link DnsServerAddressStreamProvider} which is used to determine which DNS server is used to resolve
|
|
|
|
* each hostname.
|
|
|
|
* @return {@code this}.
|
|
|
|
*/
|
2017-03-31 02:02:16 +02:00
|
|
|
public DnsNameResolverBuilder nameServerProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) {
|
2017-02-02 10:32:33 +01:00
|
|
|
this.dnsServerAddressStreamProvider =
|
|
|
|
checkNotNull(dnsServerAddressStreamProvider, "dnsServerAddressStreamProvider");
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-06-30 23:12:11 +02:00
|
|
|
/**
|
|
|
|
* Set the list of search domains of the resolver.
|
|
|
|
*
|
|
|
|
* @param searchDomains the search domains
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder searchDomains(Iterable<String> searchDomains) {
|
|
|
|
checkNotNull(searchDomains, "searchDomains");
|
|
|
|
|
2016-10-31 07:23:22 +01:00
|
|
|
final List<String> list = new ArrayList<String>(4);
|
2016-06-30 23:12:11 +02:00
|
|
|
|
|
|
|
for (String f : searchDomains) {
|
|
|
|
if (f == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid duplicate entries.
|
|
|
|
if (list.contains(f)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.add(f);
|
|
|
|
}
|
|
|
|
|
2018-06-29 07:56:04 +02:00
|
|
|
this.searchDomains = list.toArray(new String[0]);
|
2016-06-30 23:12:11 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of dots which must appear in a name before an initial absolute query is made.
|
2016-07-23 09:47:43 +02:00
|
|
|
* The default value is {@code 1}.
|
2016-06-30 23:12:11 +02:00
|
|
|
*
|
|
|
|
* @param ndots the ndots value
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder ndots(int ndots) {
|
|
|
|
this.ndots = ndots;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-01-25 09:28:22 +01:00
|
|
|
private DnsCache newCache() {
|
|
|
|
return new DefaultDnsCache(intValue(minTtl, 0), intValue(maxTtl, Integer.MAX_VALUE), intValue(negativeTtl, 0));
|
|
|
|
}
|
|
|
|
|
2018-08-22 17:49:22 +02:00
|
|
|
private AuthoritativeDnsServerCache newAuthoritativeDnsServerCache() {
|
|
|
|
return new DefaultAuthoritativeDnsServerCache(
|
|
|
|
intValue(minTtl, 0), intValue(maxTtl, Integer.MAX_VALUE),
|
|
|
|
// Let us use the sane ordering as DnsNameResolver will be used when returning
|
|
|
|
// nameservers from the cache.
|
|
|
|
new NameServerComparator(DnsNameResolver.preferredAddressType(resolvedAddressTypes).addressType()));
|
|
|
|
}
|
|
|
|
|
2017-01-18 10:00:01 +01:00
|
|
|
/**
|
|
|
|
* Set if domain / host names should be decoded to unicode when received.
|
|
|
|
* See <a href="https://tools.ietf.org/html/rfc3492">rfc3492</a>.
|
|
|
|
*
|
|
|
|
* @param decodeIdn if should get decoded
|
|
|
|
* @return {@code this}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder decodeIdn(boolean decodeIdn) {
|
|
|
|
this.decodeIdn = decodeIdn;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-12-14 15:27:49 +01:00
|
|
|
/**
|
|
|
|
* Returns a new {@link DnsNameResolver} instance.
|
|
|
|
*
|
|
|
|
* @return a {@link DnsNameResolver}
|
|
|
|
*/
|
|
|
|
public DnsNameResolver build() {
|
2018-04-26 08:04:01 +02:00
|
|
|
if (eventLoop == null) {
|
|
|
|
throw new IllegalStateException("eventLoop should be specified to build a DnsNameResolver.");
|
|
|
|
}
|
|
|
|
|
2016-01-07 17:49:15 +01:00
|
|
|
if (resolveCache != null && (minTtl != null || maxTtl != null || negativeTtl != null)) {
|
|
|
|
throw new IllegalStateException("resolveCache and TTLs are mutually exclusive");
|
|
|
|
}
|
|
|
|
|
2017-01-25 09:28:22 +01:00
|
|
|
if (authoritativeDnsServerCache != null && (minTtl != null || maxTtl != null || negativeTtl != null)) {
|
|
|
|
throw new IllegalStateException("authoritativeDnsServerCache and TTLs are mutually exclusive");
|
|
|
|
}
|
2016-01-07 17:49:15 +01:00
|
|
|
|
2017-01-25 09:28:22 +01:00
|
|
|
DnsCache resolveCache = this.resolveCache != null ? this.resolveCache : newCache();
|
2018-08-22 17:49:22 +02:00
|
|
|
AuthoritativeDnsServerCache authoritativeDnsServerCache = this.authoritativeDnsServerCache != null ?
|
|
|
|
this.authoritativeDnsServerCache : newAuthoritativeDnsServerCache();
|
2015-12-14 15:27:49 +01:00
|
|
|
return new DnsNameResolver(
|
|
|
|
eventLoop,
|
|
|
|
channelFactory,
|
2017-01-25 09:28:22 +01:00
|
|
|
resolveCache,
|
|
|
|
authoritativeDnsServerCache,
|
2017-04-07 03:09:28 +02:00
|
|
|
dnsQueryLifecycleObserverFactory,
|
2015-12-14 15:27:49 +01:00
|
|
|
queryTimeoutMillis,
|
|
|
|
resolvedAddressTypes,
|
|
|
|
recursionDesired,
|
|
|
|
maxQueriesPerResolve,
|
|
|
|
traceEnabled,
|
|
|
|
maxPayloadSize,
|
|
|
|
optResourceEnabled,
|
2016-06-30 23:12:11 +02:00
|
|
|
hostsFileEntriesResolver,
|
2017-02-02 10:32:33 +01:00
|
|
|
dnsServerAddressStreamProvider,
|
2016-06-30 23:12:11 +02:00
|
|
|
searchDomains,
|
2017-01-18 10:00:01 +01:00
|
|
|
ndots,
|
|
|
|
decodeIdn);
|
2015-12-14 15:27:49 +01:00
|
|
|
}
|
2018-04-26 08:04:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a copy of this {@link DnsNameResolverBuilder}
|
|
|
|
*
|
|
|
|
* @return {@link DnsNameResolverBuilder}
|
|
|
|
*/
|
|
|
|
public DnsNameResolverBuilder copy() {
|
|
|
|
DnsNameResolverBuilder copiedBuilder = new DnsNameResolverBuilder();
|
|
|
|
|
|
|
|
if (eventLoop != null) {
|
|
|
|
copiedBuilder.eventLoop(eventLoop);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelFactory != null) {
|
|
|
|
copiedBuilder.channelFactory(channelFactory);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resolveCache != null) {
|
|
|
|
copiedBuilder.resolveCache(resolveCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxTtl != null && minTtl != null) {
|
|
|
|
copiedBuilder.ttl(minTtl, maxTtl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negativeTtl != null) {
|
|
|
|
copiedBuilder.negativeTtl(negativeTtl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (authoritativeDnsServerCache != null) {
|
|
|
|
copiedBuilder.authoritativeDnsServerCache(authoritativeDnsServerCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dnsQueryLifecycleObserverFactory != null) {
|
|
|
|
copiedBuilder.dnsQueryLifecycleObserverFactory(dnsQueryLifecycleObserverFactory);
|
|
|
|
}
|
|
|
|
|
|
|
|
copiedBuilder.queryTimeoutMillis(queryTimeoutMillis);
|
|
|
|
copiedBuilder.resolvedAddressTypes(resolvedAddressTypes);
|
|
|
|
copiedBuilder.recursionDesired(recursionDesired);
|
|
|
|
copiedBuilder.maxQueriesPerResolve(maxQueriesPerResolve);
|
|
|
|
copiedBuilder.traceEnabled(traceEnabled);
|
|
|
|
copiedBuilder.maxPayloadSize(maxPayloadSize);
|
|
|
|
copiedBuilder.optResourceEnabled(optResourceEnabled);
|
|
|
|
copiedBuilder.hostsFileEntriesResolver(hostsFileEntriesResolver);
|
|
|
|
|
|
|
|
if (dnsServerAddressStreamProvider != null) {
|
|
|
|
copiedBuilder.nameServerProvider(dnsServerAddressStreamProvider);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchDomains != null) {
|
|
|
|
copiedBuilder.searchDomains(Arrays.asList(searchDomains));
|
|
|
|
}
|
|
|
|
|
|
|
|
copiedBuilder.ndots(ndots);
|
|
|
|
copiedBuilder.decodeIdn(decodeIdn);
|
|
|
|
|
|
|
|
return copiedBuilder;
|
|
|
|
}
|
2015-12-14 15:27:49 +01:00
|
|
|
}
|