diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-11-14 11:41:37 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-11-30 14:42:52 -0500 |
commit | 22f2f13f81407cffd46d5b17eca4bcead347fe58 (patch) | |
tree | 75f66d34b6951af5e1e6f0cf89a51475ef649cd2 | |
parent | 4614f8e6816d559f8fbe9ae0f42d751d3fb95c77 (diff) | |
download | tor-22f2f13f81407cffd46d5b17eca4bcead347fe58.tar.gz tor-22f2f13f81407cffd46d5b17eca4bcead347fe58.zip |
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.)
-rw-r--r-- | src/or/circpathbias.c | 3 | ||||
-rw-r--r-- | src/or/circuitbuild.c | 2 | ||||
-rw-r--r-- | src/or/entrynodes.c | 9 | ||||
-rw-r--r-- | 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 6ee69aac1e..2968607f1b 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 0881f231aa..2998f5c602 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 b3fa31df7b..434f2f6222 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 00f96916b6..7f5a9110c9 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, |