speed up DNS

run queries in parallel
decrease timeout
do not fall back to google
This commit is contained in:
Daniel Gultsch 2018-09-08 11:30:15 +02:00
parent accc378c4b
commit be4c6bc2ca
5 changed files with 306 additions and 273 deletions

View File

@ -132,8 +132,7 @@ public class Account extends AbstractEntity {
STREAM_ERROR, STREAM_ERROR,
POLICY_VIOLATION, POLICY_VIOLATION,
PAYMENT_REQUIRED, PAYMENT_REQUIRED,
MISSING_INTERNET_PERMISSION(false), MISSING_INTERNET_PERMISSION(false);
NETWORK_IS_UNREACHABLE(false);
private final boolean isError; private final boolean isError;
private final boolean attemptReconnect; private final boolean attemptReconnect;
@ -211,8 +210,6 @@ public class Account extends AbstractEntity {
return R.string.payment_required; return R.string.payment_required;
case MISSING_INTERNET_PERMISSION: case MISSING_INTERNET_PERMISSION:
return R.string.missing_internet_permission; return R.string.missing_internet_permission;
case NETWORK_IS_UNREACHABLE:
return R.string.network_is_unreachable;
default: default:
return R.string.account_status_unknown; return R.string.account_status_unknown;
} }

View File

