[tor-commits] [tor/master] Add FallbackDir list to GETINFO config/defaults
nickm at torproject.org
nickm at torproject.org
Thu Jan 7 17:20:09 UTC 2016
commit 3bc45f2628b8f9f979835503b42f6ae103dbd703
Author: George Tankersley <george.tankersley at gmail.com>
Date: Thu Dec 10 22:55:42 2015 -0800
Add FallbackDir list to GETINFO config/defaults
---
changes/feature16774 | 3 +++
src/or/config.c | 45 +++++++++++++++++++++++++++++++++++++--------
src/test/test_config.c | 4 +++-
3 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/changes/feature16774 b/changes/feature16774
new file mode 100644
index 0000000..87ba488
--- /dev/null
+++ b/changes/feature16774
@@ -0,0 +1,3 @@
+ o Minor enhancement:
+ - Adds FallbackDir entries to 'GETINFO config/defaults'. Closes ticket
+ #16774 and 17817. Patch by George Tankersley.
diff --git a/src/or/config.c b/src/or/config.c
index a1f8e49..ff25a79 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -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);
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 1b9e84d..097fe15 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -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);
More information about the tor-commits
mailing list