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

[tor-commits] [ooni-probe/master] Respect the includeip = false option in ooniprobe.conf for scapyt derivate tests



commit dc01cb60c73d4a57df3e01e6acf0d136d2e79e2c
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sun Nov 11 15:38:05 2012 +0100

    Respect the includeip = false option in ooniprobe.conf for scapyt derivate tests
    * If the option to not include the IP address of the probe is set, change the
      source and destination ip address of the sent and received packets to
      127.0.0.1
---
 ooni/reporter.py         |   10 +---------
 ooni/templates/scapyt.py |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/ooni/reporter.py b/ooni/reporter.py
index eea44c7..b5e2039 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -15,11 +15,6 @@ import yaml
 import json
 import traceback
 
-from yaml.representer import *
-from yaml.emitter import *
-from yaml.serializer import *
-from yaml.resolver import *
-
 from twisted.python.util import untilConcludes
 from twisted.trial import reporter
 from twisted.internet import defer, reactor
@@ -94,7 +89,6 @@ def getTestDetails(options):
                     }
     defer.returnValue(test_details)
 
-
 class OReporter(object):
     def createReport(options):
         """
@@ -114,10 +108,8 @@ class OReporter(object):
     def testDone(self, test, test_name):
         test_report = dict(test.report)
 
-        # XXX the scapy test has an example of how 
-        # to do this properly.
         if isinstance(test.input, packet.Packet):
-            test_input = repr(test.input)
+            test_input = createPacketReport(test.input)
         else:
             test_input = test.input
 
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index feaf720..d137276 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -14,6 +14,8 @@ from scapy.all import send, sr, IP, TCP
 from ooni.nettest import NetTestCase
 from ooni.utils import log
 
+from ooni import config
+
 from ooni.utils.txscapy import ScapyProtocol
 
 def createPacketReport(packet_list):
@@ -53,8 +55,17 @@ class BaseScapyTest(NetTestCase):
             self.report['sent_packets'] = []
             for snd, rcv in answered:
                 log.debug("Writing report for scapy test")
-                pkt_report_r = createPacketReport(rcv)
-                pkt_report_s = createPacketReport(snd)
+                sent_packet = snd
+                received_packet = rcv
+
+                if not config.privacy.includeip:
+                    log.msg("Detected you would not like to include your ip in the report")
+                    log.msg("Stripping source and destination IPs from the reports")
+                    sent_packet.src = '127.0.0.1'
+                    received_packet.dst = '127.0.0.1'
+
+                pkt_report_r = createPacketReport(received_packet)
+                pkt_report_s = createPacketReport(sent_packet)
                 self.report['answered_packets'].append(pkt_report_r)
                 self.report['sent_packets'].append(pkt_report_s)
                 log.debug("Done")



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