diff options
Diffstat (limited to 'src/main')
4 files changed, 37 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 74d0cf010..1ad4295d3 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -134,7 +134,8 @@ public class Account extends AbstractEntity { POLICY_VIOLATION(true), REGISTRATION_PASSWORD_TOO_WEAK(true), PAYMENT_REQUIRED(true), - MISSING_INTERNET_PERMISSION(true); + MISSING_INTERNET_PERMISSION(true), + NETWORK_IS_UNREACHABLE(false); private final boolean isError; @@ -202,6 +203,8 @@ public class Account extends AbstractEntity { return R.string.payment_required; case MISSING_INTERNET_PERMISSION: return R.string.missing_internet_permission; + case NETWORK_IS_UNREACHABLE: + return R.string.network_is_unreachable; default: return R.string.account_status_unknown; } diff --git a/src/main/java/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java index 0dc5bd0ac..83875b3eb 100644 --- a/src/main/java/de/pixart/messenger/utils/Resolver.java +++ b/src/main/java/de/pixart/messenger/utils/Resolver.java @@ -9,6 +9,7 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import de.measite.minidns.DNSClient; @@ -23,6 +24,7 @@ import de.measite.minidns.record.CNAME; import de.measite.minidns.record.Data; import de.measite.minidns.record.InternetAddressRR; import de.measite.minidns.record.SRV; +import de.measite.minidns.util.MultipleIoException; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.services.XmppConnectionService; @@ -32,6 +34,8 @@ public class Resolver { private static final String DIRECT_TLS_SERVICE = "_xmpps-client"; private static final String STARTTLS_SERICE = "_xmpp-client"; + private static final String NETWORK_IS_UNREACHABLE = "Network is unreachable"; + private static XmppConnectionService SERVICE = null; public static void registerXmppConnectionService(XmppConnectionService service) { @@ -43,19 +47,28 @@ public class Resolver { DNSClient.addDnsServerLookupMechanism(new AndroidUsingLinkProperties(context)); } - public static List<Result> resolve(String domain) { + public static List<Result> resolve(String domain) throws NetworkIsUnreachableException { List<Result> results = new ArrayList<>(); + HashSet<String> messages = new HashSet<>(); + try { results.addAll(resolveSrv(domain, true)); + } catch (MultipleIoException e) { + messages.addAll(extractMessages(e)); } catch (Throwable throwable) { Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (direct TLS)", throwable); } try { results.addAll(resolveSrv(domain, false)); + } catch (MultipleIoException e) { + messages.addAll(extractMessages(e)); } catch (Throwable throwable) { Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (STARTTLS)", throwable); } if (results.size() == 0) { + if (messages.size() == 1 && messages.contains(NETWORK_IS_UNREACHABLE)) { + throw new NetworkIsUnreachableException(); + } results.addAll(resolveNoSrvRecords(DNSName.from(domain), true)); } Collections.sort(results); @@ -63,6 +76,18 @@ public class Resolver { return results; } + private static HashSet<String> extractMessages(MultipleIoException e) { + HashSet<String> messages = new HashSet<>(); + for (Exception inner : e.getExceptions()) { + if (inner instanceof MultipleIoException) { + messages.addAll(extractMessages((MultipleIoException) inner)); + } else { + messages.add(inner.getMessage()); + } + } + return messages; + } + private static List<Result> resolveSrv(String domain, final boolean directTls) throws IOException { if (Thread.currentThread().isInterrupted()) { return Collections.emptyList(); @@ -238,4 +263,8 @@ public class Resolver { return createDefault(hostname, null); } } + + public static class NetworkIsUnreachableException extends Exception { + + } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 24510b038..378cd78aa 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -448,6 +448,8 @@ public class XmppConnection implements Runnable { this.changeStatus(Account.State.MISSING_INTERNET_PERMISSION); } catch (final StateChangingException e) { this.changeStatus(e.state); + } catch (final Resolver.NetworkIsUnreachableException e) { + this.changeStatus(Account.State.NETWORK_IS_UNREACHABLE); } catch (final UnknownHostException | ConnectException e) { this.changeStatus(Account.State.SERVER_NOT_FOUND); } catch (final SocksSocketFactory.SocksProxyNotFoundException e) { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 44ad91908..0cb129c93 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -781,4 +781,5 @@ <string name="yesterday">Yesterday</string> <string name="pref_validate_hostname">Validate hostname with DNSSEC</string> <string name="pref_validate_hostname_summary">Server certificates that contain the validated hostname are considered verified</string> + <string name="network_is_unreachable">Network is unreachable</string> </resources> |