[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Refactor to use template methods
commit f3dedf882764b99dc3a5c17fb6640640f70cd576
Author: aagbsn <aagbsn@xxxxxxxx>
Date: Fri Apr 3 19:34:29 2015 +0000
Refactor to use template methods
---
ooni/nettests/third_party/lantern.py | 36 +++++++++++-----------------------
ooni/templates/process.py | 5 ++++-
2 files changed, 15 insertions(+), 26 deletions(-)
diff --git a/ooni/nettests/third_party/lantern.py b/ooni/nettests/third_party/lantern.py
index cb5b57e..a0aea78 100644
--- a/ooni/nettests/third_party/lantern.py
+++ b/ooni/nettests/third_party/lantern.py
@@ -8,7 +8,7 @@ import os.path
from os import getenv
-class LanternBootstrapProcessDirector(ProcessDirector):
+class LanternProcessDirector(ProcessDirector):
"""
This Process Director monitors Lantern during its
bootstrap and fires a callback if bootstrap is
@@ -16,7 +16,8 @@ class LanternBootstrapProcessDirector(ProcessDirector):
before timing out.
"""
- def __init__(self, timeout=None):
+ def __init__(self, d, timeout=None):
+ self.d = d
self.stderr = ""
self.stdout = ""
self.finished = None
@@ -26,17 +27,6 @@ class LanternBootstrapProcessDirector(ProcessDirector):
self.exit_reason = None
self.bootstrapped = defer.Deferred()
- def errReceived(self, data):
- self.stderr += data
-
- def processEnded(self, reason):
- log.debug("Ended %s" % reason)
-
- def cancelTimer(self):
- if self.timeout and self.timer:
- self.timer.cancel()
- log.debug("Cancelled Timer")
-
def outReceived(self, data):
self.stdout += data
# output received, see if we have bootstrapped
@@ -57,7 +47,6 @@ class LanternTest(ProcessTest):
Then, make a HTTP request for http://google.com
and records the response body or failure string.
- XXX: fix the path issue
"""
name = "Lantern Circumvention Tool Test"
@@ -66,23 +55,20 @@ class LanternTest(ProcessTest):
timeout = 20
def setUp(self):
- self.processDirector = LanternBootstrapProcessDirector(timeout=self.timeout)
+ self.d = defer.Deferred()
+ self.processDirector = LanternProcessDirector(self.d, timeout=self.timeout)
+ self.d.addCallback(self.processEnded, "lantern_linux")
def runLantern(self):
command = ["lantern_linux", "--headless"]
- paths = filter(os.path.exists,[os.path.join(os.path.expanduser(x), command[0]) for x in getenv('PATH').split(':')])
- if paths:
+
+ paths = filter(os.path.exists,[os.path.join(os.path.expanduser(x), command[0]) for x in getenv('PATH').split(':')])
+ if paths:
command[0] = paths[0]
log.debug("Spawning Lantern")
reactor.spawnProcess(self.processDirector, command[0], command)
- def addOutputToReport(self, result):
- self.report['stdout'] = self.processDirector.stdout
- self.report['stderr'] = self.processDirector.stderr
- return result
-
def test_lantern_circumvent(self):
-
proxyEndpoint=TCP4ClientEndpoint(reactor, '127.0.0.1', 8787)
agent = ProxyAgent(proxyEndpoint, reactor)
@@ -99,10 +85,10 @@ class LanternTest(ProcessTest):
request = agent.request("GET", "http://google.com")
request.addCallback(readBody)
request.addCallback(addResultToReport)
+ request.addCallback(self.processDirector.close)
return request
self.processDirector.bootstrapped.addCallback(doRequest)
- self.processDirector.bootstrapped.addBoth(self.addOutputToReport)
self.processDirector.bootstrapped.addErrback(addFailureToReport)
self.runLantern()
- return self.processDirector.bootstrapped
+ return self.d
diff --git a/ooni/templates/process.py b/ooni/templates/process.py
index 2d62de1..3bbd8f6 100644
--- a/ooni/templates/process.py
+++ b/ooni/templates/process.py
@@ -16,12 +16,15 @@ class ProcessDirector(protocol.ProcessProtocol):
self.timer = None
self.exit_reason = None
+ def cancelTimer(self):
+ if self.timeout and self.timer:
+ self.timer.cancel()
+
def close(self, reason=None):
self.reason = reason
self.transport.loseConnection()
def resetTimer(self):
- log.debug("Resetting Timer")
if self.timeout is not None:
if self.timer is not None:
self.timer.cancel()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits