[tor-commits] [tor/master] prop271: make entry_guard_t mostly-private

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


commit 22f2f13f81407cffd46d5b17eca4bcead347fe58
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Nov 14 11:41:37 2016 -0500

    prop271: make entry_guard_t mostly-private
    
    The entry_guard_t structure should really be opaque, so that we
    can change its contents and have the rest of Tor not care.
    
    This commit makes it "mostly opaque" -- circpathbias.c can still see
    inside it.  (I'm making circpathbias.c exempt since it's the only
    part of Tor outside of entrynodes.c that made serious use of
    entry_guard_t internals.)
---
 src/or/circpathbias.c |  3 +++
 src/or/circuitbuild.c |  2 +-
 src/or/entrynodes.c   |  9 +++++++++
 src/or/entrynodes.h   | 18 ++++++++++++------
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/or/circpathbias.c b/src/or/circpathbias.c
index 6ee69aa..2968607 100644
--- a/src/or/circpathbias.c
+++ b/src/or/circpathbias.c
@@ -21,6 +21,9 @@
  * each guard, and stored persistently in the state file.
  */
 
+/* XXXX prop271 I would like to remove this. */
+#define ENTRYNODES_EXPOSE_STRUCT
+
 #include "or.h"
 #include "channel.h"
 #include "circpathbias.h"
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 0881f23..2998f5c 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2238,7 +2238,7 @@ choose_good_entry_server(uint8_t purpose, cpath_build_state_t *state)
      )) {
     SMARTLIST_FOREACH(get_entry_guards(), const entry_guard_t *, entry,
       {
-        if ((node = node_get_by_id(entry->identity))) {
+        if ((node = entry_guard_find_node(entry))) {
           nodelist_add_node_and_family(excluded, node);
         }
       });
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index b3fa31d..434f2f6 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -405,6 +405,15 @@ entry_guard_get_by_id_digest_for_guard_selection(guard_selection_t *gs,
   return NULL;
 }
 
+/** Return the node_t associated with a single entry_guard_t. May
+ * return NULL if the guard is not currently in the consensus. */
+const node_t *
+entry_guard_find_node(const entry_guard_t *guard)
+{
+  tor_assert(guard);
+  return node_get_by_id(guard->identity);
+}
+
 /** If <b>digest</b> matches the identity of any node in the
  * entry_guards list for the default guard selection state,
  return that node. Else return NULL. */
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index 00f9691..7f5a911 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -12,18 +12,18 @@
 #ifndef TOR_ENTRYNODES_H
 #define TOR_ENTRYNODES_H
 
-#if 1
-/* XXXX NM I would prefer that all of this stuff be private to
- * entrynodes.c. */
-
 /* Forward declare for guard_selection_t; entrynodes.c has the real struct */
 typedef struct guard_selection_s guard_selection_t;
 
+/* Forward declare for entry_guard_t; the real declaration is private. */
+typedef struct entry_guard_t entry_guard_t;
+
+#if defined(ENTRYNODES_PRIVATE) || defined(ENTRYNODES_EXPOSE_STRUCT)
 /** An entry_guard_t represents our information about a chosen long-term
  * first hop, known as a "helper" node in the literature. We can't just
  * use a node_t, since we want to remember these even when we
  * don't have any directory info. */
-typedef struct entry_guard_t {
+struct entry_guard_t {
   char nickname[MAX_NICKNAME_LEN+1];
   char identity[DIGEST_LEN];
   time_t chosen_on_date; /**< Approximately when was this guard added?
@@ -80,8 +80,12 @@ typedef struct entry_guard_t {
   double use_successes; /**< Number of successfully used circuits using
                                * this guard as first hop. */
   /**@}*/
-} entry_guard_t;
+};
+#endif
 
+#if 1
+/* XXXX NM I would prefer that all of this stuff be private to
+ * entrynodes.c. */
 entry_guard_t *entry_guard_get_by_id_digest_for_guard_selection(
     guard_selection_t *gs, const char *digest);
 entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
@@ -98,6 +102,8 @@ int num_live_entry_guards(int for_directory);
 
 #endif
 
+const node_t *entry_guard_find_node(const entry_guard_t *guard);
+
 #ifdef ENTRYNODES_PRIVATE
 STATIC const node_t *add_an_entry_guard(guard_selection_t *gs,
                                         const node_t *chosen,





More information about the tor-commits mailing list