[tor-commits] [tor/master] Extract guard_selection_infer_type into its own function.

nickm at torproject.org nickm at torproject.org
Fri Dec 16 16:26:19 UTC 2016


commit 217590ad05943968683f02c3f556b987e99158b1
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Nov 30 10:16:24 2016 -0500

    Extract guard_selection_infer_type into its own function.
---
 src/or/entrynodes.c | 24 ++++++++++++++++++------
 src/or/entrynodes.h |  3 +++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 02ed924..9441be4 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -194,14 +194,13 @@ should_apply_guardfraction(const networkstatus_t *ns)
 }
 
 /**
- * Allocate and return a new guard_selection_t, with the name <b>name</b>.
+ * Try to determine the correct type for a selection named "name",
+ * if <b>type</b> is GS_TYPE_INFER.
  */
-STATIC guard_selection_t *
-guard_selection_new(const char *name,
-                    guard_selection_type_t type)
+STATIC guard_selection_type_t
+guard_selection_infer_type(guard_selection_type_t type,
+                           const char *name)
 {
-  guard_selection_t *gs;
-
   if (type == GS_TYPE_INFER) {
     if (!strcmp(name, "legacy"))
       type = GS_TYPE_LEGACY;
@@ -212,6 +211,19 @@ guard_selection_new(const char *name,
     else
       type = GS_TYPE_NORMAL;
   }
+  return type;
+}
+
+/**
+ * Allocate and return a new guard_selection_t, with the name <b>name</b>.
+ */
+STATIC guard_selection_t *
+guard_selection_new(const char *name,
+                    guard_selection_type_t type)
+{
+  guard_selection_t *gs;
+
+  type = guard_selection_infer_type(type, name);
 
   gs = tor_malloc_zero(sizeof(*gs));
   gs->name = tor_strdup(name);
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index 753d6f7..b676172 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -490,6 +490,9 @@ STATIC double get_extreme_restriction_threshold(void);
 
 // ---------- XXXX these functions and definitions are post-prop271.
 HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
+STATIC guard_selection_type_t guard_selection_infer_type(
+                           guard_selection_type_t type_in,
+                           const char *name);
 STATIC guard_selection_t *guard_selection_new(const char *name,
                                               guard_selection_type_t type);
 STATIC guard_selection_t *get_guard_selection_by_name(





More information about the tor-commits mailing list