Merge remote-tracking branch 'gtank/feature16774-squashed'

This commit is contained in:
Nick Mathewson 2016-01-07 09:20:03 -08:00
commit 5ba7b1a74d
3 changed files with 43 additions and 9 deletions

3
changes/feature16774 Normal file
View File

@ -0,0 +1,3 @@
o Minor enhancement:
- Adds FallbackDir entries to 'GETINFO config/defaults'. Closes ticket
#16774 and 17817. Patch by George Tankersley.

View File

@ -938,6 +938,14 @@ static const char *default_authorities[] = {
NULL
};
/** List of fallback directory authorities. The list is generated by opt-in of
* relays that meet certain stability criteria.
*/
static const char *default_fallbacks[] = {
#include "fallback_dirs.inc"
NULL
};
/** Add the default directory authorities directly into the trusted dir list,
* but only add them insofar as they share bits with <b>type</b>.
* Each authority's bits are restricted to the bits shared with <b>type</b>.
@ -960,14 +968,10 @@ MOCK_IMPL(void,
add_default_fallback_dir_servers,(void))
{
int i;
const char *fallback[] = {
#include "fallback_dirs.inc"
NULL
};
for (i=0; fallback[i]; i++) {
if (parse_dir_fallback_line(fallback[i], 0)<0) {
for (i=0; default_fallbacks[i]; i++) {
if (parse_dir_fallback_line(default_fallbacks[i], 0)<0) {
log_err(LD_BUG, "Couldn't parse internal FallbackDir line %s",
fallback[i]);
default_fallbacks[i]);
}
}
}
@ -7390,7 +7394,7 @@ getinfo_helper_config(control_connection_t *conn,
smartlist_free(sl);
} else if (!strcmp(question, "config/defaults")) {
smartlist_t *sl = smartlist_new();
int i, dirauth_lines_seen = 0;
int i, dirauth_lines_seen = 0, fallback_lines_seen = 0;
for (i = 0; option_vars_[i].name; ++i) {
const config_var_t *var = &option_vars_[i];
if (var->initvalue != NULL) {
@ -7401,6 +7405,13 @@ getinfo_helper_config(control_connection_t *conn,
*/
++dirauth_lines_seen;
}
if (strcmp(option_vars_[i].name, "FallbackDir") == 0) {
/*
* Similarly count fallback lines, so that we can decided later
* to add the defaults manually.
*/
++fallback_lines_seen;
}
char *val = esc_for_log(var->initvalue);
smartlist_add_asprintf(sl, "%s %s\n",var->name,val);
tor_free(val);
@ -7426,6 +7437,24 @@ getinfo_helper_config(control_connection_t *conn,
}
}
if (fallback_lines_seen == 0 &&
get_options()->UseDefaultFallbackDirs == 1) {
/*
* We didn't see any explicitly configured fallback mirrors,
* so add the defaults to the list manually.
*
* default_fallbacks is included earlier in this file and
* is a const char ** NULL-terminated array of fallback config lines.
*/
const char **i;
for (i = default_fallbacks; *i != NULL; ++i) {
char *val = esc_for_log(*i);
smartlist_add_asprintf(sl, "FallbackDir %s\n", val);
tor_free(val);
}
}
*answer = smartlist_join_strings(sl, "", 0, NULL);
SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
smartlist_free(sl);

View File

@ -3421,9 +3421,11 @@ test_config_default_dir_servers(void *arg)
int trusted_count = 0;
int fallback_count = 0;
/* new set of options should stop fallback parsing */
opts = tor_malloc_zero(sizeof(or_options_t));
opts->UseDefaultFallbackDirs = 0;
consider_adding_dir_servers(opts, opts);
/* set old_options to NULL to force dir update */
consider_adding_dir_servers(opts, NULL);
trusted_count = smartlist_len(router_get_trusted_dir_servers());
fallback_count = smartlist_len(router_get_fallback_dir_servers());
or_options_free(opts);