[tor-commits] [orbot/master] reset default ports to 9050, 8118 but make them dynamic if needed

n8fr8 at torproject.org n8fr8 at torproject.org
Fri Jul 5 12:40:01 UTC 2019


commit 814fbb31a58bbcfa4863376354366ac4f974fcd0
Author: n8fr8 <nathan at guardianproject.info>
Date:   Tue Jun 18 14:48:59 2019 -0400

    reset default ports to 9050, 8118 but make them dynamic if needed
    - ports will be checked and if not available, increment +1
    - new setting add to allow static setting of http port value
---
 app/src/main/res/values/strings.xml                |  4 ++
 app/src/main/res/xml/preferences.xml               | 10 ++++-
 .../torproject/android/service/OrbotConstants.java | 50 +++++++++++-----------
 .../org/torproject/android/service/TorService.java | 30 ++++++++++---
 .../android/service/TorServiceConstants.java       |  4 +-
 5 files changed, 63 insertions(+), 35 deletions(-)

diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d1b28772..1e0b85c5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -136,6 +136,10 @@
     <string name="pref_socks_summary">Port that Tor offers its SOCKS proxy on (default: 9050 or 0 to disable)</string>
     <string name="pref_socks_dialog">SOCKS Port Config</string>
 
+    <string name="pref_http_title">Tor HTTP</string>
+    <string name="pref_http_summary">Port that Tor offers its HTTP proxy on (default: 8118 or 0 to disable)</string>
+    <string name="pref_http_dialog">HTTP Port Config</string>
+
     <string name="pref_transport_title">Tor TransProxy Port</string>
     <string name="pref_transport_summary">Port that Tor offers its Transparent Proxy on (default: 9040 or 0 to disable)</string>
     <string name="pref_transport_dialog">TransProxy Port Config</string>
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 53aa5ecd..ac596cf3 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -244,7 +244,7 @@
     <PreferenceCategory android:title="Debug">
 
         <EditTextPreference
-            android:defaultValue="auto"
+            android:defaultValue="9050"
             android:dialogTitle="@string/pref_socks_dialog"
             android:inputType="number"
             android:key="pref_socks"
@@ -252,6 +252,14 @@
             android:title="@string/pref_socks_title" />
 
         <EditTextPreference
+            android:defaultValue="8118"
+            android:dialogTitle="@string/pref_http_dialog"
+            android:inputType="number"
+            android:key="pref_http"
+            android:summary="@string/pref_http_summary"
+            android:title="@string/pref_http_title" />
+
+        <EditTextPreference
             android:defaultValue="auto"
             android:dialogTitle="@string/pref_transport_dialog"
             android:inputType="number"
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotConstants.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotConstants.java
index e7f09a77..0ad83f77 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotConstants.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotConstants.java
@@ -5,41 +5,41 @@ package org.torproject.android.service;
 
 public interface OrbotConstants {
 
-	public final static String TAG = "Orbot";
+	String TAG = "Orbot";
 
-	public final static String PREFS_KEY = "OrbotPrefs";
-	public final static String PREFS_KEY_TORIFIED = "PrefTord";
+	String PREFS_KEY = "OrbotPrefs";
+	String PREFS_KEY_TORIFIED = "PrefTord";
 
-	public final static int FILE_WRITE_BUFFER_SIZE = 2048;
+	int FILE_WRITE_BUFFER_SIZE = 2048;
 	
 	//path to check Tor against
-	public final static String URL_TOR_CHECK = "https://check.torproject.org";
+	String URL_TOR_CHECK = "https://check.torproject.org";
 	
-    public final static String URL_TOR_BRIDGES = "https://bridges.torproject.org/bridges?transport=";
-
-	public final static String PREF_BRIDGES_UPDATED = "pref_bridges_enabled";
-	//public final static String PREF_BRIDGES_OBFUSCATED = "pref_bridges_obfuscated";
-    public final static String PREF_OR = "pref_or";
-    public final static String PREF_OR_PORT = "pref_or_port";
-    public final static String PREF_OR_NICKNAME = "pref_or_nickname";
-    public final static String PREF_REACHABLE_ADDRESSES = "pref_reachable_addresses";
-    public final static String PREF_REACHABLE_ADDRESSES_PORTS = "pref_reachable_addresses_ports";
-	public final static  int RESULT_CLOSE_ALL = 0;
+    String URL_TOR_BRIDGES = "https://bridges.torproject.org/bridges?transport=";
+
+	String PREF_BRIDGES_UPDATED = "pref_bridges_enabled";
+	//String PREF_BRIDGES_OBFUSCATED = "pref_bridges_obfuscated";
+    String PREF_OR = "pref_or";
+    String PREF_OR_PORT = "pref_or_port";
+    String PREF_OR_NICKNAME = "pref_or_nickname";
+    String PREF_REACHABLE_ADDRESSES = "pref_reachable_addresses";
+    String PREF_REACHABLE_ADDRESSES_PORTS = "pref_reachable_addresses_ports";
+	 int RESULT_CLOSE_ALL = 0;
 	
-	public final static String PREF_DISABLE_NETWORK = "pref_disable_network";
+	String PREF_DISABLE_NETWORK = "pref_disable_network";
 	
-	public final static String PREF_TOR_SHARED_PREFS = "org.torproject.android_preferences";
+	String PREF_TOR_SHARED_PREFS = "org.torproject.android_preferences";
 	
-	public final static int MAX_LOG_LENGTH = 10000;
-	
-	public final static String PREF_SOCKS = "pref_socks";
+	String PREF_SOCKS = "pref_socks";
+
+	String PREF_HTTP = "pref_http";
 
-	public final static String PREF_ISOLATE_DEST = "pref_isolate_dest";
+	String PREF_ISOLATE_DEST = "pref_isolate_dest";
 
-	public final static String PREF_CONNECTION_PADDING = "pref_connection_padding";
-	public final static String PREF_REDUCED_CONNECTION_PADDING = "pref_reduced_connection_padding";
+	String PREF_CONNECTION_PADDING = "pref_connection_padding";
+	String PREF_REDUCED_CONNECTION_PADDING = "pref_reduced_connection_padding";
 
-	public final static String PREF_PREFER_IPV6 = "pref_prefer_ipv6";
-	public final static String PREF_DISABLE_IPV4 = "pref_disable_ipv4";
+	String PREF_PREFER_IPV6 = "pref_prefer_ipv6";
+	String PREF_DISABLE_IPV4 = "pref_disable_ipv4";
 
 }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
index f4785a0f..cbd06301 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -656,13 +656,20 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
  //       extraLines.append("RunAsDaemon 1").append('\n');
  //       extraLines.append("AvoidDiskWrites 1").append('\n');
         
-         String socksPortPref = prefs.getString(OrbotConstants.PREF_SOCKS,    String.valueOf(TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT));
+         String socksPortPref = prefs.getString(OrbotConstants.PREF_SOCKS, (TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT));
 
          if (socksPortPref.indexOf(':')!=-1)
              socksPortPref = socksPortPref.split(":")[1];
          
         socksPortPref = checkPortOrAuto(socksPortPref);
 
+        String httpPortPref = prefs.getString(OrbotConstants.PREF_HTTP, (TorServiceConstants.HTTP_PROXY_PORT_DEFAULT));
+
+        if (httpPortPref.indexOf(':')!=-1)
+            httpPortPref = httpPortPref.split(":")[1];
+
+        httpPortPref = checkPortOrAuto(httpPortPref);
+
         String isolate = "";
         if(prefs.getBoolean(OrbotConstants.PREF_ISOLATE_DEST, false))
         {
@@ -745,17 +752,26 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 
     }
 
-    private String checkPortOrAuto (String port)
+    private String checkPortOrAuto (String portString)
     {
-        if (!port.equalsIgnoreCase("auto"))
+        if (!portString.equalsIgnoreCase("auto"))
         {
-            boolean isPortUsed = TorServiceUtils.isPortOpen("127.0.0.1",Integer.parseInt(port),500);
+            boolean isPortUsed = true;
+            int port = Integer.parseInt(portString);
+
+            while (isPortUsed) {
+                isPortUsed = TorServiceUtils.isPortOpen("127.0.0.1", port, 500);
 
-            if (isPortUsed) //the specified port is not available, so let Tor find one instead
-                port = "auto";
+                if (isPortUsed) //the specified port is not available, so let Tor find one instead
+                    port++;
+            }
+
+
+            return port + "";
         }
 
-        return port;
+        return portString;
+
     }
 
     public boolean updateTorConfigCustom(File fileTorRcCustom, String extraLines) throws IOException, FileNotFoundException, TimeoutException {
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
index dcbb824a..8898439e 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java
@@ -61,8 +61,8 @@ public interface TorServiceConstants {
 //	String TOR_VPN_DNS_LISTEN_ADDRESS = "127.0.0.1";
 	
 //	int CONTROL_PORT_DEFAULT = 9051;
-    String HTTP_PROXY_PORT_DEFAULT = "auto"; // like Privoxy!
-    String SOCKS_PROXY_PORT_DEFAULT = "auto";
+    String HTTP_PROXY_PORT_DEFAULT = "8118"; // like Privoxy!
+    String SOCKS_PROXY_PORT_DEFAULT = "9050";
 
 	//path to check Tor against
 	String URL_TOR_CHECK = "https://check.torproject.org";





More information about the tor-commits mailing list