aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-06-26 20:05:03 +0200
committerChristian Schneppe <christian@pix-art.de>2017-06-26 20:05:03 +0200
commit2228f2d07649dbeda15af966fac5142317e9b5a7 (patch)
treeb7f702249823997d266ee59468da9c2675cfdc83 /src/main
parent76e85b1724003c5afb6de70eb6f849988f9249b4 (diff)
use ResolverApi.reliable(..)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/utils/Resolver.java42
1 files changed, 11 insertions, 31 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java
index d69a828e2..3f4ffa43f 100644
--- a/src/main/java/de/pixart/messenger/utils/Resolver.java
+++ b/src/main/java/de/pixart/messenger/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 de.pixart.messenger.Config;
@@ -54,25 +49,16 @@ public class Resolver {
}
private static List<Result> resolveSrv(String domain, final boolean directTls) throws IOException {
- Question question = new Question((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE) + "._tcp." + domain, Record.TYPE.SRV);
- ResolverResult<Data> 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<SRV> result = DnssecResolverApi.INSTANCE.resolveDnssecReliable(dnsName, SRV.class);
List<Result> 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;
@@ -81,13 +67,7 @@ public class Resolver {
private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) {
List<Result> list = new ArrayList<>();
try {
- ResolverResult<D> 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<D> results = DnssecResolverApi.INSTANCE.resolveDnssecReliable(srv.name, type);
for (D record : results.getAnswersOrEmptySet()) {
Result resolverResult = Result.fromRecord(srv, directTls);
resolverResult.authenticated = results.isAuthenticData() && authenticated;
@@ -131,7 +111,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 +