]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'teor/feature15775-fallback-v9-squashed'
authorNick Mathewson <nickm@torproject.org>
Tue, 15 Dec 2015 19:04:00 +0000 (14:04 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 15 Dec 2015 19:04:00 +0000 (14:04 -0500)
1  2 
.gitignore
src/or/config.c
src/or/include.am
src/or/routerlist.c
src/test/test_config.c

diff --cc .gitignore
Simple merge
diff --cc src/or/config.c
Simple merge
Simple merge
Simple merge
index 0137d1c49a09a76b15c476b89fda370b2848d2c8,00489d1d1a6e4f5a4962bca6427bf5da3fcecc80..53fc693a336112a1edbe97d5f5fc40114626ddeb
@@@ -3411,98 -3195,39 +3411,126 @@@ test_config_adding_dir_servers(void *ar
    UNMOCK(add_default_fallback_dir_servers);
  }
  
 +static void
 +test_config_default_dir_servers(void *arg)
 +{
 +  or_options_t *opts = NULL;
 +  (void)arg;
 +  int trusted_count = 0;
 +  int fallback_count = 0;
 +
 +  opts = tor_malloc_zero(sizeof(or_options_t));
 +  opts->UseDefaultFallbackDirs = 0;
 +  consider_adding_dir_servers(opts, opts);
 +  trusted_count = smartlist_len(router_get_trusted_dir_servers());
 +  fallback_count = smartlist_len(router_get_fallback_dir_servers());
 +  or_options_free(opts);
 +  opts = NULL;
 +
 +  /* assume a release will never go out with less than 7 authorities */
 +  tt_assert(trusted_count >= 7);
 +  /* if we disable the default fallbacks, there must not be any extra */
 +  tt_assert(fallback_count == trusted_count);
 +
 +  opts = tor_malloc_zero(sizeof(or_options_t));
 +  opts->UseDefaultFallbackDirs = 1;
 +  consider_adding_dir_servers(opts, opts);
 +  trusted_count = smartlist_len(router_get_trusted_dir_servers());
 +  fallback_count = smartlist_len(router_get_fallback_dir_servers());
 +  or_options_free(opts);
 +  opts = NULL;
 +
 +  /* assume a release will never go out with less than 7 authorities */
 +  tt_assert(trusted_count >= 7);
 +  /* XX/teor - allow for default fallbacks to be added without breaking
 +   * the unit tests. Set a minimum fallback count once the list is stable. */
 +  tt_assert(fallback_count >= trusted_count);
 +
 + done:
 +  or_options_free(opts);
 +}
 +
 +static void
 +test_config_use_multiple_directories(void *arg)
 +{
 +  (void)arg;
 +
 +  or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
 +
 +  /* Clients can use multiple directory mirrors for bootstrap */
 +  memset(options, 0, sizeof(or_options_t));
 +  options->ClientOnly = 1;
 +  tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
 +            == 1);
 +
 +  /* Bridge Clients can use multiple directory mirrors for bootstrap */
 +  memset(options, 0, sizeof(or_options_t));
 +  options->UseBridges = 1;
 +  tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
 +            == 1);
 +
 +  /* Bridge Relays (Bridges) must act like clients, and use multiple
 +   * directory mirrors for bootstrap */
 +  memset(options, 0, sizeof(or_options_t));
 +  options->BridgeRelay = 1;
 +  tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
 +            == 1);
 +
 +  /* Clients set to FetchDirInfoEarly must fetch it from the authorities */
 +  memset(options, 0, sizeof(or_options_t));
 +  options->FetchDirInfoEarly = 1;
 +  tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
 +            == 0);
 +
 +  /* OR servers must fetch the consensus from the authorities */
 +  memset(options, 0, sizeof(or_options_t));
 +  options->ORPort_set = 1;
 +  tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
 +            == 0);
 +
 + done:
 +  tor_free(options);
 +}
 +
+ static void
+ test_config_default_fallback_dirs(void *arg)
+ {
+   const char *fallback[] = {
+ #include "../or/fallback_dirs.inc"
+     NULL
+   };
+   int n_included_fallback_dirs = 0;
+   int n_added_fallback_dirs = 0;
+   (void)arg;
+   clear_dir_servers();
+   while (fallback[n_included_fallback_dirs])
+     n_included_fallback_dirs++;
+   add_default_fallback_dir_servers();
+   n_added_fallback_dirs = smartlist_len(router_get_fallback_dir_servers());
+   tt_assert(n_included_fallback_dirs == n_added_fallback_dirs);
+   done:
+   clear_dir_servers();
+ }
  #define CONFIG_TEST(name, flags)                          \
    { #name, test_config_ ## name, flags, NULL, NULL }
  
  struct testcase_t config_tests[] = {
 -  CONFIG_TEST(adding_dir_servers, 0),
 +  CONFIG_TEST(adding_trusted_dir_server, TT_FORK),
 +  CONFIG_TEST(adding_fallback_dir_server, TT_FORK),
 +  CONFIG_TEST(parsing_trusted_dir_server, 0),
 +  CONFIG_TEST(parsing_fallback_dir_server, 0),
 +  CONFIG_TEST(adding_default_trusted_dir_servers, TT_FORK),
 +  CONFIG_TEST(adding_dir_servers, TT_FORK),
 +  CONFIG_TEST(default_dir_servers, TT_FORK),
+   CONFIG_TEST(default_fallback_dirs, 0),
    CONFIG_TEST(resolve_my_address, TT_FORK),
    CONFIG_TEST(addressmap, 0),
    CONFIG_TEST(parse_bridge_line, 0),