From 84bfa895d725338d92f677a31a4dcf6381845e0c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 29 Nov 2016 11:47:12 -0500 Subject: Change return value of entry_guard_succeeded to an enum. George pointed out that (-1,0,1) for (never usable, maybe usable later, usable right now) was a pretty rotten convention that made the code harder to read. --- src/or/circuitbuild.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/or/circuitbuild.c') diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 5d0a04fe71..c7e116e853 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -964,28 +964,29 @@ circuit_send_next_onion_skin(origin_circuit_t *circ) memset(&ec, 0, sizeof(ec)); if (!hop) { /* done building the circuit. whew. */ - int r; + guard_usable_t r; if (get_options()->UseDeprecatedGuardAlgorithm) { // The circuit is usable; we already marked the guard as okay. - r = 1; + r = GUARD_USABLE_NOW; } else if (! circ->guard_state) { if (circuit_get_cpath_len(circ) != 1) { log_warn(LD_BUG, "%d-hop circuit %p with purpose %d has no " "guard state", circuit_get_cpath_len(circ), circ, circ->base_.purpose); } - r = 1; + r = GUARD_USABLE_NOW; } else { r = entry_guard_succeeded(&circ->guard_state); } - const int is_usable_for_streams = (r == 1); - if (r == 1) { + const int is_usable_for_streams = (r == GUARD_USABLE_NOW); + if (r == GUARD_USABLE_NOW) { circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_OPEN); - } else if (r == 0) { + } else if (r == GUARD_MAYBE_USABLE_LATER) { // XXXX prop271 we might want to probe for whether this // XXXX one is ready even before the next second rolls over. circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_GUARD_WAIT); } else { + tor_assert_nonfatal(r == GUARD_USABLE_NEVER); return - END_CIRC_REASON_INTERNAL; } -- cgit v1.2.3-54-g00ecf