[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] improve stop/start logic for tor and snowflake



commit 806b7233b2bc54f10e464ba9d0cfbf4621783344
Author: n8fr8 <nathan@xxxxxxxxxxxxxxxxxxxx>
Date:   Fri Jul 2 14:09:51 2021 -0400

    improve stop/start logic for tor and snowflake
---
 .../torproject/android/service/OrbotService.java   | 28 +++++++---------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
index c7d455f7..ca4b538c 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -288,7 +288,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
             //not registered yet
         }
 
-        stopTorAsync();
+
 
         super.onDestroy();
     }
@@ -404,7 +404,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
     /**
      * if someone stops during startup, we may have to wait for the conn port to be setup, so we can properly shutdown tor
      */
-    private synchronized void stopTor() throws Exception {
+    private void stopTor() throws Exception {
 
         if (conn != null) {
             logNotice("Using control port to shutdown Tor");
@@ -695,12 +695,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
     private void startTor() {
         try {
 
-            // STATUS_STARTING is set in onCreate()
-            if (mCurrentStatus.equals(STATUS_STOPPING)) {
-                // these states should probably be handled better
-                sendCallbackLogMessage("Ignoring start request, currently " + mCurrentStatus);
-                return;
-            } else if (mCurrentStatus.equals(STATUS_ON)) {
+            if (torServiceConnection != null && conn != null)
+            {
                 showConnectedToTorNetworkNotification();
                 sendCallbackLogMessage("Ignoring start request, already started.");
                 return;
@@ -708,9 +704,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
             sendCallbackStatus(STATUS_STARTING);
 
-            // make sure there are no stray daemons running
-            stopTor();
-
             showToolbarNotification(getString(R.string.status_starting_up), NOTIFY_ID, R.drawable.ic_stat_tor);
             //sendCallbackLogMessage(getString(R.string.status_starting_up));
             //logNotice(getString(R.string.status_starting_up));
@@ -1554,16 +1547,12 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                             IPtProxy.startObfs4Proxy("DEBUG", false, false);
                         else if (useIPtSnowflakeProxy())
                             startSnowflakeClient();
-                    }
-                    else if (Prefs.beSnowflakeProxy())
-                    {
+                    } else if (Prefs.beSnowflakeProxy()) {
 
                         if (Prefs.limitSnowflakeProxying()
-                        && isChargingAndWifi(OrbotService.this))
-                        {
+                                && isChargingAndWifi(OrbotService.this)) {
                             enableSnowflakeProxy();
-                        }
-                        else
+                        } else
                             enableSnowflakeProxy();
                     }
 
@@ -1585,7 +1574,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                         if (mPortSOCKS != -1 && mPortHTTP != -1)
                             sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans);
                     }
-
+                } else if (action.equals(ACTION_STOP)) {
+                    stopTorAsync();
                 } else if (action.equals(ACTION_START_VPN)) {
                     if (mVpnManager != null && (!mVpnManager.isStarted())) {
                         //start VPN here



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits