[tor-commits] [sbws/master] circuitbuilder: return a tuple with the error

juga at torproject.org juga at torproject.org
Fri Dec 21 09:13:44 UTC 2018


commit 92f2dab747711f9b9fadd8675685941c9ffe0357
Author: juga0 <juga at riseup.net>
Date:   Sun Dec 9 08:58:48 2018 +0000

    circuitbuilder: return a tuple with the error
    
    obtained when trying to build the circuit, or None if it was
    successful.
    That way it can be logged and stored in the results.
---
 sbws/core/scanner.py       |  2 +-
 sbws/lib/circuitbuilder.py | 12 +++++++++---
 sbws/lib/destination.py    |  3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index a9b4959..5406a74 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -196,7 +196,7 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
     assert circ_fps is not None and len(circ_fps) == 2
     # Build the circuit
     our_nick = conf['scanner']['nickname']
-    circ_id = cb.build_circuit(circ_fps)
+    circ_id, reason = cb.build_circuit(circ_fps)
     if not circ_id:
         log.warning('Could not build circuit involving %s', relay.nickname)
         msg = 'Unable to complete circuit'
diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index e3b3950..2546f0a 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -68,23 +68,29 @@ class CircuitBuilder:
             log.exception("Error trying to get circuit to close it: %s.", e)
 
     def _build_circuit_impl(self, path):
+        """
+        :returns tuple: circuit id if the circuit was built, error if there
+            was an error building the circuit.
+        """
         if not valid_circuit_length(path):
             raise PathLengthException()
         c = self.controller
         timeout = self.circuit_timeout
         fp_path = '[' + ' -> '.join([p[0:8] for p in path]) + ']'
         log.debug('Building %s', fp_path)
+        error = None
         for _ in range(0, 3):
             try:
                 circ_id = c.new_circuit(
                     path, await_build=True, timeout=timeout)
             except (InvalidRequest, CircuitExtensionFailed,
                     ProtocolError, Timeout) as e:
-                log.warning(e)
+                log.debug(e)
+                error = str(e)
                 continue
             else:
-                return circ_id
-        return None
+                return circ_id, None
+        return None, error
 
     def __del__(self):
         c = self.controller
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index 1b4c192..c081f89 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -194,7 +194,8 @@ class DestinationList:
             for _ in range(0, 3):
                 # Pick a random exit
                 exit = self._rng.choice(exits)
-                circ_id = self._cb.build_circuit([None, exit.fingerprint])
+                circ_id, reason = \
+                        self._cb.build_circuit([None, exit.fingerprint])
                 if circ_id:
                     break
             if not circ_id:





More information about the tor-commits mailing list