[tor-commits] [ooni-probe/master] Fix bug in scapy test template

art at torproject.org art at torproject.org
Tue Nov 6 12:43:37 UTC 2012


commit 85ff8f2daf527d81da69d5e3af84f7e97e6fe579
Author: Arturo Filastò <arturo at filasto.net>
Date:   Tue Nov 6 00:34:18 2012 +0100

    Fix bug in scapy test template
    * Add debug lines to scapyt
---
 nettests/examples/example_scapyt.py |    1 +
 ooni/lib/txscapy.py                 |   15 +++++++++++----
 ooni/templates/scapyt.py            |    2 +-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/nettests/examples/example_scapyt.py b/nettests/examples/example_scapyt.py
index cda3a10..ce32ac3 100644
--- a/nettests/examples/example_scapyt.py
+++ b/nettests/examples/example_scapyt.py
@@ -3,6 +3,7 @@
 # :authors: Arturo Filastò
 # :licence: see LICENSE
 
+from ooni.utils import log
 from ooni.templates import scapyt
 from scapy.all import *
 
diff --git a/ooni/lib/txscapy.py b/ooni/lib/txscapy.py
index d4f146e..4446be0 100644
--- a/ooni/lib/txscapy.py
+++ b/ooni/lib/txscapy.py
@@ -24,6 +24,8 @@ from zope.interface import implements
 from scapy.all import Gen
 from scapy.all import SetGen
 
+from ooni.utils import log
+
 LINUX=sys.platform.startswith("linux")
 OPENBSD=sys.platform.startswith("openbsd")
 FREEBSD=sys.platform.startswith("freebsd")
@@ -260,6 +262,7 @@ class Scapy(object):
         self.socket.send(pkt)
 
     def timeout(self, *arg, **kw):
+        log.debug("Caught a timeout with %s %s" % (arg, kw))
         if not self.done:
             self._reactor.callLater(self.timeoutSeconds, self.timeout, None)
         else:
@@ -284,6 +287,7 @@ class Scapy(object):
         @param filter:   provide a BPF filter
         @param iface:    listen answers only on the given interface
         """
+        log.debug("Calling with %s" % pkts)
         self.recv = True
         if timeout:
             self.timeoutSeconds = timeout
@@ -356,15 +360,18 @@ class Scapy(object):
         self.running = False
 
 @defer.inlineCallbacks
-def txsr(*args, **kw):
-    tr = Scapy(*args, **kw)
-    tr.sr(*args, **kw)
+def txsr(*arg, **kw):
+    tr = Scapy(*arg, **kw)
+    log.debug("Calling sr with %s, %s" % (arg, kw))
+    tr.sr(*arg, **kw)
     yield tr.deferred
     tr.finalClose()
 
 @defer.inlineCallbacks
 def txsend(*arg, **kw):
-    tr = Scapy(*arg, **kw)
+    tr = Scapy(**kw)
+    log.debug("Calling send with %s, %s" % (arg, kw))
     tr.send(*arg, **kw)
     yield tr.deferred
     tr.finalClose()
+
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index 1b19dbf..8751587 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -45,7 +45,7 @@ class ScapyTest(NetTestCase):
         self.reactor.stop()
 
     def sendReceivePackets(self, *kw):
-        d = txsr(packets=self.request, pcapfile=self.pcapfile,
+        d = txsr(self.request, pcapfile=self.pcapfile,
                  timeout=self.timeout, reactor=self.reactor)
         return d
 





More information about the tor-commits mailing list