slightly refactor dns resolver

This commit is contained in:
Daniel Gultsch 2017-09-21 21:46:11 +02:00
parent 881d4ad5b7
commit e5becc2e12
1 changed files with 6 additions and 10 deletions

View File

@ -14,6 +14,8 @@ import java.util.List;
import de.measite.minidns.DNSClient; import de.measite.minidns.DNSClient;
import de.measite.minidns.DNSName; import de.measite.minidns.DNSName;
import de.measite.minidns.Question;
import de.measite.minidns.Record;
import de.measite.minidns.dnssec.DNSSECResultNotAuthenticException; import de.measite.minidns.dnssec.DNSSECResultNotAuthenticException;
import de.measite.minidns.dnsserverlookup.AndroidUsingExec; import de.measite.minidns.dnsserverlookup.AndroidUsingExec;
import de.measite.minidns.hla.DnssecResolverApi; import de.measite.minidns.hla.DnssecResolverApi;
@ -151,18 +153,12 @@ public class Resolver {
} }
private static <D extends Data> ResolverResult<D> resolveWithFallback(DNSName dnsName, Class<D> type, boolean validateHostname) throws IOException { private static <D extends Data> ResolverResult<D> resolveWithFallback(DNSName dnsName, Class<D> type, boolean validateHostname) throws IOException {
final Question question = new Question(dnsName, Record.TYPE.getType(type));
if (!validateHostname) { if (!validateHostname) {
return ResolverApi.INSTANCE.resolve(dnsName, type); return ResolverApi.INSTANCE.resolve(question);
} }
try { try {
final ResolverResult<D> r = DnssecResolverApi.INSTANCE.resolveDnssecReliable(dnsName, type); return DnssecResolverApi.INSTANCE.resolveDnssecReliable(question);
if (r.wasSuccessful()) {
if (r.getAnswers().isEmpty() && type.equals(SRV.class)) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": resolving SRV records of " + dnsName.toString() + " with DNSSEC yielded empty result");
}
return r;
}
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", r.getResolutionUnsuccessfulException());
} catch (DNSSECResultNotAuthenticException e) { } catch (DNSSECResultNotAuthenticException e) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", e); Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", e);
} catch (IOException e) { } catch (IOException e) {
@ -170,7 +166,7 @@ public class Resolver {
} catch (Throwable throwable) { } catch (Throwable throwable) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", throwable); Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", throwable);
} }
return ResolverApi.INSTANCE.resolve(dnsName, type); return ResolverApi.INSTANCE.resolve(question);
} }
private static boolean validateHostname() { private static boolean validateHostname() {