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.)
This commit is contained in:
Nick Mathewson 2016-11-14 11:41:37 -05:00
parent 4614f8e681
commit 22f2f13f81
4 changed files with 25 additions and 7 deletions

View File

@ -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"

View File

@ -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);
}
});

View File

@ -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. */

View File

@ -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,