39
39
import io .netty .handler .codec .dns .DnsResponse ;
40
40
import io .netty .resolver .HostsFileEntriesResolver ;
41
41
import io .netty .resolver .InetNameResolver ;
42
+ import io .netty .util .NetUtil ;
42
43
import io .netty .util .NetUtil2 ;
43
44
import io .netty .util .ReferenceCountUtil ;
44
45
import io .netty .util .concurrent .FastThreadLocal ;
45
46
import io .netty .util .concurrent .Future ;
46
47
import io .netty .util .concurrent .Promise ;
47
48
import io .netty .util .internal .EmptyArrays ;
48
49
import io .netty .util .internal .PlatformDependent ;
50
+ import io .netty .util .internal .StringUtil ;
49
51
import io .netty .util .internal .StringUtil2 ;
50
52
import io .netty .util .internal .UnstableApi ;
51
53
import io .netty .util .internal .logging .InternalLogger ;
@@ -81,19 +83,19 @@ public class DnsNameResolver extends InetNameResolver {
81
83
static final String [] DEFAULT_SEACH_DOMAINS ;
82
84
83
85
static {
84
- if (NetUtil2 .isIpV4StackPreferred ()) {
86
+ if (NetUtil .isIpV4StackPreferred ()) {
85
87
DEFAULT_RESOLVE_ADDRESS_TYPES = new InternetProtocolFamily2 [] { InternetProtocolFamily2 .IPv4 };
86
- LOCALHOST_ADDRESS = NetUtil2 .LOCALHOST4 ;
88
+ LOCALHOST_ADDRESS = NetUtil .LOCALHOST4 ;
87
89
} else {
88
90
DEFAULT_RESOLVE_ADDRESS_TYPES = new InternetProtocolFamily2 [2 ];
89
91
if (NetUtil2 .isIpV6AddressesPreferred ()) {
90
92
DEFAULT_RESOLVE_ADDRESS_TYPES [0 ] = InternetProtocolFamily2 .IPv6 ;
91
93
DEFAULT_RESOLVE_ADDRESS_TYPES [1 ] = InternetProtocolFamily2 .IPv4 ;
92
- LOCALHOST_ADDRESS = NetUtil2 .LOCALHOST6 ;
94
+ LOCALHOST_ADDRESS = NetUtil .LOCALHOST6 ;
93
95
} else {
94
96
DEFAULT_RESOLVE_ADDRESS_TYPES [0 ] = InternetProtocolFamily2 .IPv4 ;
95
97
DEFAULT_RESOLVE_ADDRESS_TYPES [1 ] = InternetProtocolFamily2 .IPv6 ;
96
- LOCALHOST_ADDRESS = NetUtil2 .LOCALHOST4 ;
98
+ LOCALHOST_ADDRESS = NetUtil .LOCALHOST4 ;
97
99
}
98
100
}
99
101
}
@@ -155,6 +157,7 @@ protected DnsServerAddressStream initialValue() throws Exception {
155
157
private final boolean cnameFollowAAAARecords ;
156
158
private final InternetProtocolFamily2 preferredAddressType ;
157
159
private final DnsRecordType [] resolveRecordTypes ;
160
+ private final boolean decodeIdn ;
158
161
159
162
/**
160
163
* 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 {
175
178
* @param hostsFileEntriesResolver the {@link HostsFileEntriesResolver} used to check for local aliases
176
179
* @param searchDomains the list of search domain
177
180
* @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)}
178
184
*/
185
+ @ Deprecated
179
186
public DnsNameResolver (
180
187
EventLoop eventLoop ,
181
188
ChannelFactory <? extends DatagramChannel > channelFactory ,
@@ -191,6 +198,49 @@ public DnsNameResolver(
191
198
HostsFileEntriesResolver hostsFileEntriesResolver ,
192
199
String [] searchDomains ,
193
200
int 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 ) {
194
244
195
245
super (eventLoop );
196
246
checkNotNull (channelFactory , "channelFactory" );
@@ -206,6 +256,7 @@ public DnsNameResolver(
206
256
this .resolveCache = checkNotNull (resolveCache , "resolveCache" );
207
257
this .searchDomains = checkNotNull (searchDomains , "searchDomains" ).clone ();
208
258
this .ndots = checkPositiveOrZero (ndots , "ndots" );
259
+ this .decodeIdn = decodeIdn ;
209
260
210
261
boolean cnameFollowARecords = false ;
211
262
boolean cnameFollowAAAARecords = false ;
@@ -309,6 +360,10 @@ final DnsRecordType[] resolveRecordTypes() {
309
360
return resolveRecordTypes ;
310
361
}
311
362
363
+ final boolean isDecodeIdn () {
364
+ return decodeIdn ;
365
+ }
366
+
312
367
/**
313
368
* Returns {@code true} if and only if this resolver sends a DNS query with the RD (recursion desired) flag set.
314
369
* The default value is {@code true}.
@@ -503,7 +558,7 @@ private static void validateAdditional(DnsRecord record, boolean validateType) {
503
558
@ Override
504
559
protected final InetAddress loopbackAddress () {
505
560
return preferredAddressType () == InternetProtocolFamily2 .IPv4 ?
506
- NetUtil2 .LOCALHOST4 : NetUtil2 .LOCALHOST6 ;
561
+ NetUtil .LOCALHOST4 : NetUtil .LOCALHOST6 ;
507
562
}
508
563
509
564
/**
@@ -514,7 +569,7 @@ protected void doResolve(String inetHost,
514
569
DnsRecord [] additionals ,
515
570
Promise <InetAddress > promise ,
516
571
DnsCache resolveCache ) throws Exception {
517
- final byte [] bytes = NetUtil2 .createByteArrayFromIpAddressString (inetHost );
572
+ final byte [] bytes = NetUtil .createByteArrayFromIpAddressString (inetHost );
518
573
if (bytes != null ) {
519
574
// The inetHost is actually an ipaddress.
520
575
promise .setSuccess (InetAddress .getByAddress (bytes ));
@@ -639,7 +694,7 @@ protected void doResolveAll(String inetHost,
639
694
DnsRecord [] additionals ,
640
695
Promise <List <InetAddress >> promise ,
641
696
DnsCache resolveCache ) throws Exception {
642
- final byte [] bytes = NetUtil2 .createByteArrayFromIpAddressString (inetHost );
697
+ final byte [] bytes = NetUtil .createByteArrayFromIpAddressString (inetHost );
643
698
if (bytes != null ) {
644
699
// The unresolvedAddress was created via a String that contains an ipaddress.
645
700
promise .setSuccess (Collections .singletonList (InetAddress .getByAddress (bytes )));
0 commit comments