add error state for unavailable tor network

This commit is contained in:
Daniel Gultsch 2015-11-30 16:01:48 +01:00
parent b4a259837e
commit 2225b0b6d5
4 changed files with 15 additions and 14 deletions

View file

@ -83,7 +83,7 @@ public class Account extends AbstractEntity {
REGISTRATION_NOT_SUPPORTED(true), REGISTRATION_NOT_SUPPORTED(true),
SECURITY_ERROR(true), SECURITY_ERROR(true),
INCOMPATIBLE_SERVER(true), INCOMPATIBLE_SERVER(true),
DNS_TIMEOUT(true); TOR_NOT_AVAILABLE(true);
private final boolean isError; private final boolean isError;
@ -127,8 +127,8 @@ public class Account extends AbstractEntity {
return R.string.account_status_security_error; return R.string.account_status_security_error;
case INCOMPATIBLE_SERVER: case INCOMPATIBLE_SERVER:
return R.string.account_status_incompatible_server; return R.string.account_status_incompatible_server;
case DNS_TIMEOUT: case TOR_NOT_AVAILABLE:
return R.string.account_status_dns_timeout; return R.string.account_status_tor_unavailable;
default: default:
return R.string.account_status_unknown; return R.string.account_status_unknown;
} }

View file

@ -1,14 +1,11 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -37,7 +34,11 @@ public class SocksSocketFactory {
public static Socket createSocket(InetSocketAddress address, String destination, int port) throws IOException { public static Socket createSocket(InetSocketAddress address, String destination, int port) throws IOException {
Socket socket = new Socket(); Socket socket = new Socket();
socket.connect(address, Config.CONNECT_TIMEOUT * 1000); try {
socket.connect(address, Config.CONNECT_TIMEOUT * 1000);
} catch (IOException e) {
throw new SocksProxyNotFoundException();
}
createSocksConnection(socket, destination, port); createSocksConnection(socket, destination, port);
return socket; return socket;
} }
@ -49,4 +50,8 @@ public class SocksSocketFactory {
static class SocksConnectionException extends IOException { static class SocksConnectionException extends IOException {
} }
public static class SocksProxyNotFoundException extends IOException {
}
} }

View file

@ -29,7 +29,6 @@ import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.URL; import java.net.URL;
import java.nio.ByteBuffer;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.Principal; import java.security.Principal;
@ -318,8 +317,8 @@ public class XmppConnection implements Runnable {
this.changeStatus(Account.State.UNAUTHORIZED); this.changeStatus(Account.State.UNAUTHORIZED);
} 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 DnsTimeoutException e) { } catch (final SocksSocketFactory.SocksProxyNotFoundException e) {
this.changeStatus(Account.State.DNS_TIMEOUT); this.changeStatus(Account.State.TOR_NOT_AVAILABLE);
} catch (final IOException | XmlPullParserException | NoSuchAlgorithmException e) { } catch (final IOException | XmlPullParserException | NoSuchAlgorithmException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage());
this.changeStatus(Account.State.OFFLINE); this.changeStatus(Account.State.OFFLINE);
@ -1327,9 +1326,6 @@ public class XmppConnection implements Runnable {
} }
private class DnsTimeoutException extends IOException {
}
public enum Identity { public enum Identity {
FACEBOOK, FACEBOOK,
SLACK, SLACK,

View file

@ -521,7 +521,7 @@
<string name="download_failed_could_not_connect">Download failed: Could not connect to host</string> <string name="download_failed_could_not_connect">Download failed: Could not connect to host</string>
<string name="pref_use_white_background">Use white background</string> <string name="pref_use_white_background">Use white background</string>
<string name="pref_use_white_background_summary">Show received messages as black text on a white background</string> <string name="pref_use_white_background_summary">Show received messages as black text on a white background</string>
<string name="account_status_dns_timeout">Timeout in DNS</string> <string name="account_status_tor_unavailable">TOR network unavailable</string>
<string name="server_info_broken">Broken</string> <string name="server_info_broken">Broken</string>
<string name="pref_presence_settings">Presence settings</string> <string name="pref_presence_settings">Presence settings</string>
<string name="pref_away_when_screen_off">Away when screen is off</string> <string name="pref_away_when_screen_off">Away when screen is off</string>