commit cb21e983ccce8c8f44f95b98da8bd1c01d7905f4
Author: aagbsn <aagbsn(a)extc.org>
Date: Sun Jun 30 17:26:49 2013 +0200
Set pcap name for each NetTest.
---
ooni/director.py | 23 +++++++++++------------
ooni/settings.py | 16 ++++------------
2 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/ooni/director.py b/ooni/director.py
index 55ed8e7..a44ee57 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -116,12 +116,6 @@ class Director(object):
def start(self):
self.netTests = self.getNetTests()
- if config.privacy.includepcap:
- log.msg("Starting")
- if not config.reports.pcap:
- config.generate_pcap_filename()
- self.startSniffing()
-
if config.advanced.start_tor:
log.msg("Starting Tor...")
yield self.startTor()
@@ -217,6 +211,12 @@ class Director(object):
net_test_loader:
an instance of :class:ooni.nettest.NetTestLoader
"""
+
+ if config.privacy.includepcap:
+ if not config.reports.pcap:
+ config.reports.pcap = config.generatePcapFilename(net_test_loader.testDetails)
+ self.startSniffing()
+
report = Report(reporters, self.reportEntryManager)
net_test = NetTest(net_test_loader, report)
@@ -233,7 +233,6 @@ class Director(object):
self.netTestDone(net_test)
-
def startSniffing(self):
""" Start sniffing with Scapy. Exits if required privileges (root) are not
available.
@@ -242,23 +241,23 @@ class Director(object):
try:
checkForRoot()
except errors.InsufficientPrivileges:
- print "[!] Includepcap options requires root priviledges to run"
- print " you should run ooniprobe as root or disable the options in ooniprobe.conf"
+ log.err("Includepcap options requires root priviledges to run")
+ log.err("you should run ooniprobe as root or disable the options in ooniprobe.conf")
reactor.stop()
sys.exit(1)
- print "Starting sniffer"
config.scapyFactory = ScapyFactory(config.advanced.interface)
if os.path.exists(config.reports.pcap):
- print "Report PCAP already exists with filename %s" % config.reports.pcap
- print "Renaming files with such name..."
+ log.msg("Report PCAP already exists with filename %s" % config.reports.pcap)
+ log.msg("Renaming files with such name...")
pushFilenameStack(config.reports.pcap)
if self.sniffer:
config.scapyFactory.unRegisterProtocol(self.sniffer)
self.sniffer = ScapySniffer(config.reports.pcap)
config.scapyFactory.registerProtocol(self.sniffer)
+ log.msg("Starting packet capture to: %s" % config.reports.pcap)
def startTor(self):
""" Starts Tor
diff --git a/ooni/settings.py b/ooni/settings.py
index 846fc10..6c8a9a3 100644
--- a/ooni/settings.py
+++ b/ooni/settings.py
@@ -82,17 +82,9 @@ class OConfig(object):
pass
self.set_paths()
- def generate_pcap_filename():
- if self.global_options.get('pcapfile'):
- self.reports.pcap = self.global_options['pcapfile']
- else:
- if self.global_options.get('test'):
- test_filename = os.path.basename(self.global_options['test'])
- else:
- test_filename = os.path.basename(self.global_options['testdeck'])
-
- test_name = '.'.join(test_filename.split(".")[:-1])
- frm_str = "report_%s_"+otime.timestamp()+".%s"
- self.reports.pcap = frm_str % (test_name, "pcap")
+ def generatePcapFilename(testDetails):
+ test_name, start_time = testDetails['test_name'], testDetails['start_time']
+ start_time = otime.epochToTimestamp(start_time)
+ return "report-%s-%s.%s" % (test_name, start_time, "pcap")
config = OConfig()