[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Move the creation of the agent for HTTPS and HTTP urls into constructor.
commit f4fda9b7e24da3dbe4a93a2406b9cdda5ca36e23
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date: Fri Feb 5 20:06:48 2016 +0100
Move the creation of the agent for HTTPS and HTTP urls into constructor.
This is needed by our unittests
---
ooni/reporter.py | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index c62fa90..42787fb 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -10,12 +10,16 @@ from yaml.representer import SafeRepresenter
from yaml.emitter import Emitter
from yaml.serializer import Serializer
from yaml.resolver import Resolver
+
from twisted.python.util import untilConcludes
-from twisted.internet import defer
+from twisted.internet import defer, reactor
+from twisted.web.client import Agent
from twisted.internet.error import ConnectionRefusedError
from twisted.python.failure import Failure
from twisted.internet.endpoints import TCP4ClientEndpoint
+from txsocksx.http import SOCKS5Agent
+
from ooni.utils import log
from ooni.tasks import Measurement
try:
@@ -233,6 +237,15 @@ class OONIBReporter(OReporter):
self.reportID = None
+ if self.collectorAddress.startswith('https://'):
+ # not sure if there's something else it needs. Seems to work.
+ # Very difficult to get it to work with self-signed certs.
+ self.agent = Agent(reactor)
+
+ elif self.collectorAddress.startswith('http://'):
+ log.msg("Warning using unencrypted collector")
+ self.agent = Agent(reactor)
+
OReporter.__init__(self, test_details)
def validateCollectorAddress(self):
@@ -287,9 +300,6 @@ class OONIBReporter(OReporter):
# do this with some deferred kung foo or instantiate the reporter after
# tor is started.
- from twisted.web.client import Agent
- from txsocksx.http import SOCKS5Agent
- from twisted.internet import reactor
if self.collectorAddress.startswith('httpo://'):
self.collectorAddress = \
@@ -298,15 +308,6 @@ class OONIBReporter(OReporter):
config.tor.socks_port)
self.agent = SOCKS5Agent(reactor, proxyEndpoint=proxyEndpoint)
- elif self.collectorAddress.startswith('https://'):
- # not sure if there's something else it needs. Seems to work.
- # Very difficult to get it to work with self-signed certs.
- self.agent = Agent(reactor)
-
- elif self.collectorAddress.startswith('http://'):
- log.msg("Warning using unencrypted collector")
- self.agent = Agent(reactor)
-
url = self.collectorAddress + '/report'
content = '---\n'
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits