aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/utils/Resolver.java41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java
index ff2dce039..250a6f097 100644
--- a/src/main/java/de/pixart/messenger/utils/Resolver.java
+++ b/src/main/java/de/pixart/messenger/utils/Resolver.java
@@ -177,6 +177,10 @@ public class Resolver {
ResolverResult<SRV> result = resolveWithFallback(dnsName, SRV.class);
final List<Result> results = new ArrayList<>();
final List<Thread> threads = new ArrayList<>();
+
+ final List<Result> fallbackResults = new ArrayList<>();
+ final List<Thread> fallbackThreads = new ArrayList<>();
+
for (SRV record : result.getAnswersOrEmptySet()) {
if (record.name.length() == 0) {
continue;
@@ -193,6 +197,22 @@ public class Resolver {
results.addAll(ipv4s);
}
}));
+ fallbackThreads.add(new Thread(() -> {
+ try {
+ for (CNAME cname : resolveWithFallback(record.name, CNAME.class, result.isAuthenticData()).getAnswersOrEmptySet()) {
+ final List<Result> ipv6s = resolveIp(record, cname.name, AAAA.class, result.isAuthenticData(), directTls);
+ synchronized (fallbackResults) {
+ fallbackResults.addAll(ipv6s);
+ }
+ final List<Result> ipv4s = resolveIp(record, cname.name, A.class, result.isAuthenticData(), directTls);
+ synchronized (results) {
+ fallbackResults.addAll(ipv4s);
+ }
+ }
+ } catch (Throwable throwable) {
+ Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving srv cname-fallback records", throwable);
+ }
+ }));
}
for (Thread thread : threads) {
thread.start();
@@ -205,13 +225,30 @@ public class Resolver {
return Collections.emptyList();
}
}
- return results;
+ if (results.size() > 0) {
+ return results;
+ }
+ for (Thread thread : fallbackThreads) {
+ thread.start();
+ }
+ for (Thread thread : fallbackThreads) {
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ return Collections.emptyList();
+ }
+ }
+ return fallbackResults;
}
private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) {
+ return resolveIp(srv, srv.name, type, authenticated, directTls);
+ }
+
+ private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, DNSName hostname, Class<D> type, boolean authenticated, boolean directTls) {
List<Result> list = new ArrayList<>();
try {
- ResolverResult<D> results = resolveWithFallback(srv.name, type, authenticated);
+ ResolverResult<D> results = resolveWithFallback(hostname, type, authenticated);
for (D record : results.getAnswersOrEmptySet()) {
Result resolverResult = Result.fromRecord(srv, directTls);
resolverResult.authenticated = results.isAuthenticData() && authenticated;