commit 86aa9ff669b567c5677ba1174c6c07bb9dcc6cc2 Author: Arturo Filastò art@fuffa.org Date: Fri Aug 16 21:52:31 2013 +0200
Add support for exposing OONIB not over Tor (useful for debugging)
Test the input list API. --- oonib.conf.example | 2 ++ oonib/api.py | 18 ++++++++++++------ oonib/inputs/handlers.py | 17 +++++++++-------- oonib/runner.py | 14 ++++++++------ 4 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/oonib.conf.example b/oonib.conf.example index a1bba84..36df0e3 100644 --- a/oonib.conf.example +++ b/oonib.conf.example @@ -28,6 +28,8 @@ main: debug: false stale_time: 3600
+ tor_hidden_service: true + helpers: http_return_request: port: 57001 diff --git a/oonib/api.py b/oonib/api.py index 48c2e1e..775c4ad 100644 --- a/oonib/api.py +++ b/oonib/api.py @@ -1,3 +1,5 @@ +from cyclone import web + from oonib.deck.api import deckAPI from oonib.report.api import reportAPI from oonib.inputs.api import inputsAPI @@ -6,17 +8,21 @@ from oonib.bouncer.api import bouncerAPI
from oonib import config
-oonibAPI = [] -oonibAPI += reportAPI +ooniBackendAPI = [] +ooniBackendAPI += reportAPI
if config.main.inputs_dir: - oonibAPI += inputsAPI + ooniBackendAPI += inputsAPI
if config.main.deck_dir: - oonibAPI += deckAPI + ooniBackendAPI += deckAPI
if config.main.policy_file: - oonibAPI += policyAPI + ooniBackendAPI += policyAPI
if config.main.bouncer_file: - oonibAPI += bouncerAPI + ooniBackendAPI += bouncerAPI + +print ooniBackendAPI + +ooniBackend = web.Application(ooniBackendAPI, debug=True) diff --git a/oonib/inputs/handlers.py b/oonib/inputs/handlers.py index a1ed80d..cf056ba 100644 --- a/oonib/inputs/handlers.py +++ b/oonib/inputs/handlers.py @@ -1,18 +1,20 @@ -from oonib.handlers import OONIBHandler - -from oonib import config - +import glob import json import os + import yaml
+from oonib.handlers import OONIBHandler + +from oonib import config + class InputsDescHandler(OONIBHandler): def get(self, inputID): #XXX return the input descriptor # see oonib.md in ooni-spec bn = os.path.basename(inputID) + ".desc" try: - f = open(os.path.join(config.main.input_dir, bn)) + f = open(os.path.join(config.main.inputs_dir, bn)) a = {} inputDesc = yaml.safe_load(f) a['id'] = inputID @@ -24,12 +26,11 @@ class InputsDescHandler(OONIBHandler):
class InputsListHandler(OONIBHandler): def get(self): - if not config.main.input_dir: return - path = os.path.abspath(config.main.input_dir) + "/*" + path = os.path.abspath(config.main.inputs_dir) + "/*" inputnames = map(os.path.basename, glob.iglob(path)) inputList = [] for inputname in inputnames: - f = open(os.path.join(config.main.input_dir, deckname)) + f = open(os.path.join(config.main.inputs_dir, inputname)) d = yaml.safe_load(f) inputList.append({ 'id': inputname, diff --git a/oonib/runner.py b/oonib/runner.py index 10f2bef..294f414 100644 --- a/oonib/runner.py +++ b/oonib/runner.py @@ -21,7 +21,7 @@ from txtorcon import TCPHiddenServiceEndpoint, TorConfig from txtorcon import launch_tor
from oonib.report.api import reportAPI -from oonib.api import oonibAPI +from oonib.api import ooniBackend
from oonib import oonibackend from oonib import config @@ -37,7 +37,7 @@ def txSetupFailed(failure): log.err("Setup failed") log.exception(failure)
-def setupCollector(tor_process_protocol): +def setupCollector(tor_process_protocol, datadir): def setup_complete(port): #XXX: drop some other noise about what API are available on this machine print("Exposed collector Tor hidden service on httpo://%s" @@ -53,7 +53,7 @@ def setupCollector(tor_process_protocol): #XXX: also set up a separate keyed hidden service for collectors to push their status to, if the bouncer is enabled hs_endpoint = TCPHiddenServiceEndpoint(reactor, torconfig, public_port, data_dir=datadir) - hidden_service = hs_endpoint.listen(oonibAPI) + hidden_service = hs_endpoint.listen(ooniBackend) hidden_service.addCallback(setup_complete) hidden_service.addErrback(txSetupFailed)
@@ -86,10 +86,9 @@ def startTor(): progress_updates=updates) else: d = launch_tor(torconfig, reactor, progress_updates=updates) - d.addCallback(setupCollector) + d.addCallback(setupCollector, datadir) d.addErrback(txSetupFailed)
- if platformType == "win32": from twisted.scripts._twistw import WindowsApplicationRunner
@@ -108,7 +107,10 @@ else: self.startApplication(self.application) # This is our addition. The rest is taken from # twisted/scripts/_twistd_unix.py 12.2.0 - startTor() + if config.main.tor_hidden_service: + startTor() + else: + reactor.listenTCP(8888, ooniBackend, interface="127.0.0.1") self.startReactor(None, self.oldstdout, self.oldstderr) self.removePID(self.config['pidfile']) if os.path.exists(tempfile.gettempdir()):
tor-commits@lists.torproject.org