From e5becc2e129f44b537670b8b3d557eb64da99ce9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 21 Sep 2017 21:46:11 +0200 Subject: [PATCH] slightly refactor dns resolver --- .../eu/siacs/conversations/utils/Resolver.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/Resolver.java b/src/main/java/eu/siacs/conversations/utils/Resolver.java index a23ef26ba..1e650c98c 100644 --- a/src/main/java/eu/siacs/conversations/utils/Resolver.java +++ b/src/main/java/eu/siacs/conversations/utils/Resolver.java @@ -14,6 +14,8 @@ import java.util.List; import de.measite.minidns.DNSClient; 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.dnsserverlookup.AndroidUsingExec; import de.measite.minidns.hla.DnssecResolverApi; @@ -151,18 +153,12 @@ public class Resolver { } private static ResolverResult resolveWithFallback(DNSName dnsName, Class type, boolean validateHostname) throws IOException { + final Question question = new Question(dnsName, Record.TYPE.getType(type)); if (!validateHostname) { - return ResolverApi.INSTANCE.resolve(dnsName, type); + return ResolverApi.INSTANCE.resolve(question); } try { - final ResolverResult r = DnssecResolverApi.INSTANCE.resolveDnssecReliable(dnsName, type); - 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()); + return DnssecResolverApi.INSTANCE.resolveDnssecReliable(question); } catch (DNSSECResultNotAuthenticException e) { Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", e); } catch (IOException e) { @@ -170,7 +166,7 @@ public class Resolver { } catch (Throwable 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() {