aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-10-02 22:09:17 +0200
committerChristian Schneppe <christian@pix-art.de>2018-10-02 22:09:17 +0200
commit526c9de0f5b562487e27b43b661b9ebf1f431972 (patch)
tree5a0cf0c749018502c2c3dc422575624fca11f1a9 /src/main/java/de/pixart/messenger/utils
parentf162458323365bdd2a8aa0a1a97e5a79753ccf0d (diff)
clean up connection code. unify domain = ip and extended connection settings into fake resolver
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils')
-rw-r--r--src/main/java/de/pixart/messenger/utils/Resolver.java37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java
index e159c3dd0..a1bd22d36 100644
--- a/src/main/java/de/pixart/messenger/utils/Resolver.java
+++ b/src/main/java/de/pixart/messenger/utils/Resolver.java
@@ -63,14 +63,26 @@ public class Resolver {
final Field useHardcodedDnsServers = DNSClient.class.getDeclaredField("useHardcodedDnsServers");
useHardcodedDnsServers.setAccessible(true);
useHardcodedDnsServers.setBoolean(dnsClient, false);
- } catch (NoSuchFieldException e) {
- Log.e(Config.LOGTAG, "Unable to disable hardcoded DNS servers", e);
- } catch (IllegalAccessException e) {
+ } catch (NoSuchFieldException | IllegalAccessException e) {
Log.e(Config.LOGTAG, "Unable to disable hardcoded DNS servers", e);
}
}
+ public static List<Result> fromHardCoded(String hostname, int port) {
+ Result result = new Result();
+ result.hostname = DNSName.from(hostname);
+ result.port = port;
+ result.directTls = port == 443 || port == 5223;
+ result.authenticated = true;
+ return Collections.singletonList(result);
+ }
+
+
public static List<Result> resolve(String domain) {
+ final List<Result> ipResults = fromIpAddress(domain);
+ if (ipResults.size() > 0) {
+ return ipResults;
+ }
final List<Result> results = new ArrayList<>();
final List<Result> fallbackResults = new ArrayList<>();
Thread[] threads = new Thread[3];
@@ -125,9 +137,21 @@ public class Resolver {
for (Thread thread : threads) {
thread.interrupt();
}
- synchronized (results) {
- return new ArrayList<>(results);
- }
+ return Collections.emptyList();
+ }
+ }
+
+ private static List<Result> fromIpAddress(String domain) {
+ if (!IP.matches(domain)) {
+ return Collections.emptyList();
+ }
+ try {
+ Result result = new Result();
+ result.ip = InetAddress.getByName(domain);
+ result.port = 5222;
+ return Collections.singletonList(result);
+ } catch (UnknownHostException e) {
+ return Collections.emptyList();
}
}
@@ -377,5 +401,4 @@ public class Resolver {
return contentValues;
}
}
-
} \ No newline at end of file