Commit 92f2dab7 authored by juga's avatar juga
Browse files

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.
parent f9c5a9dc
......@@ -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'
......
......@@ -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
......
......@@ -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:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment