DNS Resolve ambiguity in which DNS servers are used during resolution

Motivation:
Recently DnsServerAddressStreamProvider was introduced to allow control for each query as to which DNS server should be used for resolution to respect the local host's default DNS server configuration. However resolver-dns also accepts a stream of DNS servers to use by default, but this stream is not host name aware. This creates an ambiguity as to which method is used to determine the DNS server to user during resolution, and in which order. We can remove this ambiguity and provide a more general API by just supporting DnsServerAddressStreamProvider.

Modifications:
- Remove the fixed DnsServerAddresses and instead only accept a DnsServerAddressStreamProvider.
- Add utility methods to help use DnsServerAddressStreamProvider for a single entry, a list of entries, and get the default for the current machine.

Result:
Fixes https://github.com/netty/netty/issues/6573.
This commit is contained in:
Scott Mitchell 2017-03-30 17:02:16 -07:00
parent 36c6a61d33
commit e074df2ae6
14 changed files with 206 additions and 82 deletions

View File

@ -17,15 +17,21 @@ package io.netty.resolver.dns;
import io.netty.util.internal.UnstableApi;
@UnstableApi
public final class NoopDnsServerAddressStreamProvider implements DnsServerAddressStreamProvider {
public static final NoopDnsServerAddressStreamProvider INSTANCE = new NoopDnsServerAddressStreamProvider();
import static io.netty.resolver.dns.DnsServerAddresses.defaultAddresses;
private NoopDnsServerAddressStreamProvider() {
/**
* A {@link DnsServerAddressStreamProvider} which will use predefined default DNS servers to use for DNS resolution.
* These defaults do not respect your host's machines defaults.
*/
@UnstableApi
public final class DefaultDnsServerAddressStreamProvider implements DnsServerAddressStreamProvider {
public static final DefaultDnsServerAddressStreamProvider INSTANCE = new DefaultDnsServerAddressStreamProvider();
private DefaultDnsServerAddressStreamProvider() {
}
@Override
public DnsServerAddressStream nameServerAddressStream(String hostname) {
return null;
return defaultAddresses().stream();
}
}

View File

@ -43,22 +43,22 @@ import static io.netty.util.internal.PlatformDependent.newConcurrentHashMap;
public class DnsAddressResolverGroup extends AddressResolverGroup<InetSocketAddress> {
private final ChannelFactory<? extends DatagramChannel> channelFactory;
private final DnsServerAddresses nameServerAddresses;
private final DnsServerAddressStreamProvider nameServerProvider;
private final ConcurrentMap<String, Promise<InetAddress>> resolvesInProgress = newConcurrentHashMap();
private final ConcurrentMap<String, Promise<List<InetAddress>>> resolveAllsInProgress = newConcurrentHashMap();
public DnsAddressResolverGroup(
Class<? extends DatagramChannel> channelType,
DnsServerAddresses nameServerAddresses) {
this(new ReflectiveChannelFactory<DatagramChannel>(channelType), nameServerAddresses);
DnsServerAddressStreamProvider nameServerProvider) {
this(new ReflectiveChannelFactory<DatagramChannel>(channelType), nameServerProvider);
}
public DnsAddressResolverGroup(
ChannelFactory<? extends DatagramChannel> channelFactory,
DnsServerAddresses nameServerAddresses) {
DnsServerAddressStreamProvider nameServerProvider) {
this.channelFactory = channelFactory;
this.nameServerAddresses = nameServerAddresses;
this.nameServerProvider = nameServerProvider;
}
@SuppressWarnings("deprecation")
@ -70,20 +70,20 @@ public class DnsAddressResolverGroup extends AddressResolverGroup<InetSocketAddr
" (expected: " + StringUtil.simpleClassName(EventLoop.class));
}
return newResolver((EventLoop) executor, channelFactory, nameServerAddresses);
return newResolver((EventLoop) executor, channelFactory, nameServerProvider);
}
/**
* @deprecated Override {@link #newNameResolver(EventLoop, ChannelFactory, DnsServerAddresses)}.
* @deprecated Override {@link #newNameResolver(EventLoop, ChannelFactory, DnsServerAddressStreamProvider)}.
*/
@Deprecated
protected AddressResolver<InetSocketAddress> newResolver(
EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory,
DnsServerAddresses nameServerAddresses) throws Exception {
DnsServerAddressStreamProvider nameServerProvider) throws Exception {
final NameResolver<InetAddress> resolver = new InflightNameResolver<InetAddress>(
eventLoop,
newNameResolver(eventLoop, channelFactory, nameServerAddresses),
newNameResolver(eventLoop, channelFactory, nameServerProvider),
resolvesInProgress,
resolveAllsInProgress);
@ -96,10 +96,11 @@ public class DnsAddressResolverGroup extends AddressResolverGroup<InetSocketAddr
*/
protected NameResolver<InetAddress> newNameResolver(EventLoop eventLoop,
ChannelFactory<? extends DatagramChannel> channelFactory,
DnsServerAddresses nameServerAddresses) throws Exception {
DnsServerAddressStreamProvider nameServerProvider)
throws Exception {
return new DnsNameResolverBuilder(eventLoop)
.channelFactory(channelFactory)
.nameServerAddresses(nameServerAddresses)
.nameServerProvider(nameServerProvider)
.build();
}

View File

@ -132,7 +132,6 @@ public class DnsNameResolver extends InetNameResolver {
private static final DatagramDnsResponseDecoder DECODER = new DatagramDnsResponseDecoder();
private static final DatagramDnsQueryEncoder ENCODER = new DatagramDnsQueryEncoder();
final DnsServerAddresses nameServerAddresses;
final Future<Channel> channelFuture;
final DatagramChannel ch;
@ -151,7 +150,7 @@ public class DnsNameResolver extends InetNameResolver {
new FastThreadLocal<DnsServerAddressStream>() {
@Override
protected DnsServerAddressStream initialValue() throws Exception {
return nameServerAddresses.stream();
return dnsServerAddressStreamProvider.nameServerAddressStream("");
}
};
@ -178,9 +177,6 @@ public class DnsNameResolver extends InetNameResolver {
*
* @param eventLoop the {@link EventLoop} which will perform the communication with the DNS servers
* @param channelFactory the {@link ChannelFactory} that will create a {@link DatagramChannel}
* @param nameServerAddresses the addresses of the DNS server. For each DNS query, a new stream is created from
* this to determine which DNS server should be contacted for the next retry in case
* of failure.
* @param resolveCache the DNS resolved entries cache
* @param authoritativeDnsServerCache the cache used to find the authoritative DNS server for a domain
* @param queryTimeoutMillis timeout of each DNS query in millis
@ -191,7 +187,7 @@ public class DnsNameResolver extends InetNameResolver {
* @param maxPayloadSize the capacity of the datagram packet buffer
* @param optResourceEnabled if automatic inclusion of a optional records is enabled
* @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
* @param dnsServerAddressStreamProvider The {@link DnsServerAddressStreamProvider} used to override the name
* @param dnsServerAddressStreamProvider The {@link DnsServerAddressStreamProvider} used to determine the name
* servers for each hostname lookup.
* @param searchDomains the list of search domain
* @param ndots the ndots value
@ -201,7 +197,6 @@ public class DnsNameResolver extends InetNameResolver {
public DnsNameResolver(
EventLoop eventLoop,
ChannelFactory<? extends DatagramChannel> channelFactory,
DnsServerAddresses nameServerAddresses,
final DnsCache resolveCache,
DnsCache authoritativeDnsServerCache,
long queryTimeoutMillis,
@ -218,7 +213,6 @@ public class DnsNameResolver extends InetNameResolver {
boolean decodeIdn) {
super(eventLoop);
checkNotNull(channelFactory, "channelFactory");
this.nameServerAddresses = checkNotNull(nameServerAddresses, "nameServerAddresses");
this.queryTimeoutMillis = checkPositive(queryTimeoutMillis, "queryTimeoutMillis");
this.resolvedAddressTypes = resolvedAddressTypes != null ? resolvedAddressTypes : DEFAULT_RESOLVE_ADDRESS_TYPES;
this.recursionDesired = recursionDesired;
@ -636,12 +630,8 @@ public class DnsNameResolver extends InetNameResolver {
DnsRecord[] additionals,
Promise<InetAddress> promise,
DnsCache resolveCache) {
DnsServerAddressStream dnsServerAddressStream =
dnsServerAddressStreamProvider.nameServerAddressStream(hostname);
SingleResolverContext ctx = dnsServerAddressStream == null ?
new SingleResolverContext(this, hostname, additionals, resolveCache, nameServerAddresses.stream()) :
new SingleResolverContext(this, hostname, additionals, resolveCache, dnsServerAddressStream);
ctx.resolve(promise);
new SingleResolverContext(this, hostname, additionals, resolveCache,
dnsServerAddressStreamProvider.nameServerAddressStream(hostname)).resolve(promise);
}
static final class SingleResolverContext extends DnsNameResolverContext<InetAddress> {
@ -797,12 +787,8 @@ public class DnsNameResolver extends InetNameResolver {
DnsRecord[] additionals,
Promise<List<InetAddress>> promise,
DnsCache resolveCache) {
DnsServerAddressStream dnsServerAddressStream =
dnsServerAddressStreamProvider.nameServerAddressStream(hostname);
ListResolverContext ctx = dnsServerAddressStream == null ?
new ListResolverContext(this, hostname, additionals, resolveCache, nameServerAddresses.stream()) :
new ListResolverContext(this, hostname, additionals, resolveCache, dnsServerAddressStream);
ctx.resolve(promise);
new ListResolverContext(this, hostname, additionals, resolveCache,
dnsServerAddressStreamProvider.nameServerAddressStream(hostname)).resolve(promise);
}
private static String hostname(String inetHost) {

View File

@ -27,6 +27,7 @@ import io.netty.util.internal.UnstableApi;
import java.util.ArrayList;
import java.util.List;
import static io.netty.resolver.dns.DnsServerAddressStreamProviders.platformDefault;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.intValue;
@ -35,14 +36,8 @@ import static io.netty.util.internal.ObjectUtil.intValue;
*/
@UnstableApi
public final class DnsNameResolverBuilder {
// TODO(scott): how is this done on Windows? This may require a JNI call to GetNetworkParams
// https://msdn.microsoft.com/en-us/library/aa365968(VS.85).aspx.
private static final DnsServerAddressStreamProvider DEFAULT_DNS_SERVER_ADDRESS_STREAM_PROVIDER =
UnixResolverDnsServerAddressStreamProvider.parseSilently();
private final EventLoop eventLoop;
private ChannelFactory<? extends DatagramChannel> channelFactory;
private DnsServerAddresses nameServerAddresses = DnsServerAddresses.defaultAddresses();
private DnsCache resolveCache;
private DnsCache authoritativeDnsServerCache;
private Integer minTtl;
@ -56,7 +51,7 @@ public final class DnsNameResolverBuilder {
private int maxPayloadSize = 4096;
private boolean optResourceEnabled = true;
private HostsFileEntriesResolver hostsFileEntriesResolver = HostsFileEntriesResolver.DEFAULT;
private DnsServerAddressStreamProvider dnsServerAddressStreamProvider = DEFAULT_DNS_SERVER_ADDRESS_STREAM_PROVIDER;
private DnsServerAddressStreamProvider dnsServerAddressStreamProvider = platformDefault();
private String[] searchDomains = DnsNameResolver.DEFAULT_SEARCH_DOMAINS;
private int ndots = 1;
private boolean decodeIdn = true;
@ -93,17 +88,6 @@ public final class DnsNameResolverBuilder {
return channelFactory(new ReflectiveChannelFactory<DatagramChannel>(channelType));
}
/**
* Sets the addresses of the DNS server.
*
* @param nameServerAddresses the DNS server addresses
* @return {@code this}
*/
public DnsNameResolverBuilder nameServerAddresses(DnsServerAddresses nameServerAddresses) {
this.nameServerAddresses = nameServerAddresses;
return this;
}
/**
* Sets the cache for resolution results.
*
@ -282,7 +266,7 @@ public final class DnsNameResolverBuilder {
* each hostname.
* @return {@code this}.
*/
public DnsNameResolverBuilder nameServerCache(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) {
public DnsNameResolverBuilder nameServerProvider(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) {
this.dnsServerAddressStreamProvider =
checkNotNull(dnsServerAddressStreamProvider, "dnsServerAddressStreamProvider");
return this;
@ -364,7 +348,6 @@ public final class DnsNameResolverBuilder {
return new DnsNameResolver(
eventLoop,
channelFactory,
nameServerAddresses,
resolveCache,
authoritativeDnsServerCache,
queryTimeoutMillis,

View File

@ -34,6 +34,7 @@ import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import java.net.IDN;
@ -96,7 +97,7 @@ abstract class DnsNameResolverContext<T> {
this.additionals = additionals;
this.resolveCache = resolveCache;
this.nameServerAddrs = nameServerAddrs;
this.nameServerAddrs = ObjectUtil.checkNotNull(nameServerAddrs, "nameServerAddrs");
maxAllowedQueries = parent.maxQueriesPerResolve();
resolvedInternetProtocolFamilies = parent.resolvedInternetProtocolFamiliesUnsafe();
traceEnabled = parent.isTraceEnabled();

View File

@ -29,8 +29,9 @@ public interface DnsServerAddressStreamProvider {
/**
* Ask this provider for the name servers to query for {@code hostname}.
* @param hostname The hostname for which to lookup the DNS server addressed to use.
* @return The {@link DnsServerAddressStream} which should be used to resolve {@code hostname} or {@code null} to
* use the default resolvers.
* If this is the final {@link DnsServerAddressStreamProvider} to be queried then generally empty
* string or {@code '.'} correspond to the default {@link DnsServerAddressStream}.
* @return The {@link DnsServerAddressStream} which should be used to resolve {@code hostname}.
*/
DnsServerAddressStream nameServerAddressStream(String hostname);
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2017 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.util.internal.UnstableApi;
/**
* Utility methods related to {@link DnsServerAddressStreamProvider}.
*/
@UnstableApi
public final class DnsServerAddressStreamProviders {
// TODO(scott): how is this done on Windows? This may require a JNI call to GetNetworkParams
// https://msdn.microsoft.com/en-us/library/aa365968(VS.85).aspx.
private static final DnsServerAddressStreamProvider DEFAULT_DNS_SERVER_ADDRESS_STREAM_PROVIDER =
UnixResolverDnsServerAddressStreamProvider.parseSilently();
private DnsServerAddressStreamProviders() {
}
/**
* A {@link DnsServerAddressStreamProvider} which inherits the DNS servers from your local host's configuration.
* <p>
* Note that only macOS and Linux are currently supported.
* @return A {@link DnsServerAddressStreamProvider} which inherits the DNS servers from your local host's
* configuration.
*/
public static DnsServerAddressStreamProvider platformDefault() {
return DEFAULT_DNS_SERVER_ADDRESS_STREAM_PROVIDER;
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2017 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.util.internal.UnstableApi;
import java.util.List;
/**
* A {@link DnsServerAddressStreamProvider} which iterates through a collection of
* {@link DnsServerAddressStreamProvider} until the first non-{@code null} result is found.
*/
@UnstableApi
public final class MultiDnsServerAddressStreamProvider implements DnsServerAddressStreamProvider {
private final DnsServerAddressStreamProvider[] providers;
/**
* Create a new instance.
* @param providers The providers to use for DNS resolution. They will be queried in order.
*/
public MultiDnsServerAddressStreamProvider(List<DnsServerAddressStreamProvider> providers) {
this.providers = providers.toArray(new DnsServerAddressStreamProvider[0]);
}
/**
* Create a new instance.
* @param providers The providers to use for DNS resolution. They will be queried in order.
*/
public MultiDnsServerAddressStreamProvider(DnsServerAddressStreamProvider... providers) {
this.providers = providers.clone();
}
@Override
public DnsServerAddressStream nameServerAddressStream(String hostname) {
for (DnsServerAddressStreamProvider provider : providers) {
DnsServerAddressStream stream = provider.nameServerAddressStream(hostname);
if (stream != null) {
return stream;
}
}
return null;
}
}

View File

@ -21,8 +21,8 @@ import io.netty.channel.EventLoop;
import io.netty.channel.socket.DatagramChannel;
import io.netty.resolver.AddressResolver;
import io.netty.resolver.AddressResolverGroup;
import io.netty.resolver.RoundRobinInetAddressResolver;
import io.netty.resolver.NameResolver;
import io.netty.resolver.RoundRobinInetAddressResolver;
import io.netty.util.internal.UnstableApi;
import java.net.InetAddress;
@ -38,21 +38,22 @@ public class RoundRobinDnsAddressResolverGroup extends DnsAddressResolverGroup {
public RoundRobinDnsAddressResolverGroup(
Class<? extends DatagramChannel> channelType,
DnsServerAddresses nameServerAddresses) {
super(channelType, nameServerAddresses);
DnsServerAddressStreamProvider nameServerProvider) {
super(channelType, nameServerProvider);
}
public RoundRobinDnsAddressResolverGroup(
ChannelFactory<? extends DatagramChannel> channelFactory,
DnsServerAddresses nameServerAddresses) {
super(channelFactory, nameServerAddresses);
DnsServerAddressStreamProvider nameServerProvider) {
super(channelFactory, nameServerProvider);
}
/**
* We need to override this method, not
* {@link #newNameResolver(EventLoop, ChannelFactory, DnsServerAddresses)},
* {@link #newNameResolver(EventLoop, ChannelFactory, DnsServerAddressStreamProvider)},
* because we need to eliminate possible caching of {@link io.netty.resolver.NameResolver#resolve}
* by {@link InflightNameResolver} created in {@link #newResolver(EventLoop, ChannelFactory, DnsServerAddresses)}.
* by {@link InflightNameResolver} created in
* {@link #newResolver(EventLoop, ChannelFactory, DnsServerAddressStreamProvider)}.
*/
@Override
protected final AddressResolver<InetSocketAddress> newAddressResolver(EventLoop eventLoop,

View File

@ -0,0 +1,41 @@
/*
* Copyright 2017 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.util.internal.UnstableApi;
import java.net.InetSocketAddress;
/**
* A {@link DnsServerAddressStreamProvider} which always uses a single DNS server for resolution.
*/
@UnstableApi
public final class SingletonDnsServerAddressStreamProvider implements DnsServerAddressStreamProvider {
private final DnsServerAddresses addresses;
/**
* Create a new instance.
* @param address The singleton address to use for every DNS resolution.
*/
public SingletonDnsServerAddressStreamProvider(final InetSocketAddress address) {
addresses = DnsServerAddresses.singleton(address);
}
@Override
public DnsServerAddressStream nameServerAddressStream(String hostname) {
return addresses.stream();
}
}

View File

@ -52,17 +52,17 @@ public final class UnixResolverDnsServerAddressStreamProvider implements DnsServ
/**
* Attempt to parse {@code /etc/resolv.conf} and files in the {@code /etc/resolver} directory by default.
* A failure to parse will return {@link NoopDnsServerAddressStreamProvider}.
* A failure to parse will return {@link DefaultDnsServerAddressStreamProvider}.
*/
public static DnsServerAddressStreamProvider parseSilently() {
try {
UnixResolverDnsServerAddressStreamProvider nameServerCache =
new UnixResolverDnsServerAddressStreamProvider("/etc/resolv.conf", "/etc/resolver");
return nameServerCache.mayOverrideNameServers() ? nameServerCache
: NoopDnsServerAddressStreamProvider.INSTANCE;
: DefaultDnsServerAddressStreamProvider.INSTANCE;
} catch (Exception e) {
logger.debug("failed to parse /etc/resolv.conf and/or /etc/resolver", e);
return NoopDnsServerAddressStreamProvider.INSTANCE;
return DefaultDnsServerAddressStreamProvider.INSTANCE;
}
}

View File

@ -60,8 +60,8 @@ public class DnsNameResolverClientSubnetTest {
private static DnsNameResolverBuilder newResolver(EventLoopGroup group) {
return new DnsNameResolverBuilder(group.next())
.channelType(NioDatagramChannel.class)
.nameServerAddresses(DnsServerAddresses.singleton(SocketUtils.socketAddress("8.8.8.8", 53)))
.nameServerCache(NoopDnsServerAddressStreamProvider.INSTANCE)
.nameServerProvider(
new SingletonDnsServerAddressStreamProvider(SocketUtils.socketAddress("8.8.8.8", 53)))
.maxQueriesPerResolve(1)
.optResourceEnabled(false);
}

View File

@ -278,18 +278,25 @@ public class DnsNameResolverTest {
private static final EventLoopGroup group = new NioEventLoopGroup(1);
private static DnsNameResolverBuilder newResolver(boolean decodeToUnicode) {
return newResolver(decodeToUnicode, NoopDnsServerAddressStreamProvider.INSTANCE);
return newResolver(decodeToUnicode, null);
}
private static DnsNameResolverBuilder newResolver(boolean decodeToUnicode,
DnsServerAddressStreamProvider dnsServerAddressStreamProvider) {
return new DnsNameResolverBuilder(group.next())
DnsNameResolverBuilder builder = new DnsNameResolverBuilder(group.next())
.channelType(NioDatagramChannel.class)
.nameServerAddresses(DnsServerAddresses.singleton(dnsServer.localAddress()))
.nameServerCache(dnsServerAddressStreamProvider)
.maxQueriesPerResolve(1)
.decodeIdn(decodeToUnicode)
.optResourceEnabled(false);
if (dnsServerAddressStreamProvider == null) {
builder.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()));
} else {
builder.nameServerProvider(new MultiDnsServerAddressStreamProvider(dnsServerAddressStreamProvider,
new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress())));
}
return builder;
}
private static DnsNameResolverBuilder newResolver() {
@ -761,9 +768,8 @@ public class DnsNameResolverTest {
EventLoopGroup group = new NioEventLoopGroup(1);
DnsNameResolver resolver = new DnsNameResolver(
group.next(), new ReflectiveChannelFactory<DatagramChannel>(NioDatagramChannel.class),
DnsServerAddresses.singleton(dnsServer.localAddress()), NoopDnsCache.INSTANCE, nsCache,
3000, ResolvedAddressTypes.IPV4_ONLY, true, 10,
true, 4096, false, HostsFileEntriesResolver.DEFAULT, NoopDnsServerAddressStreamProvider.INSTANCE,
NoopDnsCache.INSTANCE, nsCache, 3000, ResolvedAddressTypes.IPV4_ONLY, true, 10, true, 4096, false,
HostsFileEntriesResolver.DEFAULT, new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()),
DnsNameResolver.DEFAULT_SEARCH_DOMAINS, 0, true) {
@Override
int dnsRedirectPort(InetAddress server) {

View File

@ -33,20 +33,19 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.StringContains.containsString;
public class SearchDomainTest {
private DnsNameResolverBuilder newResolver() {
return new DnsNameResolverBuilder(group.next())
.channelType(NioDatagramChannel.class)
.nameServerAddresses(DnsServerAddresses.singleton(dnsServer.localAddress()))
.nameServerCache(NoopDnsServerAddressStreamProvider.INSTANCE)
.nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()))
.maxQueriesPerResolve(1)
.optResourceEnabled(false);
}