aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-12-14 19:02:29 +0100
committeriNPUTmice <daniel@gultsch.de>2014-12-14 19:02:29 +0100
commit5cbae258084a5f77857c5f535451fe3b459ce0d1 (patch)
tree9a557c623ff285cdb5b973eb319d5168452f93c3 /src/main/java/eu/siacs/conversations
parent50410dad334643945e4978117d81dc3cbf4c3157 (diff)
more patches for dns helper
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/utils/DNSHelper.java32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
index 2aa6f5738..a09b4d0fe 100644
--- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
@@ -140,23 +140,17 @@ 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())) {
- ArrayList<String> ip = ips6.get(srv.getName());
- Collections.shuffle(ip, rnd);
- namePort.putString("ip", ip.get(0));
- values.add(namePort);
+ 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("ip", ip.get(0));
- values.add(namePort);
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4));
+ added = true;
}
- if (!ips6.containsKey(srv.getName()) && !ips4.containsKey(srv.getName())) {
- values.add(namePort);
+ if (!added) {
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),null));
}
}
bundle.putParcelableArrayList("values", values);
@@ -168,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) {