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

[tor-commits] [ooni-probe/master] Switch to using threads.deferToThread() in method deferMakeConnection().



commit f69452eac1cf5334ab84caab260cbfcaf3adc2dd
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Thu Feb 28 18:35:49 2013 +0000

    Switch to using threads.deferToThread() in method deferMakeConnection().
---
 nettests/experimental/tls_handshake.py |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/nettests/experimental/tls_handshake.py b/nettests/experimental/tls_handshake.py
index 48902b3..ddef435 100644
--- a/nettests/experimental/tls_handshake.py
+++ b/nettests/experimental/tls_handshake.py
@@ -696,15 +696,23 @@ class TLSHandshakeTest(nettest.NetTestCase):
             self.report['host'] = host
             self.report['port'] = port
 
-        @defer.inlineCallbacks
-        def deferMakeConnection(host):
-            connection = yield makeConnection(host)
-            if isinstance(connection, Failure) \
-                    or isinstance(connection, Exception):
-                failed = connectionFailed(connection, host)
-                defer.returnValue(failed)
+            if isinstance(connection, Exception) \
+                    or isinstance(connection, ConnectionTimeout):
+                log.msg("Handshake failed with reason: %s" % connection.message)
+                self.report['state'] = connection.message
+            elif isinstance(connection, failure.Failure):
+                log.msg("Handshake failed with reason: Socket %s"
+                        % connection.getErrorMessage())
+                self.report['state'] = connection.getErrorMessage()
+                ctmo = connection.trap(ConnectionTimeout)
+                if ctmo == ConnectionTimeout:
+                    connection.cleanFailure()
             else:
-                defer.returnValue(connection)
+                log.msg("Handshake failed with reason: %s" % str(connection))
+                if not 'state' in self.report.keys():
+                    self.report['state'] = str(connection)
+
+            return None
 
         connection = deferMakeConnection(self.input)
         connection.addCallbacks(connectionSucceeded, connectionFailed,



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