commit 69c5d3a014212ce0c0899e256531fdfe3d179604 Author: Arturo Filastò art@fuffa.org Date: Fri Dec 7 01:51:11 2012 +0100
Fix bugs in oonib reporter * Add support for setting the tor binary path in oonib/config.py --- oonib/config.py | 4 +++ oonib/report/api.py | 6 +++- oonib/report/file_collector.py | 48 +++++++++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 12 deletions(-)
diff --git a/oonib/config.py b/oonib/config.py index 2736cd0..cdee45a 100644 --- a/oonib/config.py +++ b/oonib/config.py @@ -7,6 +7,8 @@ def get_root_path(): root = os.path.abspath(root) return root
+backend_version = '0.0.1' + # XXX convert this to something that is a proper config file main = Storage()
@@ -19,6 +21,8 @@ main.tor_datadir = os.path.join(get_root_path(), 'oonib', 'data', 'tor')
main.database_uri = "sqlite:"+get_root_path()+"oonib_test_db.db" main.db_threadpool_size = 10 +#main.tor_binary = '/usr/sbin/tor' +main.tor_binary = '/usr/local/bin/tor'
helpers = Storage()
diff --git a/oonib/report/api.py b/oonib/report/api.py index 14a4bc1..b3d529d 100644 --- a/oonib/report/api.py +++ b/oonib/report/api.py @@ -1,9 +1,10 @@ """ -/new +/report
/pcap
-This is the async pcap reporting system. It requires the client to have created a report already, but can work independently from test progress. +This is the async pcap reporting system. It requires the client to have created +a report already, but can work independently from test progress.
""" import random @@ -18,6 +19,7 @@ from cyclone import web
from ooni import otime from ooni.utils import randomStr + from oonib import models, config from oonib.report import file_collector
diff --git a/oonib/report/file_collector.py b/oonib/report/file_collector.py index 584a11d..636576b 100644 --- a/oonib/report/file_collector.py +++ b/oonib/report/file_collector.py @@ -6,10 +6,38 @@ import os
from twisted.internet import fdesc
-from oonib.report import MissingField, InvalidRequestField +from cyclone import web + from ooni.utils import randomStr +from ooni import otime + +from oonib.report import MissingField, InvalidRequestField + +from oonib import config + +def parseUpdateReportRequest(request): + #db_report_id_regexp = re.compile("[a-zA-Z0-9]+$") + + # this is the regexp for the reports that include the timestamp + report_id_regexp = re.compile("[a-zA-Z0-9_-]+$") + + # XXX here we are actually parsing a json object that could be quite big. + # If we want this to scale properly we only want to look at the test_id + # field. + # We are also keeping in memory multiple copies of the same object. A lot + # of optimization can be done. + parsed_request = json.loads(request) + try: + report_id = parsed_request['report_id'] + except KeyError: + raise MissingField('report_id') + + if not re.match(report_id_regexp, report_id): + raise InvalidRequestField('report_id') + + return parsed_request +
-from cyclone import web
def parseNewReportRequest(request): """ @@ -99,7 +127,7 @@ class NewReportHandlerFile(web.RequestHandler): software_version = report_data['software_version'] test_name = report_data['test_name'] test_version = report_data['test_version'] - probe_asn = report_data['test_version'] + probe_asn = report_data['probe_asn'] content = report_data['content']
if not probe_asn: @@ -113,7 +141,7 @@ class NewReportHandlerFile(web.RequestHandler): # random nonce report_filename = os.path.join(config.main.report_dir, report_id)
- response = {'backend_version': backend_version, + response = {'backend_version': config.backend_version, 'report_id': report_id }
@@ -122,10 +150,10 @@ class NewReportHandlerFile(web.RequestHandler):
self.write(response)
- def writeToReport(report_filename, data): + def writeToReport(self, report_filename, data): with open(report_filename, 'w+') as fd: - fdesc.setNonBlocking(fd) - fdesc.writeToFD(data) + fdesc.setNonBlocking(fd.fileno()) + fdesc.writeToFD(fd.fileno(), data)
def put(self): """ @@ -146,11 +174,11 @@ class NewReportHandlerFile(web.RequestHandler):
self.updateReport(report_filename, parsed_request['content'])
- def updateReport(report_filename, data): + def updateReport(self, report_filename, data): try: with open(report_filename, 'a+') as fd: - fdesc.setNonBlocking(fd) - fdesc.writeToFD(data) + fdesc.setNonBlocking(fd.fileno()) + fdesc.writeToFD(fd.fileno(), data) except IOError as e: web.HTTPError(404, "Report not found")
tor-commits@lists.torproject.org