use of org.minidns.record.NS in project minidns by MiniDNS.
the class IterativeDNSClient method queryRecursive.
private DNSMessage queryRecursive(ResolutionState resolutionState, DNSMessage q, InetAddress address, DNSName authoritativeZone) throws IOException {
resolutionState.recurse(address, q);
DNSMessage resMessage = query(q, address);
if (resMessage == null) {
// TODO throw exception here?
return null;
}
if (resMessage.authoritativeAnswer) {
return resMessage;
}
if (cache != null) {
cache.offer(q, resMessage, authoritativeZone);
}
List<Record<? extends Data>> authorities = resMessage.copyAuthority();
List<IOException> ioExceptions = new LinkedList<>();
// Glued NS first
for (Iterator<Record<? extends Data>> iterator = authorities.iterator(); iterator.hasNext(); ) {
Record<? extends Data> record = iterator.next();
if (record.type != TYPE.NS) {
iterator.remove();
continue;
}
DNSName name = ((NS) record.payloadData).target;
IpResultSet gluedNs = searchAdditional(resMessage, name);
for (Iterator<InetAddress> addressIterator = gluedNs.addresses.iterator(); addressIterator.hasNext(); ) {
InetAddress target = addressIterator.next();
DNSMessage recursive = null;
try {
recursive = queryRecursive(resolutionState, q, target, record.name);
} catch (IOException e) {
abortIfFatal(e);
LOGGER.log(Level.FINER, "Exception while recursing", e);
resolutionState.decrementSteps();
ioExceptions.add(e);
if (!addressIterator.hasNext()) {
iterator.remove();
}
continue;
}
return recursive;
}
}
// Try non-glued NS
for (Record<? extends Data> record : authorities) {
final Question question = q.getQuestion();
DNSName name = ((NS) record.payloadData).target;
// AAAA RR, then we should not continue here as it would result in an endless loop.
if (question.name.equals(name) && (question.type == TYPE.A || question.type == TYPE.AAAA))
continue;
IpResultSet res = null;
try {
res = resolveIpRecursive(resolutionState, name);
} catch (IOException e) {
resolutionState.decrementSteps();
ioExceptions.add(e);
}
if (res == null) {
continue;
}
for (InetAddress target : res.addresses) {
DNSMessage recursive = null;
try {
recursive = queryRecursive(resolutionState, q, target, record.name);
} catch (IOException e) {
resolutionState.decrementSteps();
ioExceptions.add(e);
continue;
}
return recursive;
}
}
MultipleIoException.throwIfRequired(ioExceptions);
// where we able to find glue records or the IPs of the next nameservers.
return null;
}
use of org.minidns.record.NS in project minidns by MiniDNS.
the class AbstractDNSClient method getCachedIPNameserverAddressesFor.
@SuppressWarnings("unchecked")
private <D extends Data> Set<D> getCachedIPNameserverAddressesFor(DNSName dnsName, TYPE type) {
Set<NS> nsSet = getCachedNameserverRecordsFor(dnsName);
if (nsSet.isEmpty())
return Collections.emptySet();
Set<D> res = new HashSet<>(3 * nsSet.size());
for (NS ns : nsSet) {
Set<D> addresses;
switch(type) {
case A:
addresses = (Set<D>) getCachedIPv4AddressesFor(ns.target);
break;
case AAAA:
addresses = (Set<D>) getCachedIPv6AddressesFor(ns.target);
break;
default:
throw new AssertionError();
}
res.addAll(addresses);
}
return res;
}
Aggregations