rewrote dns fallback

This commit is contained in:
Daniel Gultsch 2015-07-24 19:06:47 +02:00
parent e5fae429fa
commit 9c94c9ad8f
2 changed files with 9 additions and 9 deletions

View File

@ -38,17 +38,14 @@ public class DNSHelper {
public static Bundle getSRVRecord(final Jid jid) throws IOException {
final String host = jid.getDomainpart();
String dns[] = client.findDNS();
if (dns != null) {
for (String dnsserver : dns) {
InetAddress ip = InetAddress.getByName(dnsserver);
Bundle b = queryDNS(host, ip);
if (b.containsKey("values")) {
return b;
}
for (int i = 0; i < dns.length; ++i) {
InetAddress ip = InetAddress.getByName(dns[i]);
Bundle b = queryDNS(host, ip);
if (b.containsKey("values") || i == dns.length - 1) {
return b;
}
}
return queryDNS(host, InetAddress.getByName("8.8.8.8"));
return null;
}
public static Bundle queryDNS(String host, InetAddress dnsServer) {

View File

@ -164,6 +164,9 @@ public class XmppConnection implements Runnable {
}
} else {
final Bundle result = DNSHelper.getSRVRecord(account.getServer());
if (result == null) {
throw new IOException("unhandled exception in DNS resolver");
}
final ArrayList<Parcelable> values = result.getParcelableArrayList("values");
if ("timeout".equals(result.getString("error"))) {
throw new IOException("timeout in dns");