aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp/XmppConnection.java')
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java100
1 files changed, 32 insertions, 68 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index b8cddc170..be9fd5a3a 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -317,86 +317,50 @@ public class XmppConnection implements Runnable {
}
} else {
final String domain = account.getJid().getDomain();
- final List<Resolver.Result> results;
+ final Resolver.Result result;
final boolean hardcoded = extended && !account.getHostname().isEmpty();
if (hardcoded) {
- results = Resolver.fromHardCoded(account.getHostname(), account.getPort());
+ result = Resolver.fromHardCoded(account.getHostname(), account.getPort());
} else {
- results = Resolver.resolve(domain);
+ result = Resolver.resolve(domain);
+ }
+ if (result == null) {
+ throw new UnknownHostException();
}
if (Thread.currentThread().isInterrupted()) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": Thread was interrupted");
return;
}
- if (results.size() == 0) {
- 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<Resolver.Result> iterator = results.iterator(); iterator.hasNext(); ) {
- final Resolver.Result result = iterator.next();
- if (Thread.currentThread().isInterrupted()) {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": Thread was interrupted");
- return;
- }
- try {
- // if tls is true, encryption is implied and must not be started
- features.encryptionEnabled = result.isDirectTls();
- verifiedHostname = result.isAuthenticated() ? result.getHostname().toString() : null;
- Log.d(Config.LOGTAG, "verified hostname " + verifiedHostname);
- 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);
- }
+ try {
+ // if tls is true, encryption is implied and must not be started
+ features.encryptionEnabled = result.isDirectTls();
+ verifiedHostname = result.isAuthenticated() ? result.getHostname().toString() : null;
+ Log.d(Config.LOGTAG,"verified hostname " + verifiedHostname);
+ Log.d(Config.LOGTAG, account.getJid().asBareJid().toString()
+ + ": using values from resolver " + result.toString());
- localSocket = new Socket();
- localSocket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
+ localSocket = result.getSocket();
- if (features.encryptionEnabled) {
- localSocket = upgradeSocketToTls(localSocket);
- }
+ if (features.encryptionEnabled) {
+ localSocket = upgradeSocketToTls(localSocket);
+ }
- 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);
- throw new StateChangingException(Account.State.STREAM_OPENING_ERROR);
- }
- } catch (final StateChangingException e) {
- if (!iterator.hasNext()) {
- throw e;
- }
- } catch (InterruptedException e) {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": thread was interrupted before beginning stream");
- return;
- } catch (final Throwable e) {
- Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": " + e.getMessage() + "(" + e.getClass().getName() + ")");
- if (!iterator.hasNext()) {
- throw new UnknownHostException();
- }
+ 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
+ // successfully connected to server that speaks xmpp
+ } else {
+ FileBackend.close(localSocket);
+ throw new StateChangingException(Account.State.STREAM_OPENING_ERROR);
}
+ } catch (final StateChangingException e) {
+ throw e;
+ } catch (InterruptedException e) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": thread was interrupted before beginning stream");
+ return;
+ } catch (final Throwable e) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": " + e.getMessage() + "(" + e.getClass().getName() + ")");
+ throw new UnknownHostException();
}
}
processStream();