[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Implement a hotfix for https://github.com/habnabit/txsocksx/issues/9



commit 96391035de250a2d5842c5c0e68879f1838eb874
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Wed Feb 4 11:18:05 2015 +0100

    Implement a hotfix for https://github.com/habnabit/txsocksx/issues/9
---
 ooni/oonibclient.py       |    3 ++-
 ooni/reporter.py          |    2 +-
 ooni/utils/hacks.py       |   29 +++++++++++++++++++++++++++++
 ooni/utils/trueheaders.py |    2 +-
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py
index a26b771..126eeb7 100644
--- a/ooni/oonibclient.py
+++ b/ooni/oonibclient.py
@@ -203,7 +203,8 @@ class OONIBClient(object):
         try:
             test_collector = yield self.queryBackend('POST', '/bouncer/net-tests',
                                                      query={'net-tests': net_tests})
-        except Exception:
+        except Exception as exc:
+            log.exception(exc)
             raise e.CouldNotFindTestCollector
 
         defer.returnValue(test_collector)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 34ff333..bf4a645 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -287,7 +287,7 @@ class OONIBReporter(OReporter):
         # do this with some deferred kung foo or instantiate the reporter after
         # tor is started.
 
-        from txsocksx.http import SOCKS5Agent
+        from ooni.utils.hacks import SOCKS5Agent
         from twisted.internet import reactor
 
         if self.collectorAddress.startswith('httpo://'):
diff --git a/ooni/utils/hacks.py b/ooni/utils/hacks.py
index 2c84a23..e001d3f 100644
--- a/ooni/utils/hacks.py
+++ b/ooni/utils/hacks.py
@@ -2,6 +2,9 @@
 # hackish way, we put it in here. This one day will be empty.
 
 import copy_reg
+from twisted.web.client import SchemeNotSupported
+
+from txsocksx.http import SOCKS5Agent as SOCKS5AgentOriginal
 
 
 def patched_reduce_ex(self, proto):
@@ -56,3 +59,29 @@ def patched_reduce_ex(self, proto):
     else:
         return copy_reg._reconstructor, args
 
+
+class SOCKS5Agent(SOCKS5AgentOriginal):
+    """
+    This is a quick hack to fix:
+    https://github.com/habnabit/txsocksx/issues/9
+    """
+    def _getEndpoint(self, scheme_or_uri, host=None, port=None):
+        if host is not None:
+            scheme = scheme_or_uri
+        else:
+            scheme = scheme_or_uri.scheme
+            host = scheme_or_uri.host
+            port = scheme_or_uri.port
+        if scheme not in ('http', 'https'):
+            raise SchemeNotSupported('unsupported scheme', scheme)
+        endpoint = self.endpointFactory(
+            host, port, self.proxyEndpoint, **self.endpointArgs)
+        if scheme == 'https':
+            if hasattr(self, '_wrapContextFactory'):
+                tlsPolicy = self._wrapContextFactory(host, port)
+            elif hasattr(self, '_policyForHTTPS'):
+                tlsPolicy = self._policyForHTTPS.creatorForNetloc(host, port)
+            else:
+                raise NotImplementedError("can't figure out how to make a context factory")
+            endpoint = self._tlsWrapper(tlsPolicy, endpoint)
+        return endpoint
diff --git a/ooni/utils/trueheaders.py b/ooni/utils/trueheaders.py
index e5dcd0a..f015b62 100644
--- a/ooni/utils/trueheaders.py
+++ b/ooni/utils/trueheaders.py
@@ -12,7 +12,7 @@ from twisted.web._newclient import RequestNotSent, RequestGenerationFailed, Tran
 from twisted.internet import reactor
 from twisted.internet.defer import Deferred, fail, maybeDeferred, failure
 
-from txsocksx.http import SOCKS5Agent
+from ooni.utils.hacks import SOCKS5Agent
 from txsocksx.client import SOCKS5ClientFactory
 
 SOCKS5ClientFactory.noisy = False



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits