|
38 | 38 |
|
39 | 39 | import io.micrometer.core.instrument.MeterRegistry;
|
40 | 40 | import io.netty.channel.EventLoopGroup;
|
| 41 | +import io.netty.channel.socket.DatagramChannel; |
| 42 | +import io.netty.channel.socket.SocketChannel; |
41 | 43 | import io.netty.handler.codec.dns.DnsRecord;
|
42 | 44 | import io.netty.resolver.HostsFileEntriesResolver;
|
43 | 45 | import io.netty.resolver.dns.BiDnsQueryLifecycleObserverFactory;
|
| 46 | +import io.netty.resolver.dns.DnsNameResolver; |
44 | 47 | import io.netty.resolver.dns.DnsNameResolverBuilder;
|
| 48 | +import io.netty.resolver.dns.DnsNameResolverChannelStrategy; |
45 | 49 | import io.netty.resolver.dns.DnsQueryLifecycleObserverFactory;
|
46 | 50 | import io.netty.resolver.dns.DnsServerAddressStream;
|
47 | 51 | import io.netty.resolver.dns.DnsServerAddressStreamProvider;
|
@@ -83,6 +87,11 @@ public abstract class AbstractDnsResolverBuilder<SELF extends AbstractDnsResolve
|
83 | 87 | private List<String> searchDomains = DnsUtil.defaultSearchDomains();
|
84 | 88 | private int ndots = DnsUtil.defaultNdots();
|
85 | 89 | private boolean decodeIdn = true;
|
| 90 | + @Nullable |
| 91 | + private DnsNameResolverChannelStrategy datagramChannelStrategy; |
| 92 | + @Nullable |
| 93 | + private Class<? extends SocketChannel> socketChannelType; |
| 94 | + private boolean retrySocketChannelOnTimeout; |
86 | 95 |
|
87 | 96 | @Nullable
|
88 | 97 | private MeterRegistry meterRegistry;
|
@@ -487,6 +496,36 @@ protected final DnsCache maybeCreateDnsCache() {
|
487 | 496 | }
|
488 | 497 | }
|
489 | 498 |
|
| 499 | + /** |
| 500 | + * Set the strategy that is used to determine how a {@link DatagramChannel} is used by the resolver for |
| 501 | + * sending queries over UDP protocol. |
| 502 | + */ |
| 503 | + @UnstableApi |
| 504 | + public SELF datagramChannelStrategy(DnsNameResolverChannelStrategy datagramChannelStrategy) { |
| 505 | + requireNonNull(datagramChannelStrategy, "datagramChannelStrategy"); |
| 506 | + this.datagramChannelStrategy = datagramChannelStrategy; |
| 507 | + return self(); |
| 508 | + } |
| 509 | + |
| 510 | + /** |
| 511 | + * Enables <a href="https://tools.ietf.org/html/rfc7766">TCP fallback</a> using the specified |
| 512 | + * {@link SocketChannel} type. |
| 513 | + * <p> |
| 514 | + * TCP fallback is disabled by default. |
| 515 | + * @param socketChannelType the type of {@link SocketChannel} to use for TCP fallback. |
| 516 | + * @param retrySocketChannelOnTimeout if {@code true} the {@link DnsNameResolver} will also fallback to |
| 517 | + * TCP if a timeout was detected, if {@code false} it will only try to |
| 518 | + * use TCP if the response was marked as truncated. |
| 519 | + */ |
| 520 | + @UnstableApi |
| 521 | + public SELF socketChannelType(Class<? extends SocketChannel> socketChannelType, |
| 522 | + boolean retrySocketChannelOnTimeout) { |
| 523 | + requireNonNull(socketChannelType, "channelType"); |
| 524 | + this.socketChannelType = socketChannelType; |
| 525 | + this.retrySocketChannelOnTimeout = retrySocketChannelOnTimeout; |
| 526 | + return self(); |
| 527 | + } |
| 528 | + |
490 | 529 | /**
|
491 | 530 | * Builds a configurator that configures a {@link DnsNameResolverBuilder} with the properties set.
|
492 | 531 | */
|
@@ -561,6 +600,13 @@ protected final Consumer<DnsNameResolverBuilder> buildConfigurator(EventLoopGrou
|
561 | 600 | if (observerFactory != null) {
|
562 | 601 | builder.dnsQueryLifecycleObserverFactory(observerFactory);
|
563 | 602 | }
|
| 603 | + final DnsNameResolverChannelStrategy datagramChannelStrategy = this.datagramChannelStrategy; |
| 604 | + if (datagramChannelStrategy != null) { |
| 605 | + builder.datagramChannelStrategy(datagramChannelStrategy); |
| 606 | + } |
| 607 | + final Class<? extends SocketChannel> socketChannelType = this.socketChannelType; |
| 608 | + final boolean retrySocketChannelOnTimeout = this.retrySocketChannelOnTimeout; |
| 609 | + builder.socketChannelType(socketChannelType, retrySocketChannelOnTimeout); |
564 | 610 | };
|
565 | 611 | }
|
566 | 612 | }
|
0 commit comments