[tor-commits] [ooni-probe/master] Minor refactoring of various parts

art at torproject.org art at torproject.org
Sat Aug 18 04:33:54 UTC 2012


commit 3af48ccd706dd1f56faf6d4e46d8db8216d20822
Author: Arturo Filastò <hellais at torproject.org>
Date:   Fri Aug 17 21:31:52 2012 -0700

    Minor refactoring of various parts
---
 ooni/plugins/captiveportal.py |   17 +++++++++++++----
 ooni/plugins/daphn3.py        |    1 +
 ooni/protocols/daphn3.py      |    4 +++-
 oonib/testhelpers/daphn3.py   |    1 +
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/ooni/plugins/captiveportal.py b/ooni/plugins/captiveportal.py
index b48f70b..4bf99b3 100644
--- a/ooni/plugins/captiveportal.py
+++ b/ooni/plugins/captiveportal.py
@@ -31,6 +31,7 @@ try:
     from dns import resolver
 except ImportError:
     print "The dnspython module was not found. https://crate.io/packages/dnspython/"
+    resolver = None
 
 __plugoo__ = "captiveportal"
 __desc__ = "Captive portal detection test"
@@ -132,7 +133,10 @@ class CaptivePortal(OONITest):
         or a list of strings. If nameserver is not given, use local
         DNS resolver, and if that fails try using 8.8.8.8.
         """
-
+        if not resolver:
+            log.msg("dnspython is not installed.\
+                    Cannot perform DNS Resolve test")
+            return []
         if isinstance(hostname, str):
             hostname = [hostname]
 
@@ -192,6 +196,11 @@ class CaptivePortal(OONITest):
         The equivalent of:
         $ dig +short NS ooni.nu
         """
+        if not resolver:
+            log.msg("dnspython not installed.")
+            log.msg("Cannot perform test.")
+            return []
+
         res = resolver.Resolver()
         answer = res.query(hostname, 'NS')
         auth_nameservers = []
@@ -211,9 +220,9 @@ class CaptivePortal(OONITest):
         for char in hostname:
             l33t = random.choice(['caps', 'nocaps'])
             if l33t == 'caps':
-                hostname_0x20 = hostname_0x20 + char.capitalize()
+                hostname_0x20 += char.capitalize()
             else:
-                hostname_0x20 = hostname_0x20 + char.lower()
+                hostname_0x20 += char.lower()
         return hostname_0x20
 
     def check_0x20_to_auth_ns(self, hostname, sample_size=None):
@@ -394,7 +403,7 @@ class CaptivePortal(OONITest):
             log.debug("just magically resolved to a bunch of random addresses.")
             log.debug("That is definitely highly improbable. In fact, my napkin")
             log.debug("tells me that the probability of just one of those")
-            log.degug("hostnames resolving to an address is 1.68e-59, making")
+            log.debug("hostnames resolving to an address is 1.68e-59, making")
             log.debug("it nearly twice as unlikely as an MD5 hash collision.")
             log.debug("Either someone is seriously messing with your network,")
             log.debug("or else you are witnessing the impossible. %s" % r)
diff --git a/ooni/plugins/daphn3.py b/ooni/plugins/daphn3.py
index 091fe8a..a6d51b0 100644
--- a/ooni/plugins/daphn3.py
+++ b/ooni/plugins/daphn3.py
@@ -40,6 +40,7 @@ class Daphn3ClientFactory(protocol.ClientFactory):
             self.mutator.next()
 
         p.mutator = self.mutator
+        p.current_state = self.mutator.state()
         return p
 
     def clientConnectionFailed(self, reason):
diff --git a/ooni/protocols/daphn3.py b/ooni/protocols/daphn3.py
index 7514a40..a4cc32a 100644
--- a/ooni/protocols/daphn3.py
+++ b/ooni/protocols/daphn3.py
@@ -201,6 +201,8 @@ class Daphn3Protocol(protocol.Protocol):
     steps = []
     mutator = None
 
+    current_state = None
+
     role = 'client'
     state = 0
     total_states = len(steps) - 1
@@ -283,7 +285,7 @@ class Daphn3Protocol(protocol.Protocol):
             print "Terminated because of little interest in life."
             return
         report = {'reason': reason, 'proto_state': self.state,
-                'trigger': None, 'mutator_state': self.mutator.state()}
+                'trigger': None, 'mutator_state': self.current_state}
 
         if self.state < self.total_states:
             report['trigger'] = 'did not finish state walk'
diff --git a/oonib/testhelpers/daphn3.py b/oonib/testhelpers/daphn3.py
index 2dd2801..facd11f 100644
--- a/oonib/testhelpers/daphn3.py
+++ b/oonib/testhelpers/daphn3.py
@@ -40,6 +40,7 @@ class Daphn3Server(protocol.ServerFactory):
                 self.mutations.pop(addr.host)
         try:
             p.mutator = self.mutations[addr.host]
+            p.current_state = p.mutator.state()
         except:
             pass
         return p





More information about the tor-commits mailing list