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

[tor-commits] [ooni-probe/master] If the option start_tor is set to True, make sure that Tor is started before running the test deck



commit 12c12cee5224dc1f62ae7cfc77cd4e0c6e2283e9
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Tue Nov 27 03:08:15 2012 +0100

    If the option start_tor is set to True, make sure that Tor is started before running the test deck
---
 ooni/oonicli.py |   64 +++++++++++++++++++++++++++++++++++++++++++------------
 ooni/runner.py  |   61 +++++++++++++++++++---------------------------------
 ooniprobe.conf  |    4 +-
 3 files changed, 74 insertions(+), 55 deletions(-)

diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 2b0991b..26cfdab 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -96,22 +96,26 @@ def testsEnded(*arg, **kw):
     try: reactor.stop()
     except: pass
 
-def run():
-    """
-    Call me to begin testing from a file.
-    """
-    cmd_line_options = Options()
-    if len(sys.argv) == 1:
-        cmd_line_options.getUsage()
+def startSniffing():
+    from ooni.utils.txscapy import ScapyFactory, ScapySniffer
     try:
-        cmd_line_options.parseOptions()
-    except usage.UsageError, ue:
-        raise SystemExit, "%s: %s" % (sys.argv[0], ue)
+        checkForRoot()
+    except NotRootError:
+        print "[!] Includepcap options requires root priviledges to run"
+        print "    you should run ooniprobe as root or disable the options in ooniprobe.conf"
+        sys.exit(1)
+
+    print "Starting sniffer"
+    config.scapyFactory = ScapyFactory(config.advanced.interface)
+
+    sniffer = ScapySniffer(config.reports.pcap)
+    config.scapyFactory.registerProtocol(sniffer)
+
 
+def runTestDeckOrTest(result, cmd_line_options):
     deck_dl = []
     resume = cmd_line_options['resume']
 
-    log.start(cmd_line_options['logfile'])
     if cmd_line_options['testdeck']:
         test_deck = yaml.safe_load(open(cmd_line_options['testdeck']))
         for test in test_deck:
@@ -135,7 +139,39 @@ def run():
     # Print every 5 second the list of current tests running
     l = task.LoopingCall(updateStatusBar)
     l.start(5.0)
+    return d2
+
+def errorRunningTests(failure):
+    failure.printTraceback()
+
+def run():
+    """
+    Call me to begin testing from a file.
+    """
+
+    cmd_line_options = Options()
+    if len(sys.argv) == 1:
+        cmd_line_options.getUsage()
+    try:
+        cmd_line_options.parseOptions()
+    except usage.UsageError, ue:
+        raise SystemExit, "%s: %s" % (sys.argv[0], ue)
+
+    log.start(cmd_line_options['logfile'])
+
+    if config.privacy.includepcap:
+        log.msg("Starting")
+        runner.startSniffing()
+
+    if config.advanced.start_tor:
+        log.msg("Starting Tor...")
+        d = runner.startTor()
+        d.addCallback(runTestDeckOrTest, cmd_line_options)
+        d.addErrback(errorRunningTests)
+    else:
+        # We need to pass None as first argument because when the callback
+        # is fired it will pass it's result to runTestCase.
+        d = runTestDeckOrTest(None, cmd_line_options)
+        d.addErrback(errorRunningTests)
 
-    if config.start_reactor:
-        log.debug("Starting reactor")
-        reactor.run()
+    reactor.run()
diff --git a/ooni/runner.py b/ooni/runner.py
index 6940ec6..30682e9 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -433,7 +433,6 @@ class UnableToStartTor(Exception):
     pass
 
 def startTor():
-
     @defer.inlineCallbacks
     def state_complete(state):
         config.tor_state = state
@@ -444,9 +443,9 @@ def startTor():
         config.tor.socks_port = yield state.protocol.get_conf("SocksPort")
         config.tor.control_port = yield state.protocol.get_conf("ControlPort")
 
-    def setup_failed(arg):
-        log.exception(arg)
-        raise UnableTorStartTor
+    def setup_failed(failure):
+        log.exception(failure)
+        raise UnableToStartTor
 
     def setup_complete(proto):
         """
@@ -459,7 +458,7 @@ def startTor():
         return state.post_bootstrap
 
     def updates(prog, tag, summary):
-        log.msg("%d%%: %s" % (prog, summary))
+        print "%d%%: %s" % (prog, summary)
 
     tor_config = TorConfig()
     if config.tor.control_port:
@@ -481,11 +480,27 @@ def startTor():
     log.debug("Setting control port as %s" % tor_config.ControlPort)
     log.debug("Setting SOCKS port as %s" % tor_config.SocksPort)
 
-    d = launch_tor(tor_config, reactor, progress_updates=updates)
+    d = launch_tor(tor_config, reactor,
+            progress_updates=updates)
     d.addCallback(setup_complete)
     d.addErrback(setup_failed)
     return d
 
+def startSniffing():
+    from ooni.utils.txscapy import ScapyFactory, ScapySniffer
+    try:
+        checkForRoot()
+    except NotRootError:
+        print "[!] Includepcap options requires root priviledges to run"
+        print "    you should run ooniprobe as root or disable the options in ooniprobe.conf"
+        sys.exit(1)
+
+    print "Starting sniffer"
+    config.scapyFactory = ScapyFactory(config.advanced.interface)
+
+    sniffer = ScapySniffer(config.reports.pcap)
+    config.scapyFactory.registerProtocol(sniffer)
+
 def runTest(cmd_line_options):
     config.cmd_line_options = cmd_line_options
     config.generateReportFilenames()
@@ -502,36 +517,4 @@ def runTest(cmd_line_options):
     classes = findTestClassesFromFile(cmd_line_options['test'])
     test_cases, options = loadTestsAndOptions(classes, cmd_line_options)
 
-    if config.privacy.includepcap:
-        from ooni.utils.txscapy import ScapyFactory, ScapySniffer
-        try:
-            checkForRoot()
-        except NotRootError:
-            print "[!] Includepcap options requires root priviledges to run"
-            print "    you should run ooniprobe as root or disable the options in ooniprobe.conf"
-            sys.exit(1)
-
-        print "Starting sniffer"
-        config.scapyFactory = ScapyFactory(config.advanced.interface)
-
-        sniffer = ScapySniffer(config.reports.pcap)
-        config.scapyFactory.registerProtocol(sniffer)
-
-    # If we should start Tor then start it. Once Tor has started we will make
-    # sure. If not we assume that it is already running
-    if config.advanced.start_tor:
-        def tor_startup_failed(failure):
-            log.err(failure)
-
-        def tor_started():
-            return runTestCases(test_cases,
-                    options, cmd_line_options)
-
-        d = startTor()
-        d.addCallback(tor_started)
-        d.addErrback(tor_startup_failed)
-        return d
-
-    else:
-        return runTestCases(test_cases,
-                options, cmd_line_options)
+    return runTestCases(test_cases, options, cmd_line_options)
diff --git a/ooniprobe.conf b/ooniprobe.conf
index b553a37..ed77dfe 100644
--- a/ooniprobe.conf
+++ b/ooniprobe.conf
@@ -22,13 +22,13 @@ advanced:
     # /path/to/ooni-probe/data/
     geoip_data_dir: /usr/share/GeoIP/
     debug: true
-    threadpool_size: 10
-
     tor_binary: '/usr/sbin/tor'
     # For auto detection
     interface: auto
     # Of specify a specific interface
     #interface: wlan0
+    # If you do not specify start_tor, you will have to have Tor running and
+    # explicitly set the control port and orport.
     start_tor: true
 tor:
     #socks_port: 9050

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