[tor-commits] [ooni-probe/master] Move scapy to scapyproto to avoid breaking import of scapy from

art at torproject.org art at torproject.org
Sat Jul 21 00:35:06 UTC 2012


commit b25e21745ecdc5c03b3229ba77ee51b5fdd1561d
Author: Arturo Filastò <hellais at torproject.org>
Date:   Sat Jul 21 02:33:48 2012 +0200

    Move scapy to scapyproto to avoid breaking import of scapy from
    inside of protocols
---
 ooni/protocols/scapyproto.py |   55 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/ooni/protocols/scapyproto.py b/ooni/protocols/scapyproto.py
new file mode 100644
index 0000000..4166146
--- /dev/null
+++ b/ooni/protocols/scapyproto.py
@@ -0,0 +1,55 @@
+import random
+from zope.interface import implements
+from twisted.python import usage
+from twisted.plugin import IPlugin
+from twisted.internet import protocol, defer
+from ooni.plugoo.tests import ITest, OONITest
+from ooni.plugoo.assets import Asset
+from ooni.utils import log
+
+from ooni.lib.txscapy import txsr, txsend
+
+class ScapyTest(OONITest):
+    """
+    A utility class for writing scapy driven OONI tests.
+    """
+
+    receive = True
+    timeout = None
+    pcapfile = 'scapytest.pcap'
+    def initialize(self, reactor=None):
+
+        if not self.reactor:
+            from twisted.internet import reactor
+            self.reactor = reactor
+
+        self.request = {}
+        self.response = {}
+
+    def experiment(self, args):
+        log.msg("Running experiment")
+        if self.receive:
+            log.msg("Sending and receiving packets.")
+            d = txsr(self.build_packets(), pcapfile=self.pcapfile,
+                    timeout=self.timeout)
+        else:
+            log.msg("Sending packets.")
+            d = txsend(self.build_packets())
+
+        def finished(data):
+            log.msg("Finished sending")
+            return data
+
+        d.addCallback(finished)
+        return d
+
+    def build_packets(self):
+        """
+        Override this method to build scapy packets.
+        """
+        from scapy.all import IP, TCP
+        return IP()/TCP()
+
+    def load_assets(self):
+        return {}
+





More information about the tor-commits mailing list