3939import io .netty .handler .codec .dns .DnsResponse ;
4040import io .netty .resolver .HostsFileEntriesResolver ;
4141import io .netty .resolver .InetNameResolver ;
42+ import io .netty .util .NetUtil ;
4243import io .netty .util .NetUtil2 ;
4344import io .netty .util .ReferenceCountUtil ;
4445import io .netty .util .concurrent .FastThreadLocal ;
4546import io .netty .util .concurrent .Future ;
4647import io .netty .util .concurrent .Promise ;
4748import io .netty .util .internal .EmptyArrays ;
4849import io .netty .util .internal .PlatformDependent ;
50+ import io .netty .util .internal .StringUtil ;
4951import io .netty .util .internal .StringUtil2 ;
5052import io .netty .util .internal .UnstableApi ;
5153import io .netty .util .internal .logging .InternalLogger ;
@@ -81,19 +83,19 @@ public class DnsNameResolver extends InetNameResolver {
8183static final String []DEFAULT_SEACH_DOMAINS ;
8284
8385static {
84- if (NetUtil2 .isIpV4StackPreferred ()) {
86+ if (NetUtil .isIpV4StackPreferred ()) {
8587DEFAULT_RESOLVE_ADDRESS_TYPES =new InternetProtocolFamily2 [] {InternetProtocolFamily2 .IPv4 };
86- LOCALHOST_ADDRESS =NetUtil2 .LOCALHOST4 ;
88+ LOCALHOST_ADDRESS =NetUtil .LOCALHOST4 ;
8789 }else {
8890DEFAULT_RESOLVE_ADDRESS_TYPES =new InternetProtocolFamily2 [2 ];
8991if (NetUtil2 .isIpV6AddressesPreferred ()) {
9092DEFAULT_RESOLVE_ADDRESS_TYPES [0 ] =InternetProtocolFamily2 .IPv6 ;
9193DEFAULT_RESOLVE_ADDRESS_TYPES [1 ] =InternetProtocolFamily2 .IPv4 ;
92- LOCALHOST_ADDRESS =NetUtil2 .LOCALHOST6 ;
94+ LOCALHOST_ADDRESS =NetUtil .LOCALHOST6 ;
9395 }else {
9496DEFAULT_RESOLVE_ADDRESS_TYPES [0 ] =InternetProtocolFamily2 .IPv4 ;
9597DEFAULT_RESOLVE_ADDRESS_TYPES [1 ] =InternetProtocolFamily2 .IPv6 ;
96- LOCALHOST_ADDRESS =NetUtil2 .LOCALHOST4 ;
98+ LOCALHOST_ADDRESS =NetUtil .LOCALHOST4 ;
9799 }
98100 }
99101 }
@@ -155,6 +157,7 @@ protected DnsServerAddressStream initialValue() throws Exception {
155157private final boolean cnameFollowAAAARecords ;
156158private final InternetProtocolFamily2 preferredAddressType ;
157159private final DnsRecordType []resolveRecordTypes ;
160+ private final boolean decodeIdn ;
158161
159162/**
160163 * Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
@@ -175,7 +178,11 @@ protected DnsServerAddressStream initialValue() throws Exception {
175178 * @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
176179 * @param searchDomains the list of search domain
177180 * @param ndots the ndots value
181+ * @deprecated use {@link #DnsNameResolver(EventLoop, ChannelFactory, DnsServerAddresses, DnsCache, long,
182+ * InternetProtocolFamily2[], boolean, int, boolean, int,
183+ * boolean, HostsFileEntriesResolver, String[], int, boolean)}
178184 */
185+ @ Deprecated
179186public DnsNameResolver (
180187EventLoop eventLoop ,
181188ChannelFactory <?extends DatagramChannel >channelFactory ,
@@ -191,6 +198,49 @@ public DnsNameResolver(
191198HostsFileEntriesResolver hostsFileEntriesResolver ,
192199String []searchDomains ,
193200int ndots ) {
201+ this (eventLoop ,channelFactory ,nameServerAddresses ,resolveCache ,queryTimeoutMillis ,resolvedAddressTypes ,
202+ recursionDesired ,maxQueriesPerResolve ,traceEnabled ,maxPayloadSize ,optResourceEnabled ,
203+ hostsFileEntriesResolver ,searchDomains ,ndots ,true );
204+ }
205+
206+ /**
207+ * Creates a new DNS-based name resolver that communicates with the specified list of DNS servers.
208+ *
209+ * @param eventLoop the {@link EventLoop} which will perform the communication with the DNS servers
210+ * @param channelFactory the {@link ChannelFactory} that will create a {@link DatagramChannel}
211+ * @param nameServerAddresses the addresses of the DNS server. For each DNS query, a new stream is created from
212+ * this to determine which DNS server should be contacted for the next retry in case
213+ * of failure.
214+ * @param resolveCache the DNS resolved entries cache
215+ * @param queryTimeoutMillis timeout of each DNS query in millis
216+ * @param resolvedAddressTypes list of the protocol families
217+ * @param recursionDesired if recursion desired flag must be set
218+ * @param maxQueriesPerResolve the maximum allowed number of DNS queries for a given name resolution
219+ * @param traceEnabled if trace is enabled
220+ * @param maxPayloadSize the capacity of the datagram packet buffer
221+ * @param optResourceEnabled if automatic inclusion of a optional records is enabled
222+ * @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
223+ * @param searchDomains the list of search domain
224+ * @param ndots the ndots value
225+ * @param decodeIdn {@code true} if domain / host names should be decoded to unicode when received.
226+ * See <a href="https://tools.ietf.org/html/rfc3492">rfc3492</a>.
227+ */
228+ public DnsNameResolver (
229+ EventLoop eventLoop ,
230+ ChannelFactory <?extends DatagramChannel >channelFactory ,
231+ DnsServerAddresses nameServerAddresses ,
232+ final DnsCache resolveCache ,
233+ long queryTimeoutMillis ,
234+ InternetProtocolFamily2 []resolvedAddressTypes ,
235+ boolean recursionDesired ,
236+ int maxQueriesPerResolve ,
237+ boolean traceEnabled ,
238+ int maxPayloadSize ,
239+ boolean optResourceEnabled ,
240+ HostsFileEntriesResolver hostsFileEntriesResolver ,
241+ String []searchDomains ,
242+ int ndots ,
243+ boolean decodeIdn ) {
194244
195245super (eventLoop );
196246checkNotNull (channelFactory ,"channelFactory" );
@@ -206,6 +256,7 @@ public DnsNameResolver(
206256this .resolveCache =checkNotNull (resolveCache ,"resolveCache" );
207257this .searchDomains =checkNotNull (searchDomains ,"searchDomains" ).clone ();
208258this .ndots =checkPositiveOrZero (ndots ,"ndots" );
259+ this .decodeIdn =decodeIdn ;
209260
210261boolean cnameFollowARecords =false ;
211262boolean cnameFollowAAAARecords =false ;
@@ -309,6 +360,10 @@ final DnsRecordType[] resolveRecordTypes() {
309360return resolveRecordTypes ;
310361 }
311362
363+ final boolean isDecodeIdn () {
364+ return decodeIdn ;
365+ }
366+
312367/**
313368 * Returns {@code true} if and only if this resolver sends a DNS query with the RD (recursion desired) flag set.
314369 * The default value is {@code true}.
@@ -503,7 +558,7 @@ private static void validateAdditional(DnsRecord record, boolean validateType) {
503558@ Override
504559protected final InetAddress loopbackAddress () {
505560return preferredAddressType () ==InternetProtocolFamily2 .IPv4 ?
506- NetUtil2 .LOCALHOST4 :NetUtil2 .LOCALHOST6 ;
561+ NetUtil .LOCALHOST4 :NetUtil .LOCALHOST6 ;
507562 }
508563
509564/**
@@ -514,7 +569,7 @@ protected void doResolve(String inetHost,
514569DnsRecord []additionals ,
515570Promise <InetAddress >promise ,
516571DnsCache resolveCache )throws Exception {
517- final byte []bytes =NetUtil2 .createByteArrayFromIpAddressString (inetHost );
572+ final byte []bytes =NetUtil .createByteArrayFromIpAddressString (inetHost );
518573if (bytes !=null ) {
519574// The inetHost is actually an ipaddress.
520575promise .setSuccess (InetAddress .getByAddress (bytes ));
@@ -639,7 +694,7 @@ protected void doResolveAll(String inetHost,
639694DnsRecord []additionals ,
640695Promise <List <InetAddress >>promise ,
641696DnsCache resolveCache )throws Exception {
642- final byte []bytes =NetUtil2 .createByteArrayFromIpAddressString (inetHost );
697+ final byte []bytes =NetUtil .createByteArrayFromIpAddressString (inetHost );
643698if (bytes !=null ) {
644699// The unresolvedAddress was created via a String that contains an ipaddress.
645700promise .setSuccess (Collections .singletonList (InetAddress .getByAddress (bytes )));