diff options
author | George Kadianakis <desnacked@riseup.net> | 2016-12-06 14:35:31 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-12-16 11:06:22 -0500 |
commit | 50783d0123c38c649851421f33c616e0bf75d827 (patch) | |
tree | 499c39e92cf66196044a58a4761474fedd26d1f9 | |
parent | 7ab2678074e5d49628d948fadb80c5904950236c (diff) | |
download | tor-50783d0123c38c649851421f33c616e0bf75d827.tar.gz tor-50783d0123c38c649851421f33c616e0bf75d827.zip |
Easy code fixes.
- Correctly maintain the previous guard selection in choose_guard_selection().
- Print bridge identifier instead of nothing in entry_guard_describe()._
-rw-r--r-- | src/or/entrynodes.c | 19 | ||||
-rw-r--r-- | src/or/entrynodes.h | 6 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c index a28603d98d..bcf4182640 100644 --- a/src/or/entrynodes.c +++ b/src/or/entrynodes.c @@ -341,7 +341,8 @@ entry_guard_describe(const entry_guard_t *guard) static char buf[256]; tor_snprintf(buf, sizeof(buf), "%s ($%s)", - guard->nickname, hex_str(guard->identity, DIGEST_LEN)); + guard->nickname ? guard->nickname : "[bridge]", + hex_str(guard->identity, DIGEST_LEN)); return buf; } @@ -527,7 +528,7 @@ get_extreme_restriction_threshold(void) STATIC const char * choose_guard_selection(const or_options_t *options, const networkstatus_t *live_ns, - const char *old_selection, + const guard_selection_t *old_selection, guard_selection_type_t *type_out) { tor_assert(options); @@ -607,7 +608,11 @@ choose_guard_selection(const or_options_t *options, } } - /* Trickier case: we do have a previous selection */ + /* Trickier case: we do have a previous guard selection context. */ + tor_assert(old_selection); + + /* Use high and low thresholds to decide guard selection, and if we fall in + the middle then keep the current guard selection context. */ if (n_passing_filter >= meaningful_threshold_high) { *type_out = GS_TYPE_NORMAL; return "default"; @@ -615,7 +620,9 @@ choose_guard_selection(const or_options_t *options, *type_out = GS_TYPE_RESTRICTED; return "restricted"; } else { - return NULL; + /* we are in the middle: maintain previous guard selection */ + *type_out = old_selection->type; + return old_selection->name; } } @@ -634,16 +641,16 @@ update_guard_selection_choice(const or_options_t *options) return 1; } - const char *cur_name = curr_guard_context->name; guard_selection_type_t type = GS_TYPE_INFER; const char *new_name = choose_guard_selection( options, networkstatus_get_live_consensus(approx_time()), - cur_name, + curr_guard_context, &type); tor_assert(new_name); tor_assert(type != GS_TYPE_INFER); + const char *cur_name = curr_guard_context->name; if (! strcmp(cur_name, new_name)) { log_debug(LD_GUARD, "Staying with guard context \"%s\" (no change)", new_name); diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h index 116e5abb8c..11335255e2 100644 --- a/src/or/entrynodes.h +++ b/src/or/entrynodes.h @@ -519,9 +519,9 @@ STATIC void guard_selection_free(guard_selection_t *gs); MOCK_DECL(STATIC int, entry_guard_is_listed, (guard_selection_t *gs, const entry_guard_t *guard)); STATIC const char *choose_guard_selection(const or_options_t *options, - const networkstatus_t *ns, - const char *old_selection, - guard_selection_type_t *type_out); + const networkstatus_t *ns, + const guard_selection_t *old_selection, + guard_selection_type_t *type_out); STATIC entry_guard_t *get_sampled_guard_with_id(guard_selection_t *gs, const uint8_t *rsa_id); |