From 4faf0f2ec95a64f423544d011cddce51b9ef16fa Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 25 Jun 2017 19:30:03 +0200 Subject: [PATCH] use ResolverApi.reliable(..) --- .../siacs/conversations/utils/Resolver.java | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/Resolver.java b/src/main/java/eu/siacs/conversations/utils/Resolver.java index 272a1e7bd..0d92bcea9 100644 --- a/src/main/java/eu/siacs/conversations/utils/Resolver.java +++ b/src/main/java/eu/siacs/conversations/utils/Resolver.java @@ -12,15 +12,10 @@ 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.DNSSECValidationFailedException; import de.measite.minidns.hla.DnssecResolverApi; -import de.measite.minidns.hla.ResolverApi; import de.measite.minidns.hla.ResolverResult; import de.measite.minidns.record.A; import de.measite.minidns.record.AAAA; -import de.measite.minidns.record.Data; import de.measite.minidns.record.InternetAddressRR; import de.measite.minidns.record.SRV; import eu.siacs.conversations.Config; @@ -57,25 +52,16 @@ public class Resolver { } private static List resolveSrv(String domain, final boolean directTls) throws IOException { - Question question = new Question((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE)+"._tcp."+domain,Record.TYPE.SRV); - ResolverResult result; - try { - result = DnssecResolverApi.INSTANCE.resolve(question); - } catch (DNSSECValidationFailedException e) { - Log.d(Config.LOGTAG,Resolver.class.getSimpleName()+": error resolving SRV record with DNSSEC. Trying DNS instead "+e.getMessage()); - result = ResolverApi.INSTANCE.resolve(question); - } + DNSName dnsName = DNSName.from((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE)+"._tcp."+domain); + ResolverResult result = DnssecResolverApi.INSTANCE.resolveDnssecReliable(dnsName,SRV.class); List results = new ArrayList<>(); - for(Data record : result.getAnswersOrEmptySet()) { - if (record instanceof SRV) { - SRV srvRecord = (SRV) record; - boolean added = results.addAll(resolveIp(srvRecord,A.class,result.isAuthenticData(),directTls)); - added |= results.addAll(resolveIp(srvRecord,AAAA.class,result.isAuthenticData(),directTls)); - if (!added) { - Result resolverResult = Result.fromRecord(srvRecord, directTls); - resolverResult.authenticated = resolverResult.isAuthenticated(); - results.add(resolverResult); - } + for(SRV record : result.getAnswersOrEmptySet()) { + boolean added = results.addAll(resolveIp(record,A.class,result.isAuthenticData(),directTls)); + added |= results.addAll(resolveIp(record,AAAA.class,result.isAuthenticData(),directTls)); + if (!added) { + Result resolverResult = Result.fromRecord(record, directTls); + resolverResult.authenticated = resolverResult.isAuthenticated(); + results.add(resolverResult); } } return results; @@ -84,13 +70,7 @@ public class Resolver { private static List resolveIp(SRV srv, Class type, boolean authenticated, boolean directTls) { List list = new ArrayList<>(); try { - ResolverResult results; - try { - results = DnssecResolverApi.INSTANCE.resolve(srv.name, type); - } catch (DNSSECValidationFailedException e) { - Log.d(Config.LOGTAG,Resolver.class.getSimpleName()+": error resolving "+type.getSimpleName()+" with DNSSEC. Trying DNS instead "+e.getMessage()); - results = ResolverApi.INSTANCE.resolve(srv.name,type); - } + ResolverResult results = DnssecResolverApi.INSTANCE.resolveDnssecReliable(srv.name, type); for (D record : results.getAnswersOrEmptySet()) { Result resolverResult = Result.fromRecord(srv, directTls); resolverResult.authenticated = results.isAuthenticData() && authenticated; @@ -134,7 +114,7 @@ public class Resolver { @Override public String toString() { return "Result{" + - "ip='" + ip + '\'' + + "ip='" + (ip==null?null:ip.getHostAddress()) + '\'' + ", hostame='" + hostname.toString() + '\'' + ", port=" + port + ", directTls=" + directTls +