Remember which of our guards are directory caches

This commit is contained in:
Nick Mathewson 2012-12-11 11:43:27 -05:00
parent a7c6b4ab91
commit 1df7289000
2 changed files with 24 additions and 1 deletions

View File

@ -125,6 +125,15 @@ entry_guard_set_status(entry_guard_t *e, const node_t *node,
control_event_guard(e->nickname, e->identity, "GOOD"); control_event_guard(e->nickname, e->identity, "GOOD");
changed = 1; changed = 1;
} }
if (node) {
int is_dir = node_is_dir(node) != 0;
if (e->is_dir_cache != is_dir) {
e->is_dir_cache = is_dir;
changed = 1;
}
}
return changed; return changed;
} }
@ -341,6 +350,7 @@ add_an_entry_guard(const node_t *chosen, int reset_status, int prepend)
node_describe(node)); node_describe(node));
strlcpy(entry->nickname, node_get_nickname(node), sizeof(entry->nickname)); strlcpy(entry->nickname, node_get_nickname(node), sizeof(entry->nickname));
memcpy(entry->identity, node->identity, DIGEST_LEN); memcpy(entry->identity, node->identity, DIGEST_LEN);
entry->is_dir_cache = node_is_dir(node) != 0;
/* Choose expiry time smudged over the past month. The goal here /* Choose expiry time smudged over the past month. The goal here
* is to a) spread out when Tor clients rotate their guards, so they * is to a) spread out when Tor clients rotate their guards, so they
* don't all select them on the same day, and b) avoid leaving a * don't all select them on the same day, and b) avoid leaving a
@ -972,6 +982,17 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
"Bad hex digest for EntryGuard"); "Bad hex digest for EntryGuard");
} }
} }
if (smartlist_len(args) >= 3) {
const char *is_cache = smartlist_get(args, 2);
if (!strcasecmp(is_cache, "DirCache")) {
node->is_dir_cache = 1;
} else if (!strcasecmp(is_cache, "NoDirCache")) {
node->is_dir_cache = 0;
} else {
log_warn(LD_CONFIG, "Bogus third argument to EntryGuard line: %s",
escaped(is_cache));
}
}
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp)); SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
smartlist_free(args); smartlist_free(args);
if (*msg) if (*msg)
@ -1138,7 +1159,8 @@ entry_guards_update_state(or_state_t *state)
*next = line = tor_malloc_zero(sizeof(config_line_t)); *next = line = tor_malloc_zero(sizeof(config_line_t));
line->key = tor_strdup("EntryGuard"); line->key = tor_strdup("EntryGuard");
base16_encode(dbuf, sizeof(dbuf), e->identity, DIGEST_LEN); base16_encode(dbuf, sizeof(dbuf), e->identity, DIGEST_LEN);
tor_asprintf(&line->value, "%s %s", e->nickname, dbuf); tor_asprintf(&line->value, "%s %s %sDirCache", e->nickname, dbuf,
e->is_dir_cache ? "" : "No");
next = &(line->next); next = &(line->next);
if (e->unreachable_since) { if (e->unreachable_since) {
*next = line = tor_malloc_zero(sizeof(config_line_t)); *next = line = tor_malloc_zero(sizeof(config_line_t));

View File

@ -35,6 +35,7 @@ typedef struct entry_guard_t {
* for this node already? */ * for this node already? */
unsigned int path_bias_disabled : 1; /**< Have we disabled this node because unsigned int path_bias_disabled : 1; /**< Have we disabled this node because
* of path bias issues? */ * of path bias issues? */
unsigned int is_dir_cache : 1; /**< DOCDOC */
time_t bad_since; /**< 0 if this guard is currently usable, or the time at time_t bad_since; /**< 0 if this guard is currently usable, or the time at
* which it was observed to become (according to the * which it was observed to become (according to the
* directory or the user configuration) unusable. */ * directory or the user configuration) unusable. */