@ -3846,7 +3846,7 @@ public class XmppConnectionService extends Service {
ServiceDiscoveryResult discoveryResult = new ServiceDiscoveryResult(response); ServiceDiscoveryResult discoveryResult = new ServiceDiscoveryResult(response);
if (presence.getVer().equals(discoveryResult.getVer())) { if (presence.getVer().equals(discoveryResult.getVer())) {
databaseBackend.insertDiscoveryResult(discoveryResult); databaseBackend.insertDiscoveryResult(discoveryResult);
injectServiceDiscorveryResult(a.getRoster(), presence.getHash(), presence.getVer(), discoveryResult); injectServiceDiscoveryResult(a.getRoster(), presence.getHash(), presence.getVer(), discoveryResult);
} else { } else {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + discoveryResult.getVer()); Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + discoveryResult.getVer());
} }
@ -3857,7 +3857,7 @@ public class XmppConnectionService extends Service {
} }
} }
private void injectServiceDiscorveryResult(Roster roster, String hash, String ver, ServiceDiscoveryResult disco) { private void injectServiceDiscoveryResult(Roster roster, String hash, String ver, ServiceDiscoveryResult disco) {
for (Contact contact : roster.getContacts()) { for (Contact contact : roster.getContacts()) {
for (Presence presence : contact.getPresences().getPresences().values()) { for (Presence presence : contact.getPresences().getPresences().values()) {
if (hash.equals(presence.getHash()) && ver.equals(presence.getVer())) { if (hash.equals(presence.getHash()) && ver.equals(presence.getVer())) {

View File

@ -6,14 +6,15 @@ import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import de.measite.minidns.AbstractDNSClient;
import de.measite.minidns.DNSClient; import de.measite.minidns.DNSClient;
import de.measite.minidns.DNSName; import de.measite.minidns.DNSName;
import de.measite.minidns.Question; import de.measite.minidns.Question;
@ -23,309 +24,347 @@ import de.measite.minidns.dnsserverlookup.AndroidUsingExec;
import de.measite.minidns.hla.DnssecResolverApi; import de.measite.minidns.hla.DnssecResolverApi;
import de.measite.minidns.hla.ResolverApi; import de.measite.minidns.hla.ResolverApi;
import de.measite.minidns.hla.ResolverResult; import de.measite.minidns.hla.ResolverResult;
import de.measite.minidns.iterative.ReliableDNSClient;
import de.measite.minidns.record.A; import de.measite.minidns.record.A;
import de.measite.minidns.record.AAAA; import de.measite.minidns.record.AAAA;
import de.measite.minidns.record.CNAME; import de.measite.minidns.record.CNAME;
import de.measite.minidns.record.Data; import de.measite.minidns.record.Data;
import de.measite.minidns.record.InternetAddressRR; import de.measite.minidns.record.InternetAddressRR;
import de.measite.minidns.record.SRV; import de.measite.minidns.record.SRV;
import de.measite.minidns.util.MultipleIoException;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
public class Resolver { public class Resolver {
private static final String DIRECT_TLS_SERVICE = "_xmpps-client"; private static final String DIRECT_TLS_SERVICE = "_xmpps-client";
private static final String STARTTLS_SERICE = "_xmpp-client"; private static final String STARTTLS_SERICE = "_xmpp-client";
private static final String NETWORK_IS_UNREACHABLE = "Network is unreachable"; private static XmppConnectionService SERVICE = null;
private static XmppConnectionService SERVICE = null;
public static void init(XmppConnectionService service) { public static void init(XmppConnectionService service) {
Resolver.SERVICE = service; Resolver.SERVICE = service;
DNSClient.removeDNSServerLookupMechanism(AndroidUsingExec.INSTANCE); DNSClient.removeDNSServerLookupMechanism(AndroidUsingExec.INSTANCE);
DNSClient.addDnsServerLookupMechanism(AndroidUsingExecLowPriority.INSTANCE); DNSClient.addDnsServerLookupMechanism(AndroidUsingExecLowPriority.INSTANCE);
DNSClient.addDnsServerLookupMechanism(new AndroidUsingLinkProperties(service)); DNSClient.addDnsServerLookupMechanism(new AndroidUsingLinkProperties(service));
} final AbstractDNSClient client = ResolverApi.INSTANCE.getClient();
if (client instanceof ReliableDNSClient) {
disableHardcodedDnsServers((ReliableDNSClient) client);
}
}
public static List<Result> resolve(String domain) throws NetworkIsUnreachableException { private static void disableHardcodedDnsServers(ReliableDNSClient reliableDNSClient) {
List<Result> results = new ArrayList<>(); try {
HashSet<String> messages = new HashSet<>(); final Field dnsClientField = ReliableDNSClient.class.getDeclaredField("dnsClient");
try { dnsClientField.setAccessible(true);
results.addAll(resolveSrv(domain, true)); final DNSClient dnsClient = (DNSClient) dnsClientField.get(reliableDNSClient);
} catch (MultipleIoException e) { dnsClient.getDataSource().setTimeout(3000);
messages.addAll(extractMessages(e)); final Field useHardcodedDnsServers = DNSClient.class.getDeclaredField("useHardcodedDnsServers");
} catch (Throwable throwable) { useHardcodedDnsServers.setAccessible(true);
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (direct TLS)", throwable); useHardcodedDnsServers.setBoolean(dnsClient, false);
} } catch (NoSuchFieldException | IllegalAccessException e) {
try { Log.e(Config.LOGTAG, "Unable to disable hardcoded DNS servers", e);
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);
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": " + results.toString());
return results;
}
private static HashSet<String> extractMessages(MultipleIoException e) { public static List<Result> resolve(String domain) {
HashSet<String> messages = new HashSet<>(); final List<Result> results = new ArrayList<>();
for (Exception inner : e.getExceptions()) { final List<Result> fallbackResults = new ArrayList<>();
if (inner instanceof MultipleIoException) { Thread[] threads = new Thread[3];
messages.addAll(extractMessages((MultipleIoException) inner)); threads[0] = new Thread(() -> {
} else { try {
messages.add(inner.getMessage()); final List<Result> list = resolveSrv(domain, true);
} synchronized (results) {
} results.addAll(list);
return messages; }
} } catch (Throwable throwable) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (direct TLS)", throwable);
}
});
threads[1] = new Thread(() -> {
try {
final List<Result> list = resolveSrv(domain, false);
synchronized (results) {
results.addAll(list);
}
} catch (Throwable throwable) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving SRV record (STARTTLS)", throwable);
}
});
threads[2] = new Thread(() -> {
List<Result> list = resolveNoSrvRecords(DNSName.from(domain), true);
synchronized (fallbackResults) {
fallbackResults.addAll(list);
}
});
for (Thread thread : threads) {
thread.start();
}
try {
threads[0].join();
threads[1].join();
if (results.size() > 0) {
threads[2].interrupt();
Collections.sort(results);
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": " + results.toString());
return results;
} else {
threads[2].join();
Collections.sort(fallbackResults);
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": " + fallbackResults.toString());
return fallbackResults;
}
} catch (InterruptedException e) {
return results;
}
}
private static List<Result> resolveSrv(String domain, final boolean directTls) throws IOException { private static List<Result> resolveSrv(String domain, final boolean directTls) throws IOException {
if (Thread.currentThread().isInterrupted()) { DNSName dnsName = DNSName.from((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE) + "._tcp." + domain);
return Collections.emptyList(); ResolverResult<SRV> result = resolveWithFallback(dnsName, SRV.class);
} final List<Result> results = new ArrayList<>();
DNSName dnsName = DNSName.from((directTls ? DIRECT_TLS_SERVICE : STARTTLS_SERICE) + "._tcp." + domain); final List<Thread> threads = new ArrayList<>();
ResolverResult<SRV> result = resolveWithFallback(dnsName, SRV.class); for (SRV record : result.getAnswersOrEmptySet()) {
List<Result> results = new ArrayList<>(); if (record.name.length() == 0 && record.priority == 0) {
for (SRV record : result.getAnswersOrEmptySet()) { continue;
if (record.name.length() == 0 && record.priority == 0) { }
continue; threads.add(new Thread(() -> {
} final List<Result> ipv4s = resolveIp(record, A.class, result.isAuthenticData(), directTls);
final boolean addedIPv4 = results.addAll(resolveIp(record, A.class, result.isAuthenticData(), directTls)); if (ipv4s.size() == 0) {
results.addAll(resolveIp(record, AAAA.class, result.isAuthenticData(), directTls)); Result resolverResult = Result.fromRecord(record, directTls);
if (!addedIPv4 && !Thread.currentThread().isInterrupted()) { resolverResult.authenticated = resolverResult.isAuthenticated();
Result resolverResult = Result.fromRecord(record, directTls); ipv4s.add(resolverResult);
resolverResult.authenticated = resolverResult.isAuthenticated(); }
results.add(resolverResult); synchronized (results) {
} results.addAll(ipv4s);
} }
return results;
}
private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) { }));
if (Thread.currentThread().isInterrupted()) { threads.add(new Thread(() -> {
return Collections.emptyList(); final List<Result> ipv6s = resolveIp(record, AAAA.class, result.isAuthenticData(), directTls);
} synchronized (results) {
List<Result> list = new ArrayList<>(); results.addAll(ipv6s);
try { }
ResolverResult<D> results = resolveWithFallback(srv.name, type, authenticated); }));
for (D record : results.getAnswersOrEmptySet()) { }
Result resolverResult = Result.fromRecord(srv, directTls); for (Thread thread : threads) {
resolverResult.authenticated = results.isAuthenticData() && authenticated; thread.start();
resolverResult.ip = record.getInetAddress(); }
list.add(resolverResult); for (Thread thread : threads) {
} try {
} catch (Throwable t) { thread.join();
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " " + t.getMessage()); } catch (InterruptedException e) {
} return Collections.emptyList();
return list; }
} }
return results;
}
private static List<Result> resolveNoSrvRecords(DNSName dnsName, boolean withCnames) { private static <D extends InternetAddressRR> List<Result> resolveIp(SRV srv, Class<D> type, boolean authenticated, boolean directTls) {
List<Result> results = new ArrayList<>(); List<Result> list = new ArrayList<>();
try { try {
for (A a : resolveWithFallback(dnsName, A.class, false).getAnswersOrEmptySet()) { ResolverResult<D> results = resolveWithFallback(srv.name, type, authenticated);
results.add(Result.createDefault(dnsName, a.getInetAddress())); for (D record : results.getAnswersOrEmptySet()) {
} Result resolverResult = Result.fromRecord(srv, directTls);
for (AAAA aaaa : resolveWithFallback(dnsName, AAAA.class, false).getAnswersOrEmptySet()) { resolverResult.authenticated = results.isAuthenticData() && authenticated;
results.add(Result.createDefault(dnsName, aaaa.getInetAddress())); resolverResult.ip = record.getInetAddress();
} list.add(resolverResult);
if (results.size() == 0 && withCnames) { }
for (CNAME cname : resolveWithFallback(dnsName, CNAME.class, false).getAnswersOrEmptySet()) { } catch (Throwable t) {
results.addAll(resolveNoSrvRecords(cname.name, false)); Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " " + t.getMessage());
} }
} return list;
} catch (Throwable throwable) { }
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving fallback records", throwable);
}
results.add(Result.createDefault(dnsName));
return results;
}
private static <D extends Data> ResolverResult<D> resolveWithFallback(DNSName dnsName, Class<D> type) throws IOException { private static List<Result> resolveNoSrvRecords(DNSName dnsName, boolean withCnames) {
return resolveWithFallback(dnsName, type, validateHostname()); List<Result> results = new ArrayList<>();
} try {
for (A a : resolveWithFallback(dnsName, A.class, false).getAnswersOrEmptySet()) {
results.add(Result.createDefault(dnsName, a.getInetAddress()));
}
for (AAAA aaaa : resolveWithFallback(dnsName, AAAA.class, false).getAnswersOrEmptySet()) {
results.add(Result.createDefault(dnsName, aaaa.getInetAddress()));
}
if (results.size() == 0 && withCnames) {
for (CNAME cname : resolveWithFallback(dnsName, CNAME.class, false).getAnswersOrEmptySet()) {
results.addAll(resolveNoSrvRecords(cname.name, false));
}
}
} catch (Throwable throwable) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + "error resolving fallback records", throwable);
}
results.add(Result.createDefault(dnsName));
return results;
}
private static <D extends Data> ResolverResult<D> resolveWithFallback(DNSName dnsName, Class<D> type, boolean validateHostname) throws IOException { private static <D extends Data> ResolverResult<D> resolveWithFallback(DNSName dnsName, Class<D> type) throws IOException {
final Question question = new Question(dnsName, Record.TYPE.getType(type)); return resolveWithFallback(dnsName, type, validateHostname());
if (!validateHostname) { }
return ResolverApi.INSTANCE.resolve(question);
}
try {
return DnssecResolverApi.INSTANCE.resolveDnssecReliable(question);
} catch (DNSSECResultNotAuthenticException e) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", e);
} catch (IOException e) {
throw e;
} catch (Throwable throwable) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", throwable);
}
return ResolverApi.INSTANCE.resolve(question);
}
private static boolean validateHostname() { private static <D extends Data> ResolverResult<D> resolveWithFallback(DNSName dnsName, Class<D> type, boolean validateHostname) throws IOException {
return SERVICE != null && SERVICE.getBooleanPreference("validate_hostname", R.bool.validate_hostname); final Question question = new Question(dnsName, Record.TYPE.getType(type));
} if (!validateHostname) {
return ResolverApi.INSTANCE.resolve(question);
}
try {
return DnssecResolverApi.INSTANCE.resolveDnssecReliable(question);
} catch (DNSSECResultNotAuthenticException e) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", e);
} catch (IOException e) {
throw e;
} catch (Throwable throwable) {
Log.d(Config.LOGTAG, Resolver.class.getSimpleName() + ": error resolving " + type.getSimpleName() + " with DNSSEC. Trying DNS instead.", throwable);
}
return ResolverApi.INSTANCE.resolve(question);
}
public static class Result implements Comparable<Result> { private static boolean validateHostname() {
@Override return SERVICE != null && SERVICE.getBooleanPreference("validate_hostname", R.bool.validate_hostname);
public boolean equals(Object o) { }
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Result result = (Result) o; public static class Result implements Comparable<Result> {
public static final String DOMAIN = "domain";
public static final String IP = "ip";
public static final String HOSTNAME = "hostname";
public static final String PORT = "port";
public static final String PRIORITY = "priority";
public static final String DIRECT_TLS = "directTls";
public static final String AUTHENTICATED = "authenticated";
private InetAddress ip;
private DNSName hostname;
private int port = 5222;
private boolean directTls = false;
private boolean authenticated = false;
private int priority;
if (port != result.port) return false; static Result fromRecord(SRV srv, boolean directTls) {
if (directTls != result.directTls) return false; Result result = new Result();
if (authenticated != result.authenticated) return false; result.port = srv.port;
if (priority != result.priority) return false; result.hostname = srv.name;
if (ip != null ? !ip.equals(result.ip) : result.ip != null) return false; result.directTls = directTls;
return hostname != null ? hostname.equals(result.hostname) : result.hostname == null; result.priority = srv.priority;
} return result;
}
@Override static Result createDefault(DNSName hostname, InetAddress ip) {
public int hashCode() { Result result = new Result();
int result = ip != null ? ip.hashCode() : 0; result.port = 5222;
result = 31 * result + (hostname != null ? hostname.hashCode() : 0); result.hostname = hostname;
result = 31 * result + port; result.ip = ip;
result = 31 * result + (directTls ? 1 : 0); return result;
result = 31 * result + (authenticated ? 1 : 0); }
result = 31 * result + priority;
return result;
}
public static final String DOMAIN = "domain"; static Result createDefault(DNSName hostname) {
return createDefault(hostname, null);
}
public static final String IP = "ip"; public static Result fromCursor(Cursor cursor) {
public static final String HOSTNAME = "hostname"; final Result result = new Result();
public static final String PORT = "port"; try {
public static final String PRIORITY = "priority"; result.ip = InetAddress.getByAddress(cursor.getBlob(cursor.getColumnIndex(IP)));
public static final String DIRECT_TLS = "directTls"; } catch (UnknownHostException e) {
public static final String AUTHENTICATED = "authenticated"; result.ip = null;
}
result.hostname = DNSName.from(cursor.getString(cursor.getColumnIndex(HOSTNAME)));
result.port = cursor.getInt(cursor.getColumnIndex(PORT));
result.priority = cursor.getInt(cursor.getColumnIndex(PRIORITY));
result.authenticated = cursor.getInt(cursor.getColumnIndex(AUTHENTICATED)) > 0;
result.directTls = cursor.getInt(cursor.getColumnIndex(DIRECT_TLS)) > 0;
return result;
}
private InetAddress ip; @Override
private DNSName hostname; public boolean equals(Object o) {
private int port = 5222; if (this == o) return true;
private boolean directTls = false; if (o == null || getClass() != o.getClass()) return false;
private boolean authenticated = false;
private int priority;
public InetAddress getIp() { Result result = (Result) o;
return ip;
}
public int getPort() { if (port != result.port) return false;
return port; if (directTls != result.directTls) return false;
} if (authenticated != result.authenticated) return false;
if (priority != result.priority) return false;
if (ip != null ? !ip.equals(result.ip) : result.ip != null) return false;
return hostname != null ? hostname.equals(result.hostname) : result.hostname == null;
}
public DNSName getHostname() { @Override
return hostname; public int hashCode() {
} int result = ip != null ? ip.hashCode() : 0;
result = 31 * result + (hostname != null ? hostname.hashCode() : 0);
result = 31 * result + port;
result = 31 * result + (directTls ? 1 : 0);
result = 31 * result + (authenticated ? 1 : 0);
result = 31 * result + priority;
return result;
}
public boolean isDirectTls() { public InetAddress getIp() {
return directTls; return ip;
} }
public boolean isAuthenticated() { public int getPort() {
return authenticated; return port;
} }
@Override public DNSName getHostname() {
public String toString() { return hostname;
return "Result{" + }
"ip='" + (ip == null ? null : ip.getHostAddress()) + '\'' +
", hostame='" + hostname.toString() + '\'' +
", port=" + port +
", directTls=" + directTls +
", authenticated=" + authenticated +
", priority=" + priority +
'}';
}
@Override public boolean isDirectTls() {
public int compareTo(@NonNull Result result) { return directTls;
if (result.priority == priority) { }
if (directTls == result.directTls) {
if (ip == null && result.ip == null) {
return 0;
} else if (ip != null && result.ip != null) {
if (ip instanceof Inet4Address && result.ip instanceof Inet4Address) {
return 0;
} else {
return ip instanceof Inet4Address ? -1 : 1;
}
} else {
return ip != null ? -1 : 1;
}
} else {
return directTls ? -1 : 1;
}
} else {
return priority - result.priority;
}
}
public static Result fromRecord(SRV srv, boolean directTls) { public boolean isAuthenticated() {
Result result = new Result(); return authenticated;
result.port = srv.port; }
result.hostname = srv.name;
result.directTls = directTls;
result.priority = srv.priority;
return result;
}
public static Result createDefault(DNSName hostname, InetAddress ip) { @Override
Result result = new Result(); public String toString() {
result.port = 5222; return "Result{" +
result.hostname = hostname; "ip='" + (ip == null ? null : ip.getHostAddress()) + '\'' +
result.ip = ip; ", hostame='" + hostname.toString() + '\'' +
return result; ", port=" + port +
} ", directTls=" + directTls +
", authenticated=" + authenticated +
", priority=" + priority +
'}';
}
public static Result createDefault(DNSName hostname) { @Override
return createDefault(hostname, null); public int compareTo(@NonNull Result result) {
} if (result.priority == priority) {
if (directTls == result.directTls) {
if (ip == null && result.ip == null) {
return 0;
} else if (ip != null && result.ip != null) {
if (ip instanceof Inet4Address && result.ip instanceof Inet4Address) {
return 0;
} else {
return ip instanceof Inet4Address ? -1 : 1;
}
} else {
return ip != null ? -1 : 1;
}
} else {
return directTls ? -1 : 1;
}
} else {
return priority - result.priority;
}
}
public static Result fromCursor(Cursor cursor) { public ContentValues toContentValues() {
final Result result = new Result(); final ContentValues contentValues = new ContentValues();
try { contentValues.put(IP, ip == null ? null : ip.getAddress());
result.ip = InetAddress.getByAddress(cursor.getBlob(cursor.getColumnIndex(IP))); contentValues.put(HOSTNAME, hostname.toString());
} catch (UnknownHostException e) { contentValues.put(PORT, port);
result.ip = null; contentValues.put(PRIORITY, priority);
} contentValues.put(DIRECT_TLS, directTls ? 1 : 0);
result.hostname = DNSName.from(cursor.getString(cursor.getColumnIndex(HOSTNAME))); contentValues.put(AUTHENTICATED, authenticated ? 1 : 0);
result.port = cursor.getInt(cursor.getColumnIndex(PORT)); return contentValues;
result.priority = cursor.getInt(cursor.getColumnIndex(PRIORITY)); }
result.authenticated = cursor.getInt(cursor.getColumnIndex(AUTHENTICATED)) > 0; }
result.directTls = cursor.getInt(cursor.getColumnIndex(DIRECT_TLS)) > 0;
return result;
}
public ContentValues toContentValues() {
final ContentValues contentValues = new ContentValues();
contentValues.put(IP, ip == null ? null : ip.getAddress());
contentValues.put(HOSTNAME, hostname.toString());
contentValues.put(PORT, port);
contentValues.put(PRIORITY, priority);
contentValues.put(DIRECT_TLS, directTls ? 1 : 0);
contentValues.put(AUTHENTICATED, authenticated ? 1 : 0);
return contentValues;
}
}
public static class NetworkIsUnreachableException extends Exception {
}
} }

View File

@ -415,8 +415,6 @@ public class XmppConnection implements Runnable {
this.changeStatus(Account.State.MISSING_INTERNET_PERMISSION); this.changeStatus(Account.State.MISSING_INTERNET_PERMISSION);
} catch (final StateChangingException e) { } catch (final StateChangingException e) {
this.changeStatus(e.state); this.changeStatus(e.state);
} catch (final Resolver.NetworkIsUnreachableException e) {
this.changeStatus(Account.State.NETWORK_IS_UNREACHABLE);
} catch (final UnknownHostException | ConnectException e) { } catch (final UnknownHostException | ConnectException e) {
this.changeStatus(Account.State.SERVER_NOT_FOUND); this.changeStatus(Account.State.SERVER_NOT_FOUND);
} catch (final SocksSocketFactory.SocksProxyNotFoundException e) { } catch (final SocksSocketFactory.SocksProxyNotFoundException e) {

View File

@ -648,7 +648,6 @@
<string name="yesterday">Yesterday</string> <string name="yesterday">Yesterday</string>
<string name="pref_validate_hostname">Validate hostname with DNSSEC</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="pref_validate_hostname_summary">Server certificates that contain the validated hostname are considered verified</string>
<string name="network_is_unreachable">Network is unreachable</string>
<string name="certificate_does_not_contain_jid">Certificate does not contain a Jabber ID</string> <string name="certificate_does_not_contain_jid">Certificate does not contain a Jabber ID</string>
<string name="server_info_partial">partial</string> <string name="server_info_partial">partial</string>
<string name="attach_record_video">Record video</string> <string name="attach_record_video">Record video</string>