From 1d8fa7e99dc1304ece611bff99d12f52981ab1f9 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 25 Jun 2019 21:17:32 +0200 Subject: Revert "Networkstack - let OS decide IPv4 or IPv6 (#267)" This reverts commit e6a15597904019f68c02e6fd8f61fb6de0b13324. If there is IPv6 available but the server doesn't listen to it, the connection will not be established --- .../de/pixart/messenger/xmpp/XmppConnection.java | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/main/java/de/pixart/messenger/xmpp/XmppConnection.java') diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 9a72203b7..3a7e41c9a 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -320,6 +320,16 @@ public class XmppConnection implements Runnable { Log.e(Config.LOGTAG, account.getJid().asBareJid() + ": Resolver results were empty"); return; } + final Resolver.Result storedBackupResult; + if (hardcoded) { + storedBackupResult = null; + } else { + storedBackupResult = mXmppConnectionService.databaseBackend.findResolverResult(domain); + if (storedBackupResult != null && !results.contains(storedBackupResult)) { + results.add(storedBackupResult); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": loaded backup resolver result from db: " + storedBackupResult); + } + } for (Iterator iterator = results.iterator(); iterator.hasNext(); ) { final Resolver.Result result = iterator.next(); if (Thread.currentThread().isInterrupted()) { @@ -331,10 +341,18 @@ public class XmppConnection implements Runnable { features.encryptionEnabled = result.isDirectTls(); verifiedHostname = result.isAuthenticated() ? result.getHostname().toString() : null; Log.d(Config.LOGTAG, "verified hostname " + verifiedHostname); - final InetSocketAddress addr = new InetSocketAddress(IDN.toASCII(result.getHostname().toString()), result.getPort()); - Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() - + ": using values from resolver " - + result.getHostname().toString() + ":" + result.getPort() + " tls: " + features.encryptionEnabled); + final InetSocketAddress addr; + if (result.getIp() != null) { + addr = new InetSocketAddress(result.getIp(), result.getPort()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + + ": using values from resolver " + (result.getHostname() == null ? "" : result.getHostname().toString() + + "/") + result.getIp().getHostAddress() + ":" + result.getPort() + " tls: " + features.encryptionEnabled); + } else { + addr = new InetSocketAddress(IDN.toASCII(result.getHostname().toString()), result.getPort()); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + + ": using values from resolver " + + result.getHostname().toString() + ":" + result.getPort() + " tls: " + features.encryptionEnabled); + } if (!features.encryptionEnabled) { localSocket = new Socket(); @@ -362,6 +380,9 @@ public class XmppConnection implements Runnable { localSocket.setSoTimeout(Config.SOCKET_TIMEOUT * 1000); if (startXmpp(localSocket)) { localSocket.setSoTimeout(0); //reset to 0; once the connection is established we don’t want this + if (!hardcoded && !result.equals(storedBackupResult)) { + mXmppConnectionService.databaseBackend.saveResolverResult(domain, result); + } break; // successfully connected to server that speaks xmpp } else { FileBackend.close(localSocket); @@ -1969,4 +1990,4 @@ public class XmppConnection implements Runnable { return hasDiscoFeature(account.getJid().asBareJid(), Namespace.STANZA_IDS); } } -} +} \ No newline at end of file -- cgit v1.2.3