/** * Resolves the specified host name and port into a list of address. * * @param inetHost the name to resolve * @param additionals additional records ({@code OPT}) * * @return the list of the address as the result of the resolution */ public final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals) { return resolveAll(inetHost, additionals, executor().<List<InetAddress>>newPromise()); }
/** * Sends a DNS query with the specified question with additional records. */ public Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query( DnsQuestion question, Iterable<DnsRecord> additionals) { return query(nextNameServerAddress(), question, additionals); }
AuthoritativeDnsServerCache authoritativeDnsServerCache = this.authoritativeDnsServerCache != null ? this.authoritativeDnsServerCache : newAuthoritativeDnsServerCache(); return new DnsNameResolver( eventLoop, channelFactory,
/** * Resolves the {@link DnsRecord}s that are matched by the specified {@link DnsQuestion}. Unlike * {@link #query(DnsQuestion)}, this method handles redirection, CNAMEs and multiple name servers. * If the specified {@link DnsQuestion} is {@code A} or {@code AAAA}, this method looks up the configured * {@link HostsFileEntries} before sending a query to the name servers. If a match is found in the * {@link HostsFileEntries}, a synthetic {@code A} or {@code AAAA} record will be returned. * * @param question the question * @param additionals additional records ({@code OPT}) * @param promise the {@link Promise} which will be fulfilled when the resolution is finished * * @return the list of the {@link DnsRecord}s as the result of the resolution */ public final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals, Promise<List<DnsRecord>> promise) { final DnsRecord[] additionalsArray = toArray(additionals, true); return resolveAll(question, additionalsArray, promise); }
@Override void doSearchDomainQuery(String hostname, Promise<List<InetAddress>> nextPromise) { // Query the cache for the hostname first and only do a query if we could not find it in the cache. if (!DnsNameResolver.doResolveAllCached( hostname, additionals, nextPromise, resolveCache, parent.resolvedInternetProtocolFamiliesUnsafe())) { super.doSearchDomainQuery(hostname, nextPromise); } }
/** * Hook designed for extensibility so one can pass a different cache on each resolution attempt * instead of using the global one. */ protected void doResolve(String inetHost, DnsRecord[] additionals, Promise<InetAddress> promise, DnsCache resolveCache) throws Exception { if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getByName(...) does. promise.setSuccess(loopbackAddress()); return; } final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); if (bytes != null) { // The inetHost is actually an ipaddress. promise.setSuccess(InetAddress.getByAddress(bytes)); return; } final String hostname = hostname(inetHost); InetAddress hostsFileEntry = resolveHostsFileEntry(hostname); if (hostsFileEntry != null) { promise.setSuccess(hostsFileEntry); return; } if (!doResolveCached(hostname, additionals, promise, resolveCache)) { doResolveUncached(hostname, additionals, promise, resolveCache); } }
/** * Hook designed for extensibility so one can pass a different cache on each resolution attempt * instead of using the global one. */ protected void doResolveAll(String inetHost, DnsRecord[] additionals, Promise<List<InetAddress>> promise, DnsCache resolveCache) throws Exception { if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getAllByName(...) does. promise.setSuccess(Collections.singletonList(loopbackAddress())); return; } final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); if (bytes != null) { // The unresolvedAddress was created via a String that contains an ipaddress. promise.setSuccess(Collections.singletonList(InetAddress.getByAddress(bytes))); return; } final String hostname = hostname(inetHost); InetAddress hostsFileEntry = resolveHostsFileEntry(hostname); if (hostsFileEntry != null) { promise.setSuccess(Collections.singletonList(hostsFileEntry)); return; } if (!doResolveAllCached(hostname, additionals, promise, resolveCache, resolvedInternetProtocolFamilies)) { doResolveAllUncached(hostname, additionals, promise, resolveCache); } }
final Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> resolveFuture = parent.executor() .newSucceededFuture(null); queriesInProgress.add(resolveFuture); Promise<List<InetAddress>> resolverPromise = parent.executor().newPromise(); resolverPromise.addListener(new FutureListener<List<InetAddress>>() { @Override if (!DnsNameResolver.doResolveAllCached(nameServerName, additionals, resolverPromise, resolveCache(), parent.resolvedInternetProtocolFamiliesUnsafe())) { final AuthoritativeDnsServerCache authoritativeDnsServerCache = authoritativeDnsServerCache(); new DnsAddressResolveContext(parent, nameServerName, additionals, parent.newNameServerAddressStream(nameServerName), resolveCache(), new AuthoritativeDnsServerCache() { @Override
/** * Resolves the specified host name and port into a list of address. * * @param inetHost the name to resolve * @param additionals additional records ({@code OPT}) * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished * * @return the list of the address as the result of the resolution */ public final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals, Promise<List<InetAddress>> promise) { checkNotNull(promise, "promise"); if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getAllByName(...) does. return promise.setSuccess(Collections.singletonList(loopbackAddress())); } DnsRecord[] additionalsArray = toArray(additionals, true); try { doResolveAll(inetHost, additionalsArray, promise, resolveCache); return promise; } catch (Exception e) { return promise.setFailure(e); } }
/** * Resolves the specified name into an address. * * @param inetHost the name to resolve * @param additionals additional records ({@code OPT}) * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished * * @return the address as the result of the resolution */ public final Future<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals, Promise<InetAddress> promise) { checkNotNull(promise, "promise"); if (inetHost == null || inetHost.isEmpty()) { // If an empty hostname is used we should use "localhost", just like InetAddress.getByName(...) does. return promise.setSuccess(loopbackAddress()); } DnsRecord[] additionalsArray = toArray(additionals, true); try { doResolve(inetHost, additionalsArray, promise, resolveCache); return promise; } catch (Exception e) { return promise.setFailure(e); } }
private void doResolveUncached(String hostname, DnsRecord[] additionals, final Promise<InetAddress> promise, DnsCache resolveCache) { final Promise<List<InetAddress>> allPromise = executor().newPromise(); doResolveAllUncached(hostname, additionals, allPromise, resolveCache); allPromise.addListener(new FutureListener<List<InetAddress>>() { @Override public void operationComplete(Future<List<InetAddress>> future) { if (future.isSuccess()) { trySuccess(promise, future.getNow().get(0)); } else { tryFailure(promise, future.cause()); } } }); }
/** * Resolves the specified name into an address. * * @param inetHost the name to resolve * @param additionals additional records ({@code OPT}) * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished * * @return the address as the result of the resolution */ public final Future<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals, Promise<InetAddress> promise) { checkNotNull(promise, "promise"); DnsRecord[] additionalsArray = toArray(additionals, true); try { doResolve(inetHost, additionalsArray, promise, resolveCache); return promise; } catch (Exception e) { return promise.setFailure(e); } }
/** * Resolves the specified host name and port into a list of address. * * @param inetHost the name to resolve * @param additionals additional records ({@code OPT}) * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished * * @return the list of the address as the result of the resolution */ public final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals, Promise<List<InetAddress>> promise) { checkNotNull(promise, "promise"); DnsRecord[] additionalsArray = toArray(additionals, true); try { doResolveAll(inetHost, additionalsArray, promise, resolveCache); return promise; } catch (Exception e) { return promise.setFailure(e); } }
@VisibleForTesting CompletableFuture<List<InetAddress>> resolveName(String hostname) { CompletableFuture<List<InetAddress>> future = new CompletableFuture<>(); dnsResolver.resolveAll(hostname).addListener((Future<List<InetAddress>> resolveFuture) -> { if (resolveFuture.isSuccess()) { future.complete(resolveFuture.get()); } else { future.completeExceptionally(resolveFuture.cause()); } }); return future; }
content = resolver.query(new DefaultDnsQuestion(hostName, DnsRecordType.TXT)).sync().get().content(); int count = content.count(DnsSection.ANSWER); final ArrayList<TxtDnsAnswer> txtRecords = new ArrayList<>(count);
/** * The {@link AuthoritativeDnsServerCache} to use while resolving. */ AuthoritativeDnsServerCache authoritativeDnsServerCache() { return parent.authoritativeDnsServerCache(); }
final Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query0( InetSocketAddress nameServerAddr, DnsQuestion question, DnsRecord[] additionals, ChannelPromise writePromise, Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise) { assert !writePromise.isVoid(); final Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>> castPromise = cast( checkNotNull(promise, "promise")); try { new DnsQueryContext(this, nameServerAddr, question, additionals, castPromise).query(writePromise); return castPromise; } catch (Exception e) { return castPromise.setFailure(e); } }
@Override protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception { doResolveAll(inetHost, EMPTY_ADDITIONALS, promise, resolveCache); }
@Override protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception { doResolve(inetHost, EMPTY_ADDITIONALS, promise, resolveCache); }
final Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query0( InetSocketAddress nameServerAddr, DnsQuestion question, DnsRecord[] additionals, boolean flush, ChannelPromise writePromise, Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise) { assert !writePromise.isVoid(); final Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>> castPromise = cast( checkNotNull(promise, "promise")); try { new DnsQueryContext(this, nameServerAddr, question, additionals, castPromise) .query(flush, writePromise); return castPromise; } catch (Exception e) { return castPromise.setFailure(e); } }