aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/utils/DNSHelper.java')
-rw-r--r--src/main/java/eu/siacs/conversations/utils/DNSHelper.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
index 8c1a8dea..a09b4d0f 100644
--- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
@@ -140,15 +140,18 @@ public class DNSHelper {
}
ArrayList<Bundle> values = new ArrayList<>();
for (SRV srv : result) {
- Bundle namePort = new Bundle();
- namePort.putString("name", srv.getName());
- namePort.putInt("port", srv.getPort());
+ boolean added = false;
+ if (ips6.containsKey(srv.getName())) {
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips6));
+ added = true;
+ }
if (ips4.containsKey(srv.getName())) {
- ArrayList<String> ip = ips4.get(srv.getName());
- Collections.shuffle(ip, rnd);
- namePort.putString("ipv4", ip.get(0));
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4));
+ added = true;
+ }
+ if (!added) {
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),null));
}
- values.add(namePort);
}
bundle.putParcelableArrayList("values", values);
} catch (SocketTimeoutException e) {
@@ -159,6 +162,18 @@ public class DNSHelper {
return bundle;
}
+ private static Bundle createNamePortBundle(String name, int port, TreeMap<String, ArrayList<String>> ips) {
+ Bundle namePort = new Bundle();
+ namePort.putString("name", name);
+ namePort.putInt("port", port);
+ if (ips!=null) {
+ ArrayList<String> ip = ips.get(name);
+ Collections.shuffle(ip, new Random());
+ namePort.putString("ip", ip.get(0));
+ }
+ return namePort;
+ }
+
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {