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

[tor-commits] [orbot/master] check if needed ports are available



commit 78e7af4372cc9dc5f5484fccd7814d1a95d728cc
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Thu Apr 17 11:34:47 2014 -0400

    check if needed ports are available
    dont' reapply transproxy on network reconnect
---
 src/org/torproject/android/service/TorService.java |   41 ++++++++++++++++++--
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 441bd1e..48eb580 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -15,6 +15,8 @@ import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -121,8 +123,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
     	if (ENABLE_DEBUG_LOG)
     	{
     		Log.e(TAG,msg,e);
-    		sendCallbackLogMessage(msg);	
     	}
+    	
+		sendCallbackLogMessage(msg);	
+
     }
     
     
@@ -615,6 +619,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
     public void initTor () throws Exception
     {
     	
+    	boolean portsAvail = checkPortsAvailable();
+    	
+    	if (!portsAvail)
+    	{
+    		logNotice("Another app is blocking Tor from starting");
+    		return;
+    	}
+    	
     	try
     	{
     		initBinaries();
@@ -650,6 +662,31 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		//checkAddressAndCountry();
     }
     
+    private boolean checkPortsAvailable ()
+    {
+    	int[] ports = {9050,9051,8118};
+    	
+    	for (int port: ports)
+    	{
+	    	try
+	    	{
+	    		logNotice("checking local port is available: " + port);
+	    		
+	    		ServerSocket ss = new ServerSocket();
+	    		ss.bind(new InetSocketAddress(IP_LOCALHOST,port));
+	    		ss.close();
+	    	}
+	    	catch (Exception e)
+	    	{
+	    		logException ("Tor socket is not available",e);
+	    		return false;
+	    	}
+    	}
+    	
+    	return true;
+    	
+    }
+    
     /*
      * activate means whether to apply the users preferences
      * or clear them out
@@ -1576,8 +1613,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 						logNotice("Network connectivity is good. Waking Tor up...");
 						showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,-1,prefPersistNotifications);
 
-						if (mHasRoot && mEnableTransparentProxy)
-							enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
 			        }
 					
 	    		} catch (Exception e) {

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