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

[tor-commits] [ooni-probe/master] Refactor Parasitictraceroute.



commit 5a924d156bc567a3319241645df700d6f4b9023f
Author: aagbsn <aagbsn@xxxxxxxx>
Date:   Wed Aug 20 14:23:04 2014 +0000

    Refactor Parasitictraceroute.
    
    In particular, scapy.supersocket.L3RawSocket does not capture
    transmitted packets.
---
 ooni/nettests/experimental/parasitictraceroute.py |   13 +++++++-----
 ooni/utils/txscapy.py                             |   22 +++++++++++----------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/ooni/nettests/experimental/parasitictraceroute.py b/ooni/nettests/experimental/parasitictraceroute.py
index 9526455..882d25a 100644
--- a/ooni/nettests/experimental/parasitictraceroute.py
+++ b/ooni/nettests/experimental/parasitictraceroute.py
@@ -1,5 +1,6 @@
 from twisted.python import usage
 from twisted.internet import defer, reactor
+from ooni.errors import handleAllFailures
 from ooni.templates import scapyt
 from ooni.utils import log
 from ooni.utils.txscapy import ParasiticTraceroute
@@ -14,19 +15,23 @@ class ParasiticTracerouteTest(scapyt.BaseScapyTest):
 
     samplePeriod = 40
     requiresTor = False
-    requiresRoot = False
 
     def setUp(self):
         self.report['parasitic_traceroute'] = {}
 
     def test_parasitic_traceroute(self):
         self.pt = ParasiticTraceroute()
+        log.debug("Starting ParasiticTraceroute for up to %d hosts at inject "
+                "rate %d with %s" % (self.pt.numHosts, self.pt.rate, self.pt))
         config.scapyFactory.registerProtocol(self.pt)
         d = defer.Deferred()
-        reactor.callLater(self.samplePeriod, d.callback, self.pt)
+        reactor.callLater(self.samplePeriod, d.callback, self)
+        d.addCallback(self.addToReport)
+        d.addErrback(handleAllFailures)
         return d
 
-    def postProcessor(self, *args, **kwargs):
+    def addToReport(self, result):
+        log.debug("Stopping ParasiticTraceroute")
         self.pt.stopListening()
         self.report['received_packets'] = self.pt.received_packets
 
@@ -46,5 +51,3 @@ class ParasiticTracerouteTest(scapyt.BaseScapyTest):
             self.report['parasitic_traceroute'][p].sort(key=lambda x: x[0])
                 
         self.report['sent_packets'] = self.pt.sent_packets
-        return self.report
-
diff --git a/ooni/utils/txscapy.py b/ooni/utils/txscapy.py
index ba90223..e8a27b6 100644
--- a/ooni/utils/txscapy.py
+++ b/ooni/utils/txscapy.py
@@ -160,7 +160,7 @@ class ScapyFactory(abstract.FileDescriptor):
         if not super_socket and sys.platform == 'darwin':
             super_socket = conf.L3socket(iface=interface, promisc=True, filter='')
         elif not super_socket:
-            super_socket = L3RawSocket(iface=interface, promisc=True)
+            super_socket = conf.L3socket(iface=interface)
 
         self.protocols = []
         fdesc._setCloseOnExec(super_socket.ins.fileno())
@@ -325,6 +325,8 @@ class ParasiticTraceroute(ScapyProtocol):
 
     def sendPacket(self, packet):
         self.factory.send(packet)
+        self.sent_packets.append(packet)
+        log.debug("Sent packet to %s with ttl %d" % (packet.dst, packet.ttl))
 
     def packetReceived(self, packet):
         try:
@@ -332,24 +334,25 @@ class ParasiticTraceroute(ScapyProtocol):
         except IndexError:
             return
 
+        # Add TTL Expired responses.
         if isinstance(packet.getlayer(3), TCPerror):
             self.received_packets.append(packet)
+            # Live traceroute?
+            log.debug("%s replied with icmp-ttl-exceeded for %s" % (packet.src, packet[IPerror].dst))
             return
-
         elif packet.dst in self.hosts:
             if random.randint(1, 100) > self.rate:
+                # Don't send a packet this time
                 return
             try:
                 packet[IP].ttl = self.hosts[packet.dst]['ttl'].pop()
                 del packet.chksum  # XXX Why is this incorrect?
-                log.debug("Sent packet to %s with ttl %d" % (packet.dst, packet.ttl))
                 self.sendPacket(packet)
                 k = (packet.id, packet[TCP].sport, packet[TCP].dport, packet[TCP].seq)
                 self.matched_packets[k] = {'ttl': packet.ttl}
                 return
             except IndexError:
-                pass
-            return
+                return
 
         def maxttl(packet=None):
             if packet:
@@ -369,17 +372,16 @@ class ParasiticTraceroute(ScapyProtocol):
 
                 self.hosts[packet.dst] = {'ttl': genttl()}
                 log.debug("Tracing to %s" % packet.dst)
-
-            elif packet.src not in self.hosts \
+                return
+            if packet.src not in self.hosts \
                     and packet.src not in self.addresses \
                     and isinstance(packet.getlayer(1), TCP):
-
                 self.hosts[packet.src] = {'ttl': genttl(packet),
                                           'ttl_max': maxttl(packet)}
                 log.debug("Tracing to %s" % packet.src)
-            return
+                return
 
-        elif packet.src in self.hosts and not 'ttl_max' in self.hosts[packet.src]:
+        if packet.src in self.hosts and not 'ttl_max' in self.hosts[packet.src]:
             self.hosts[packet.src]['ttl_max'] = ttl_max = maxttl(packet)
             log.debug("set ttl_max to %d for host %s" % (ttl_max, packet.src))
             ttl = []



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