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

[tor-commits] [ooni-probe/master] Improve detection logic for web_connectivity



commit 4dd1542306a6cb3615cd5844728a689a4be7c998
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Tue May 3 15:23:18 2016 +0200

    Improve detection logic for web_connectivity
    
    * Fix printing of exception log
---
 bin/oonireport                             |  2 +-
 ooni/nettests/blocking/web_connectivity.py | 22 +++++++++++++++-------
 ooni/utils/log.py                          |  2 +-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/bin/oonireport b/bin/oonireport
index 6a79f4c..9f59683 100755
--- a/bin/oonireport
+++ b/bin/oonireport
@@ -14,8 +14,8 @@ def failed(failure):
     r = failure.trap(exceptions.SystemExit,
                      Exception)
     if r != exceptions.SystemExit:
-        log.err("Failed to run oonireport")
         log.exception(failure)
+        log.err("Failed to run oonireport")
         exitCode = 127
     else:
         exitCode = failure.value.code
diff --git a/ooni/nettests/blocking/web_connectivity.py b/ooni/nettests/blocking/web_connectivity.py
index 69fd002..08cae57 100644
--- a/ooni/nettests/blocking/web_connectivity.py
+++ b/ooni/nettests/blocking/web_connectivity.py
@@ -326,8 +326,15 @@ class WebConnectivityTest(httpt.HTTPTest, dnst.DNSTest):
     def determine_blocking(self, experiment_http_response, experiment_dns_answers):
         blocking = False
 
-        if (self.report['http_experiment_failure'] is None and
-                    self.report['control']['http_request']['failure'] is None):
+        control_http_failure = self.report['control']['http_request']['failure']
+        if control_http_failure is not None:
+            control_http_failure = control_http_failure.split(" ")[0]
+
+        experiment_http_failure = self.report['http_experiment_failure']
+        if experiment_http_failure is not None:
+            experiment_http_failure = experiment_http_failure.split(" ")[0]
+
+        if (experiment_http_failure is None and control_http_failure is None):
             self.report['body_length_match'] = self.compare_body_lengths(
                 experiment_http_response)
             self.report['headers_match'] = self.compare_headers(
@@ -340,8 +347,9 @@ class WebConnectivityTest(httpt.HTTPTest, dnst.DNSTest):
             self.report['dns_consistency'] = 'inconsistent'
         tcp_connect = self.compare_tcp_experiments()
 
+
         if (dns_consistent == True and tcp_connect == False and
-                self.report['http_experiment_failure'] is not None):
+                experiment_http_failure is not None):
             blocking = 'tcp_ip'
 
         # XXX we may want to have different codes for these two types of
@@ -350,12 +358,12 @@ class WebConnectivityTest(httpt.HTTPTest, dnst.DNSTest):
                       self.report['body_length_match'] == False):
             blocking = 'http'
         elif (dns_consistent == True and tcp_connect == True and
-                self.report['http_experiment_failure'] is not None and
-                self.report['control']['http_request']['failure'] != self.report['http_experiment_failure']):
+                experiment_http_failure is not None and
+                control_http_failure is None):
             blocking = 'http'
 
         elif (dns_consistent == False and
-                  (self.report['http_experiment_failure'] is not None or
+                  (experiment_http_failure is not None or
                    self.report['body_length_match'] == False)):
             blocking = 'dns'
 
@@ -364,7 +372,7 @@ class WebConnectivityTest(httpt.HTTPTest, dnst.DNSTest):
         # that is only accessible from within the country/network of the probe.
         elif (dns_consistent == False and
                   (self.control['dns']['failure'] is not None or
-                   self.control['http_request']['failure'] is not None)):
+                   control_http_failure != experiment_http_failure)):
             blocking = 'dns'
 
         return blocking
diff --git a/ooni/utils/log.py b/ooni/utils/log.py
index f36c0ff..fd80594 100644
--- a/ooni/utils/log.py
+++ b/ooni/utils/log.py
@@ -111,7 +111,7 @@ def exception(error):
     or it can be a twisted.python.failure.Failure instance.
     """
     if isinstance(error, Failure):
-        error.printTraceback()
+        error.printTraceback(sys.stdout)
     else:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         traceback.print_exception(exc_type, exc_value, exc_traceback)



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