[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Easy code fixes.
commit 50783d0123c38c649851421f33c616e0bf75d827
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Tue Dec 6 14:35:31 2016 -0500
Easy code fixes.
- Correctly maintain the previous guard selection in choose_guard_selection().
- Print bridge identifier instead of nothing in entry_guard_describe()._
---
src/or/entrynodes.c | 19 +++++++++++++------
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 a28603d..bcf4182 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 116e5ab..1133525 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);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits