diff options
author | cyberta <cyberta@riseup.net> | 2022-12-12 15:53:21 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2022-12-12 15:53:21 +0000 |
commit | 62d9effae8fe5983056a7b225535ec763f03d87b (patch) | |
tree | 19dd64806e3c85422359f5ae99e1c836e8c18048 /app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java | |
parent | 934a89e2218acb5e875020871e243e633dcf8464 (diff) | |
parent | 6667fc2999b97b498cf6ed5b9d88d913ab00d4c3 (diff) |
Merge branch 'ampcache' into 'master'
boot strap improvements
See merge request leap/bitmask_android!228
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java b/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java index 7eee1a9d..36ab66bf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java +++ b/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java @@ -15,6 +15,14 @@ package se.leap.bitmaskclient.tor; * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.BROKER_REPLIED_SUCCESS; +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.NEGOTIATING_RENDEZVOUS_VIA_AMP_CACHE; +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.NEGOTIATING_RENDEZVOUS_VIA_HTTP; +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.RETRY_AMP_CACHE_RENDEZVOUS; +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.RETRY_HTTP_RENDEZVOUS; +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.STARTED; +import static se.leap.bitmaskclient.tor.TorStatusObservable.SnowflakeStatus.STOPPED; + import android.content.Context; import android.util.Log; @@ -46,8 +54,13 @@ public class TorStatusObservable extends Observable { } public enum SnowflakeStatus { - ON, - OFF + STARTED, + NEGOTIATING_RENDEZVOUS_VIA_HTTP, + NEGOTIATING_RENDEZVOUS_VIA_AMP_CACHE, + RETRY_HTTP_RENDEZVOUS, + RETRY_AMP_CACHE_RENDEZVOUS, + BROKER_REPLIED_SUCCESS, + STOPPED } // indicates if the user has cancelled Tor, the actual TorStatus can still be different until @@ -60,17 +73,23 @@ public class TorStatusObservable extends Observable { public static final String SNOWFLAKE_STOPPED_COLLECTING = "---- SnowflakeConn: end collecting snowflakes ---"; public static final String SNOWFLAKE_COPY_LOOP_STOPPED = "copy loop ended"; public static final String SNOWFLAKE_SOCKS_ERROR = "SOCKS accept error"; + public static final String SNOWFLAKE_NEGOTIATING_HTTP = "Negotiating via HTTP rendezvous..."; + public static final String SNOWFLAKE_NEGOTIATING_AMP_CACHE = "Negotiating via AMP cache rendezvous..."; + public static final String SNOWFLAKE_CONNECTION_CLOSING = "WebRTC: Closing"; + public static final String SNOWFLAKE_HTTP_RESPONSE_200 = "HTTP rendezvous response: 200"; + public static final String SNOWFLAKE_AMP_CACHE_RESPONSE_200 = "AMP cache rendezvous response: 200"; private static TorStatusObservable instance; private TorStatus status = TorStatus.OFF; - private SnowflakeStatus snowflakeStatus = SnowflakeStatus.OFF; + private SnowflakeStatus snowflakeStatus = STOPPED; private final TorNotificationManager torNotificationManager; private String lastError; private String lastTorLog = ""; private String lastSnowflakeLog = ""; private int port = -1; private int bootstrapPercent = -1; - private Vector<String> lastLogs = new Vector<>(100); + private int retrySnowflakeRendezVous = 0; + private final Vector<String> lastLogs = new Vector<>(100); private TorStatusObservable() { torNotificationManager = new TorNotificationManager(); @@ -128,15 +147,38 @@ public class TorStatusObservable extends Observable { getInstance().torNotificationManager.buildTorNotification(context, getStringForCurrentStatus(context), getNotificationLog(), getBootstrapProgress()); } //TODO: implement proper state signalling in IPtProxy - if (SNOWFLAKE_STARTED.equals(message.trim())) { - Log.d(TAG, "snowflakeStatus ON"); - getInstance().snowflakeStatus = SnowflakeStatus.ON; - } else if (SNOWFLAKE_STOPPED_COLLECTING.equals(message.trim()) || - SNOWFLAKE_COPY_LOOP_STOPPED.equals(message.trim()) || - message.trim().contains(SNOWFLAKE_SOCKS_ERROR)) { - Log.d(TAG, "snowflakeStatus OFF"); - getInstance().snowflakeStatus = SnowflakeStatus.OFF; + message = message.trim(); + if (SNOWFLAKE_STARTED.equals(message)) { + getInstance().snowflakeStatus = STARTED; + } else if (SNOWFLAKE_NEGOTIATING_HTTP.equals(message)) { + getInstance().snowflakeStatus = NEGOTIATING_RENDEZVOUS_VIA_HTTP; + } else if (SNOWFLAKE_NEGOTIATING_AMP_CACHE.equals(message)) { + getInstance().snowflakeStatus = NEGOTIATING_RENDEZVOUS_VIA_AMP_CACHE; + } else if (SNOWFLAKE_STOPPED_COLLECTING.equals(message) || + SNOWFLAKE_COPY_LOOP_STOPPED.equals(message) || + message.contains(SNOWFLAKE_SOCKS_ERROR)) { + getInstance().snowflakeStatus = STOPPED; + } else if (SNOWFLAKE_CONNECTION_CLOSING.equals(message)) { + if (getInstance().snowflakeStatus == NEGOTIATING_RENDEZVOUS_VIA_HTTP) { + if (getInstance().retrySnowflakeRendezVous < 3) { + getInstance().retrySnowflakeRendezVous += 1; + } else { + getInstance().retrySnowflakeRendezVous = 0; + getInstance().snowflakeStatus = RETRY_AMP_CACHE_RENDEZVOUS; + } + } else if (getInstance().snowflakeStatus == NEGOTIATING_RENDEZVOUS_VIA_AMP_CACHE) { + if (getInstance().retrySnowflakeRendezVous < 3) { + getInstance().retrySnowflakeRendezVous += 1; + } else { + getInstance().retrySnowflakeRendezVous = 0; + getInstance().snowflakeStatus = RETRY_HTTP_RENDEZVOUS; + } + } + } else if (SNOWFLAKE_AMP_CACHE_RESPONSE_200.equals(message) || SNOWFLAKE_HTTP_RESPONSE_200.equals(message)) { + getInstance().snowflakeStatus = BROKER_REPLIED_SUCCESS; + getInstance().retrySnowflakeRendezVous = 0; } + Log.d(TAG, "snowflake status " + getInstance().snowflakeStatus); instance.setChanged(); instance.notifyObservers(); } |