瀏覽代碼

Merge remote-tracking branch 'asn/remove_legacy_guards'

Nick Mathewson 7 年之前
父節點
當前提交
fae4d3d925
共有 14 個文件被更改,包括 51 次插入2492 次删除
  1. 2 18
      src/or/bridges.c
  2. 0 13
      src/or/channel.c
  3. 0 8
      src/or/circpathbias.c
  4. 1 24
      src/or/circuitbuild.c
  5. 0 4
      src/or/circuituse.c
  6. 0 20
      src/or/config.c
  7. 0 10
      src/or/connection_or.c
  8. 2 3
      src/or/directory.c
  9. 44 1367
      src/or/entrynodes.c
  10. 2 128
      src/or/entrynodes.h
  11. 0 12
      src/or/or.h
  12. 0 15
      src/or/routerlist.c
  13. 0 786
      src/test/test_entrynodes.c
  14. 0 84
      src/test/test_routerlist.c

+ 2 - 18
src/or/bridges.c

@@ -761,29 +761,13 @@ learned_bridge_descriptor(routerinfo_t *ri, int from_cache)
                    fmt_and_decorate_addr(&bridge->addr),
                    (int) bridge->port);
       }
-      if (get_options()->UseDeprecatedGuardAlgorithm) {
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-        add_bridge_as_entry_guard(get_guard_selection_info(), node);
-#else
-        tor_assert_nonfatal_unreached();
-#endif
-      } else {
-        entry_guard_learned_bridge_identity(&bridge->addrport_configured,
-                               (const uint8_t*)ri->cache_info.identity_digest);
-      }
+      entry_guard_learned_bridge_identity(&bridge->addrport_configured,
+                              (const uint8_t*)ri->cache_info.identity_digest);
 
       log_notice(LD_DIR, "new bridge descriptor '%s' (%s): %s", ri->nickname,
                  from_cache ? "cached" : "fresh", router_describe(ri));
       /* set entry->made_contact so if it goes down we don't drop it from
        * our entry node list */
-      if (get_options()->UseDeprecatedGuardAlgorithm) {
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-        entry_guard_register_connect_status(ri->cache_info.identity_digest,
-                                            1, 0, now);
-#else
-        tor_assert_nonfatal_unreached();
-#endif
-      }
       if (first) {
         routerlist_retry_directory_downloads(now);
       }

+ 0 - 13
src/or/channel.c

@@ -2577,19 +2577,6 @@ channel_do_open_actions(channel_t *chan)
   if (started_here) {
     circuit_build_times_network_is_live(get_circuit_build_times_mutable());
     rep_hist_note_connect_succeeded(chan->identity_digest, now);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-    // XXXX prop271 this call is no longer useful with the new algorithm.
-    if (entry_guard_register_connect_status(
-          chan->identity_digest, 1, 0, now) < 0) {
-      /* Close any circuits pending on this channel. We leave it in state
-       * 'open' though, because it didn't actually *fail* -- we just
-       * chose not to use it. */
-      log_debug(LD_OR,
-                "New entry guard was reachable, but closing this "
-                "connection so we can retry the earlier entry guards.");
-      close_origin_circuits = 1;
-    }
-#endif
     router_set_status(chan->identity_digest, 1);
   } else {
     /* only report it to the geoip module if it's not a known router */

+ 0 - 8
src/or/circpathbias.c

@@ -1279,10 +1279,6 @@ pathbias_measure_use_rate(entry_guard_t *guard)
                  tor_lround(pb->timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
           pb->path_bias_disabled = 1;
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-          // XXXX
-          entry_guard_mark_bad(guard);
-#endif
           return;
         }
       } else if (!pb->path_bias_use_extreme) {
@@ -1388,10 +1384,6 @@ pathbias_measure_close_rate(entry_guard_t *guard)
                  tor_lround(pb->timeouts),
                  tor_lround(get_circuit_build_close_time_ms()/1000));
           pb->path_bias_disabled = 1;
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-          // XXXX
-          entry_guard_mark_bad(guard);
-#endif
           return;
         }
       } else if (!pb->path_bias_extreme) {

+ 1 - 24
src/or/circuitbuild.c

@@ -967,10 +967,7 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
     if (!hop) {
       /* done building the circuit. whew. */
       guard_usable_t r;
-      if (get_options()->UseDeprecatedGuardAlgorithm) {
-        // The circuit is usable; we already marked the guard as okay.
-        r = GUARD_USABLE_NOW;
-      } else if (! circ->guard_state) {
+      if (! circ->guard_state) {
         if (circuit_get_cpath_len(circ) != 1 &&
             circ->base_.purpose != CIRCUIT_PURPOSE_TESTING &&
             get_options()->UseEntryGuards) {
@@ -2308,26 +2305,6 @@ choose_good_entry_server(uint8_t purpose, cpath_build_state_t *state,
      * family. */
     nodelist_add_node_and_family(excluded, node);
   }
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  /* and exclude current entry guards and their families,
-   * unless we're in a test network, and excluding guards
-   * would exclude all nodes (i.e. we're in an incredibly small tor network,
-   * or we're using TestingAuthVoteGuard *).
-   * This is an incomplete fix, but is no worse than the previous behaviour,
-   * and only applies to minimal, testing tor networks
-   * (so it's no less secure) */
-  if (options->UseEntryGuards
-      && (!options->TestingTorNetwork ||
-         smartlist_len(nodelist_get_list()) > smartlist_len(get_entry_guards())
-     )) {
-    SMARTLIST_FOREACH(get_entry_guards(), const entry_guard_t *, entry,
-      {
-        if ((node = entry_guard_find_node(entry))) {
-          nodelist_add_node_and_family(excluded, node);
-        }
-      });
-  }
-#endif
 
   if (state) {
     if (state->need_uptime)

+ 0 - 4
src/or/circuituse.c

@@ -1732,10 +1732,6 @@ circuit_build_failed(origin_circuit_t *circ)
       /* New guard API: we failed. */
       if (circ->guard_state)
         entry_guard_failed(&circ->guard_state);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-      /* Old guard API: we failed. */
-      entry_guard_register_connect_status(n_chan_id, 0, 1, time(NULL));
-#endif
       /* if there are any one-hop streams waiting on this circuit, fail
        * them now so they can retry elsewhere. */
       connection_ap_fail_onehop(n_chan_id, circ->build_state);

+ 0 - 20
src/or/config.c

@@ -317,9 +317,6 @@ static config_var_t option_vars_[] = {
   V(ExtraInfoStatistics,         BOOL,     "1"),
   V(ExtendByEd25519ID,           AUTOBOOL, "auto"),
   V(FallbackDir,                 LINELIST, NULL),
-  /* XXXX prop271 -- this has an ugly name to remind us to remove it. */
-  VAR("UseDeprecatedGuardAlgorithm_",        BOOL,
-      UseDeprecatedGuardAlgorithm, "0"),
 
   V(UseDefaultFallbackDirs,      BOOL,     "1"),
 
@@ -1587,7 +1584,6 @@ options_transition_affects_guards(const or_options_t *old,
 
   return
     (old->UseEntryGuards != new->UseEntryGuards ||
-     old->UseDeprecatedGuardAlgorithm != new->UseDeprecatedGuardAlgorithm ||
      old->UseBridges != new->UseBridges ||
      old->UseEntryGuards != new->UseEntryGuards ||
      old->ClientUseIPv4 != new->ClientUseIPv4 ||
@@ -2106,15 +2102,6 @@ options_act(const or_options_t *old_options)
       !options->BridgeAuthoritativeDir)
     rep_hist_desc_stats_term();
 
-  /* Check if we need to parse and add the EntryNodes config option. */
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  if (options->EntryNodes &&
-      (!old_options ||
-       !routerset_equal(old_options->EntryNodes,options->EntryNodes) ||
-       !routerset_equal(old_options->ExcludeNodes,options->ExcludeNodes)))
-    entry_nodes_should_be_added();
-#endif
-
   /* Since our options changed, we might need to regenerate and upload our
    * server descriptor.
    */
@@ -3018,13 +3005,6 @@ options_validate(or_options_t *old_options, or_options_t *options,
 
   warn_about_relative_paths(options);
 
-#ifndef ENABLE_LEGACY_GUARD_ALGORITHM
-  if (options->UseDeprecatedGuardAlgorithm) {
-    log_warn(LD_CONFIG, "DeprecatedGuardAlgorithm not supported.");
-    return -1;
-  }
-#endif
-
   if (server_mode(options) &&
       (!strcmpstart(uname, "Windows 95") ||
        !strcmpstart(uname, "Windows 98") ||

+ 0 - 10
src/or/connection_or.c

@@ -718,11 +718,6 @@ connection_or_about_to_close(or_connection_t *or_conn)
       rep_hist_note_connect_failed(or_conn->identity_digest, now);
       /* Tell the new guard API about the channel failure */
       entry_guard_chan_failed(TLS_CHAN_TO_BASE(or_conn->chan));
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-      /* Tell the old guard API about the channel failure */
-      entry_guard_register_connect_status(or_conn->identity_digest,0,
-                                          !options->HTTPSProxy, now);
-#endif
       if (conn->state >= OR_CONN_STATE_TLS_HANDSHAKING) {
         int reason = tls_error_to_orconn_end_reason(or_conn->tls_error);
         control_event_or_conn_status(or_conn, OR_CONN_EVENT_FAILED,
@@ -1728,11 +1723,6 @@ connection_or_client_learned_peer_id(or_connection_t *conn,
 
     /* Tell the new guard API about the channel failure */
     entry_guard_chan_failed(TLS_CHAN_TO_BASE(conn->chan));
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-    /* Tell the old guard API about the channel failure */
-    entry_guard_register_connect_status(conn->identity_digest, 0, 1,
-                                        time(NULL));
-#endif
     control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED,
                                  END_OR_CONN_REASON_OR_IDENTITY);
     if (!authdir_mode_tests_reachability(options))

+ 2 - 3
src/or/directory.c

@@ -469,7 +469,7 @@ directory_pick_generic_dirserver(dirinfo_type_t type, int pds_flags,
     log_warn(LD_BUG, "Called when we have UseBridges set.");
 
   if (should_use_directory_guards(options)) {
-    const node_t *node = guards_choose_dirguard(type, guard_state_out);
+    const node_t *node = guards_choose_dirguard(guard_state_out);
     if (node)
       rs = node->rs;
   } else {
@@ -559,8 +559,7 @@ MOCK_IMPL(void, directory_get_from_dirserver, (
        * sort of dir fetch we'll be doing, so it won't return a bridge
        * that can't answer our question.
        */
-      const node_t *node = guards_choose_dirguard(type,
-                                                  &guard_state);
+      const node_t *node = guards_choose_dirguard(&guard_state);
       if (node && node->ri) {
         /* every bridge has a routerinfo. */
         routerinfo_t *ri = node->ri;

File diff suppressed because it is too large
+ 44 - 1367
src/or/entrynodes.c


+ 2 - 128
src/or/entrynodes.h

@@ -28,11 +28,6 @@ typedef struct circuit_guard_state_t circuit_guard_state_t;
    private. */
 typedef struct entry_guard_restriction_t entry_guard_restriction_t;
 
-/*
-  XXXX Prop271 undefine this in order to disable all legacy guard functions.
-*/
-// #define ENABLE_LEGACY_GUARD_ALGORITHM
-
 /* Information about a guard's pathbias status.
  * These fields are used in circpathbias.c to try to detect entry
  * nodes that are failing circuits at a suspicious frequency.
@@ -179,37 +174,6 @@ struct entry_guard_t {
   guard_selection_t *in_selection;
   /**@}*/
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  /**
-   * @name legacy guard selection algorithm fields
-   *
-   * These are used and maintained by the legacy (pre-prop271) entry guard
-   * algorithm.  Most of them we will remove as prop271 gets implemented.
-   * The rest we'll migrate over, if they are 100% semantically identical to
-   * their prop271 equivalents. XXXXprop271
-   */
-  /**@{*/
-  time_t chosen_on_date; /**< Approximately when was this guard added?
-                          * "0" if we don't know. */
-  char *chosen_by_version; /**< What tor version added this guard? NULL
-                            * if we don't know. */
-  unsigned int made_contact : 1; /**< 0 if we have never connected to this
-                                  * router, 1 if we have. */
-  unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
-                               * in spite of having it marked as unreachable?*/
-  unsigned int is_dir_cache : 1; /**< Is this node a directory cache? */
-  time_t bad_since; /**< 0 if this guard is currently usable, or the time at
-                      * which it was observed to become (according to the
-                      * directory or the user configuration) unusable. */
-  time_t unreachable_since; /**< 0 if we can connect to this guard, or the
-                             * time at which we first noticed we couldn't
-                             * connect to it. */
-  time_t last_attempted; /**< 0 if we can connect to this guard, or the time
-                          * at which we last failed to connect to it. */
-
-  /**}@*/
-#endif
-
   /** Path bias information for this guard. */
   guard_pathbias_t pb;
 };
@@ -230,8 +194,6 @@ typedef enum guard_selection_type_t {
   /** Use the normal guard selection algorithm, taking our sample from the
    * set of filtered nodes. */
   GS_TYPE_RESTRICTED,
-  /** Use the legacy (pre-prop271) guard selection algorithm and fields */
-  GS_TYPE_LEGACY,
 } guard_selection_type_t;
 
 /**
@@ -305,20 +267,6 @@ struct guard_selection_s {
    * confirmed_entry_guards receive? */
   int next_confirmed_idx;
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  /**
-   * A list of our chosen entry guards, as entry_guard_t structures; this
-   * preserves the pre-Prop271 behavior.
-   */
-  smartlist_t *chosen_entry_guards;
-
-  /**
-   * When we try to choose an entry guard, should we parse and add
-   * config's EntryNodes first?  This was formerly a global.  This
-   * preserves the pre-Prop271 behavior.
-   */
-  int should_add_entry_nodes;
-#endif
 };
 
 struct entry_guard_handle_t;
@@ -366,8 +314,7 @@ struct circuit_guard_state_t {
 int guards_update_all(void);
 const node_t *guards_choose_guard(cpath_build_state_t *state,
                                   circuit_guard_state_t **guard_state_out);
-const node_t *guards_choose_dirguard(dirinfo_type_t info,
-                                     circuit_guard_state_t **guard_state_out);
+const node_t *guards_choose_dirguard(circuit_guard_state_t **guard_state_out);
 
 #if 1
 /* XXXX NM I would prefer that all of this stuff be private to
@@ -378,11 +325,6 @@ entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
 void entry_guards_changed_for_guard_selection(guard_selection_t *gs);
 void entry_guards_changed(void);
 guard_selection_t * get_guard_selection_info(void);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-const smartlist_t *get_entry_guards_for_guard_selection(
-    guard_selection_t *gs);
-const smartlist_t *get_entry_guards(void);
-#endif
 int num_live_entry_guards_for_guard_selection(
     guard_selection_t *gs,
     int for_directory);
@@ -390,9 +332,6 @@ int num_live_entry_guards(int for_directory);
 #endif
 
 const node_t *entry_guard_find_node(const entry_guard_t *guard);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-void entry_guard_mark_bad(entry_guard_t *guard);
-#endif
 const char *entry_guard_get_rsa_id_digest(const entry_guard_t *guard);
 const char *entry_guard_describe(const entry_guard_t *guard);
 guard_pathbias_t *entry_guard_get_pathbias_state(entry_guard_t *guard);
@@ -432,10 +371,6 @@ void entry_guards_note_internet_connectivity(guard_selection_t *gs);
 int update_guard_selection_choice(const or_options_t *options);
 
 /* Used by bridges.c only. */
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-void add_bridge_as_entry_guard(guard_selection_t *gs,
-                               const node_t *chosen);
-#endif
 int num_bridges_usable(void);
 
 #ifdef ENTRYNODES_PRIVATE
@@ -610,70 +545,14 @@ STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs,
                                                 entry_guard_t *guard,
                                                 unsigned old_state);
 STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b);
-STATIC char *getinfo_helper_format_single_entry_guard(const entry_guard_t *e,
-                                                      int is_legacy);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-// ---------- XXXX this stuff is pre-prop271.
-
-STATIC const node_t *add_an_entry_guard(guard_selection_t *gs,
-                                        const node_t *chosen,
-                                        int reset_status, int prepend,
-                                        int for_discovery, int for_directory);
-STATIC int populate_live_entry_guards(smartlist_t *live_entry_guards,
-                                      const smartlist_t *all_entry_guards,
-                                      const node_t *chosen_exit,
-                                      dirinfo_type_t dirinfo_type,
-                                      int for_directory,
-                                      int need_uptime, int need_capacity);
-STATIC int decide_num_guards(const or_options_t *options, int for_directory);
-
-STATIC void entry_guards_set_from_config(guard_selection_t *gs,
-                                         const or_options_t *options);
-
-/** Flags to be passed to entry_is_live() to indicate what kind of
- * entry nodes we are looking for. */
-typedef enum {
-  ENTRY_NEED_UPTIME = 1<<0,
-  ENTRY_NEED_CAPACITY = 1<<1,
-  ENTRY_ASSUME_REACHABLE = 1<<2,
-  ENTRY_NEED_DESCRIPTOR = 1<<3,
-} entry_is_live_flags_t;
-
-STATIC const node_t *entry_is_live(const entry_guard_t *e,
-                                   entry_is_live_flags_t flags,
-                                   const char **msg);
-
-STATIC int entry_is_time_to_retry(const entry_guard_t *e, time_t now);
-#endif
-
-#endif
-
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs);
-void remove_all_entry_guards(void);
+STATIC char *getinfo_helper_format_single_entry_guard(const entry_guard_t *e);
 #endif
 
 struct bridge_info_t;
 void entry_guard_learned_bridge_identity(const tor_addr_port_t *addrport,
                                          const uint8_t *rsa_id_digest);
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-void entry_guards_compute_status_for_guard_selection(
-    guard_selection_t *gs, const or_options_t *options, time_t now);
-void entry_guards_compute_status(const or_options_t *options, time_t now);
-int entry_guard_register_connect_status_for_guard_selection(
-    guard_selection_t *gs, const char *digest, int succeeded,
-    int mark_relay_status, time_t now);
-int entry_guard_register_connect_status(const char *digest, int succeeded,
-                                        int mark_relay_status, time_t now);
-void entry_nodes_should_be_added_for_guard_selection(guard_selection_t *gs);
-void entry_nodes_should_be_added(void);
-#endif
 int entry_list_is_constrained(const or_options_t *options);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-const node_t *choose_random_entry(cpath_build_state_t *state);
-const node_t *choose_random_dirguard(dirinfo_type_t t);
-#endif
 int guards_retry_optimistic(const or_options_t *options);
 int entry_guards_parse_state_for_guard_selection(
     guard_selection_t *gs, or_state_t *state, int set, char **msg);
@@ -682,11 +561,6 @@ void entry_guards_update_state(or_state_t *state);
 int getinfo_helper_entry_guards(control_connection_t *conn,
                                 const char *question, char **answer,
                                 const char **errmsg);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-int is_node_used_as_guard_for_guard_selection(guard_selection_t *gs,
-                                              const node_t *node);
-MOCK_DECL(int, is_node_used_as_guard, (const node_t *node));
-#endif
 
 int entries_known_but_down(const or_options_t *options);
 void entries_retry_all(const or_options_t *options);

+ 0 - 12
src/or/or.h

@@ -4574,14 +4574,6 @@ typedef struct {
    * do we enforce Ed25519 identity match? */
   /* NOTE: remove this option someday. */
   int AuthDirTestEd25519LinkKeys;
-
-  /** If 1, we use the old (pre-prop271) guard selection algorithm.
-   *
-   * XXXX prop271 This option is only here as a stopgap while we're
-   * XXXX tuning and debugging the new (post-prop271) algorithm.  Eventually
-   * we should remove it entirely.
-   */
-  int UseDeprecatedGuardAlgorithm;
 } or_options_t;
 
 /** Persistent state for an onion router, as saved to disk. */
@@ -5336,10 +5328,6 @@ typedef struct dir_server_t {
  */
 #define PDS_NO_EXISTING_MICRODESC_FETCH (1<<4)
 
-/** This node is to be chosen as a directory guard, so don't choose any
- * node that's currently a guard. */
-#define PDS_FOR_GUARD (1<<5)
-
 /** Possible ways to weight routers when choosing one randomly.  See
  * routerlist_sl_choose_by_bandwidth() for more information.*/
 typedef enum bandwidth_weight_rule_t {

+ 0 - 15
src/or/routerlist.c

@@ -1996,14 +1996,9 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags,
   const int fascistfirewall = ! (flags & PDS_IGNORE_FASCISTFIREWALL);
   const int no_serverdesc_fetching =(flags & PDS_NO_EXISTING_SERVERDESC_FETCH);
   const int no_microdesc_fetching = (flags & PDS_NO_EXISTING_MICRODESC_FETCH);
-  const int for_guard = (flags & PDS_FOR_GUARD);
   int try_excluding = 1, n_excluded = 0, n_busy = 0;
   int try_ip_pref = 1;
 
-#ifndef ENABLE_LEGACY_GUARD_ALGORITHM
-  tor_assert_nonfatal(! for_guard);
-#endif
-
   if (!consensus)
     return NULL;
 
@@ -2036,16 +2031,6 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags,
 
     SKIP_MISSING_TRUSTED_EXTRAINFO(type, node->identity);
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-    /* Don't make the same node a guard twice */
-     if (for_guard && is_node_used_as_guard(node)) {
-       continue;
-     }
-#endif
-    /* Ensure that a directory guard is actually a guard node. */
-    if (for_guard && !node->is_possible_guard) {
-      continue;
-    }
     if (try_excluding &&
         routerset_contains_routerstatus(options->ExcludeNodes, status,
                                         country)) {

+ 0 - 786
src/test/test_entrynodes.c

@@ -45,41 +45,6 @@ get_or_state_replacement(void)
   return dummy_state;
 }
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-/* Unittest cleanup function: Cleanup the fake network. */
-static int
-fake_network_cleanup(const struct testcase_t *testcase, void *ptr)
-{
-  (void) testcase;
-  (void) ptr;
-
-  routerlist_free_all();
-  nodelist_free_all();
-  entry_guards_free_all();
-  or_state_free(dummy_state);
-
-  return 1; /* NOP */
-}
-
-/* Unittest setup function: Setup a fake network. */
-static void *
-fake_network_setup(const struct testcase_t *testcase)
-{
-  (void) testcase;
-
-  /* Setup fake state */
-  dummy_state = tor_malloc_zero(sizeof(or_state_t));
-  MOCK(get_or_state,
-       get_or_state_replacement);
-
-  /* Setup fake routerlist. */
-  helper_setup_fake_routerlist();
-
-  /* Return anything but NULL (it's interpreted as test fail) */
-  return dummy_state;
-}
-#endif
-
 static networkstatus_t *dummy_consensus = NULL;
 
 static smartlist_t *big_fake_net_nodes = NULL;
@@ -202,697 +167,6 @@ mock_get_options(void)
   return &mocked_options;
 }
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-/** Test choose_random_entry() with none of our routers being guard nodes. */
-static void
-test_choose_random_entry_no_guards(void *arg)
-{
-  const node_t *chosen_entry = NULL;
-
-  (void) arg;
-
-  MOCK(get_options, mock_get_options);
-
-  /* Check that we get a guard if it passes preferred
-   * address settings */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 1;
-  mocked_options.ClientPreferIPv6ORPort = 0;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  /* Try to pick an entry even though none of our routers are guards. */
-  chosen_entry = choose_random_entry(NULL);
-
-  /* Unintuitively, we actually pick a random node as our entry,
-     because router_choose_random_node() relaxes its constraints if it
-     can't find a proper entry guard. */
-  tt_assert(chosen_entry);
-
-  /* And with the other IP version active */
-  mocked_options.ClientUseIPv6 = 1;
-  chosen_entry = choose_random_entry(NULL);
-  tt_assert(chosen_entry);
-
-  /* And with the preference on auto */
-  mocked_options.ClientPreferIPv6ORPort = -1;
-  chosen_entry = choose_random_entry(NULL);
-  tt_assert(chosen_entry);
-
-  /* Check that we don't get a guard if it doesn't pass mandatory address
-   * settings */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 0;
-  mocked_options.ClientPreferIPv6ORPort = 0;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-
-  /* If we don't allow IPv4 at all, we don't get a guard*/
-  tt_assert(!chosen_entry);
-
-  /* Check that we get a guard if it passes allowed but not preferred address
-   * settings */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 1;
-  mocked_options.ClientUseIPv6 = 1;
-  mocked_options.ClientPreferIPv6ORPort = 1;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-  tt_assert(chosen_entry);
-
-  /* Check that we get a guard if it passes preferred address settings when
-   * they're auto */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 1;
-  mocked_options.ClientPreferIPv6ORPort = -1;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-  tt_assert(chosen_entry);
-
-  /* And with IPv6 active */
-  mocked_options.ClientUseIPv6 = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-  tt_assert(chosen_entry);
-
- done:
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  UNMOCK(get_options);
-}
-
-/** Test choose_random_entry() with only one of our routers being a
-    guard node. */
-static void
-test_choose_random_entry_one_possible_guard(void *arg)
-{
-  const node_t *chosen_entry = NULL;
-  node_t *the_guard = NULL;
-  smartlist_t *our_nodelist = NULL;
-
-  (void) arg;
-
-  MOCK(get_options, mock_get_options);
-
-  /* Set one of the nodes to be a guard. */
-  our_nodelist = nodelist_get_list();
-  the_guard = smartlist_get(our_nodelist, 4); /* chosen by fair dice roll */
-  the_guard->is_possible_guard = 1;
-
-  /* Check that we get the guard if it passes preferred
-   * address settings */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 1;
-  mocked_options.ClientPreferIPv6ORPort = 0;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  /* Pick an entry. Make sure we pick the node we marked as guard. */
-  chosen_entry = choose_random_entry(NULL);
-  tt_ptr_op(chosen_entry, OP_EQ, the_guard);
-
-  /* And with the other IP version active */
-  mocked_options.ClientUseIPv6 = 1;
-  chosen_entry = choose_random_entry(NULL);
-  tt_ptr_op(chosen_entry, OP_EQ, the_guard);
-
-  /* And with the preference on auto */
-  mocked_options.ClientPreferIPv6ORPort = -1;
-  chosen_entry = choose_random_entry(NULL);
-  tt_ptr_op(chosen_entry, OP_EQ, the_guard);
-
-  /* Check that we don't get a guard if it doesn't pass mandatory address
-   * settings */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 0;
-  mocked_options.ClientPreferIPv6ORPort = 0;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-
-  /* If we don't allow IPv4 at all, we don't get a guard*/
-  tt_assert(!chosen_entry);
-
-  /* Check that we get a node if it passes allowed but not preferred
-   * address settings */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 1;
-  mocked_options.ClientUseIPv6 = 1;
-  mocked_options.ClientPreferIPv6ORPort = 1;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-
-  /* We disable the guard check and the preferred address check at the same
-   * time, so we can't be sure we get the guard */
-  tt_assert(chosen_entry);
-
-  /* Check that we get a node if it is allowed but not preferred when settings
-   * are auto */
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  mocked_options.ClientUseIPv4 = 1;
-  mocked_options.ClientPreferIPv6ORPort = -1;
-  mocked_options.UseDeprecatedGuardAlgorithm = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-
-  /* We disable the guard check and the preferred address check at the same
-   * time, so we can't be sure we get the guard */
-  tt_assert(chosen_entry);
-
-  /* and with IPv6 active */
-  mocked_options.ClientUseIPv6 = 1;
-
-  chosen_entry = choose_random_entry(NULL);
-  tt_assert(chosen_entry);
-
- done:
-  memset(&mocked_options, 0, sizeof(mocked_options));
-  UNMOCK(get_options);
-}
-
-/** Helper to conduct tests for populate_live_entry_guards().
-
-   This test adds some entry guards to our list, and then tests
-   populate_live_entry_guards() to mke sure it filters them correctly.
-
-   <b>num_needed</b> is the number of guard nodes we support. It's
-   configurable to make sure we function properly with 1 or 3 guard
-   nodes configured.
-*/
-static void
-populate_live_entry_guards_test_helper(int num_needed)
-{
-  smartlist_t *our_nodelist = NULL;
-  smartlist_t *live_entry_guards = smartlist_new();
-  guard_selection_t *gs = get_guard_selection_info();
-  const smartlist_t *all_entry_guards =
-    get_entry_guards_for_guard_selection(gs);
-  or_options_t *options = get_options_mutable();
-  int retval;
-
-  /* Set NumEntryGuards to the provided number. */
-  options->NumEntryGuards = num_needed;
-  tt_int_op(num_needed, OP_EQ, decide_num_guards(options, 0));
-
-  /* The global entry guards smartlist should be empty now. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 0);
-
-  /* Walk the nodelist and add all nodes as entry guards. */
-  our_nodelist = nodelist_get_list();
-  tt_int_op(smartlist_len(our_nodelist), OP_EQ, HELPER_NUMBER_OF_DESCRIPTORS);
-
-  SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
-    const node_t *node_tmp;
-    node_tmp = add_an_entry_guard(gs, node, 0, 1, 0, 0);
-    tt_assert(node_tmp);
-  } SMARTLIST_FOREACH_END(node);
-
-  /* Make sure the nodes were added as entry guards. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ,
-            HELPER_NUMBER_OF_DESCRIPTORS);
-
-  /* Ensure that all the possible entry guards are enough to satisfy us. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_GE, num_needed);
-
-  /* Walk the entry guard list for some sanity checking */
-  SMARTLIST_FOREACH_BEGIN(all_entry_guards, const entry_guard_t *, entry) {
-    /* Since we called add_an_entry_guard() with 'for_discovery' being
-       False, all guards should have made_contact enabled. */
-    tt_int_op(entry->made_contact, OP_EQ, 1);
-
-  } SMARTLIST_FOREACH_END(entry);
-
-  /* First, try to get some fast guards. This should fail. */
-  retval = populate_live_entry_guards(live_entry_guards,
-                                      all_entry_guards,
-                                      NULL,
-                                      NO_DIRINFO, /* Don't care about DIRINFO*/
-                                      0, 0,
-                                      1); /* We want fast guard! */
-  tt_int_op(retval, OP_EQ, 0);
-  tt_int_op(smartlist_len(live_entry_guards), OP_EQ, 0);
-
-  /* Now try to get some stable guards. This should fail too. */
-  retval = populate_live_entry_guards(live_entry_guards,
-                                      all_entry_guards,
-                                      NULL,
-                                      NO_DIRINFO,
-                                      0,
-                                      1, /* We want stable guard! */
-                                      0);
-  tt_int_op(retval, OP_EQ, 0);
-  tt_int_op(smartlist_len(live_entry_guards), OP_EQ, 0);
-
-  /* Now try to get any guard we can find. This should succeed. */
-  retval = populate_live_entry_guards(live_entry_guards,
-                                      all_entry_guards,
-                                      NULL,
-                                      NO_DIRINFO,
-                                      0, 0, 0); /* No restrictions! */
-
-  /* Since we had more than enough guards in 'all_entry_guards', we
-     should have added 'num_needed' of them to live_entry_guards.
-     'retval' should be 1 since we now have enough live entry guards
-     to pick one.  */
-  tt_int_op(retval, OP_EQ, 1);
-  tt_int_op(smartlist_len(live_entry_guards), OP_EQ, num_needed);
-
- done:
-  smartlist_free(live_entry_guards);
-}
-
-/* Test populate_live_entry_guards() for 1 guard node. */
-static void
-test_populate_live_entry_guards_1guard(void *arg)
-{
-  (void) arg;
-
-  populate_live_entry_guards_test_helper(1);
-}
-
-/* Test populate_live_entry_guards() for 3 guard nodes. */
-static void
-test_populate_live_entry_guards_3guards(void *arg)
-{
-  (void) arg;
-
-  populate_live_entry_guards_test_helper(3);
-}
-
-/** Append some EntryGuard lines to the Tor state at <b>state</b>.
-
-   <b>entry_guard_lines</b> is a smartlist containing 2-tuple
-   smartlists that carry the key and values of the statefile.
-   As an example:
-   entry_guard_lines =
-     (("EntryGuard", "name 67E72FF33D7D41BF11C569646A0A7B4B188340DF DirCache"),
-      ("EntryGuardDownSince", "2014-06-07 16:02:46 2014-06-07 16:02:46"))
-*/
-static void
-state_insert_entry_guard_helper(or_state_t *state,
-                                smartlist_t *entry_guard_lines)
-{
-  config_line_t **next, *line;
-
-  next = &state->EntryGuards;
-  *next = NULL;
-
-  /* Loop over all the state lines in the smartlist */
-  SMARTLIST_FOREACH_BEGIN(entry_guard_lines, const smartlist_t *,state_lines) {
-    /* Get key and value for each line */
-    const char *state_key = smartlist_get(state_lines, 0);
-    const char *state_value = smartlist_get(state_lines, 1);
-
-    *next = line = tor_malloc_zero(sizeof(config_line_t));
-    line->key = tor_strdup(state_key);
-    tor_asprintf(&line->value, "%s", state_value);
-    next = &(line->next);
-  } SMARTLIST_FOREACH_END(state_lines);
-}
-
-/** Free memory occupied by <b>entry_guard_lines</b>. */
-static void
-state_lines_free(smartlist_t *entry_guard_lines)
-{
-  SMARTLIST_FOREACH_BEGIN(entry_guard_lines, smartlist_t *, state_lines) {
-    char *state_key = smartlist_get(state_lines, 0);
-    char *state_value = smartlist_get(state_lines, 1);
-
-    tor_free(state_key);
-    tor_free(state_value);
-    smartlist_free(state_lines);
-  } SMARTLIST_FOREACH_END(state_lines);
-
-  smartlist_free(entry_guard_lines);
-}
-
-/* Tests entry_guards_parse_state(). It creates a fake Tor state with
-   a saved entry guard and makes sure that Tor can parse it and
-   creates the right entry node out of it.
-*/
-static void
-test_entry_guards_parse_state_simple(void *arg)
-{
-  or_options_t *options = get_options_mutable();
-  options->UseDeprecatedGuardAlgorithm = 1;
-  or_state_t *state = or_state_new();
-  const smartlist_t *all_entry_guards = get_entry_guards();
-  smartlist_t *entry_state_lines = smartlist_new();
-  char *msg = NULL;
-  int retval;
-
-  /* Details of our fake guard node */
-  const char *nickname = "hagbard";
-  const char *fpr = "B29D536DD1752D542E1FBB3C9CE4449D51298212";
-  const char *tor_version = "0.2.5.3-alpha-dev";
-  const char *added_at = get_yesterday_date_str();
-  const char *unlisted_since = "2014-06-08 16:16:50";
-
-  (void) arg;
-
-  /* The global entry guards smartlist should be empty now. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 0);
-
-  { /* Prepare the state entry */
-
-    /* Prepare the smartlist to hold the key/value of each line */
-    smartlist_t *state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuard");
-    smartlist_add_asprintf(state_line, "%s %s %s", nickname, fpr, "DirCache");
-    smartlist_add(entry_state_lines, state_line);
-
-    state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuardAddedBy");
-    smartlist_add_asprintf(state_line, "%s %s %s", fpr, tor_version, added_at);
-    smartlist_add(entry_state_lines, state_line);
-
-    state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuardUnlistedSince");
-    smartlist_add_asprintf(state_line, "%s", unlisted_since);
-    smartlist_add(entry_state_lines, state_line);
-  }
-
-  /* Inject our lines in the state */
-  state_insert_entry_guard_helper(state, entry_state_lines);
-
-  /* Parse state */
-  retval = entry_guards_parse_state(state, 1, &msg);
-  tt_int_op(retval, OP_GE, 0);
-
-  /* Test that the guard was registered.
-     We need to re-get the entry guard list since its pointer was
-     overwritten in entry_guards_parse_state(). */
-  all_entry_guards = get_entry_guards();
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 1);
-
-  { /* Test the entry guard structure */
-    char hex_digest[1024];
-    char str_time[1024];
-
-    const entry_guard_t *e = smartlist_get(all_entry_guards, 0);
-    tt_str_op(e->nickname, OP_EQ, nickname); /* Verify nickname */
-
-    base16_encode(hex_digest, sizeof(hex_digest),
-                  e->identity, DIGEST_LEN);
-    tt_str_op(hex_digest, OP_EQ, fpr); /* Verify fingerprint */
-
-    tt_assert(e->is_dir_cache); /* Verify dirness */
-
-    tt_str_op(e->chosen_by_version, OP_EQ, tor_version); /* Verify version */
-
-    tt_assert(e->made_contact); /* All saved guards have been contacted */
-
-    tt_assert(e->bad_since); /* Verify bad_since timestamp */
-    format_iso_time(str_time, e->bad_since);
-    tt_str_op(str_time, OP_EQ, unlisted_since);
-
-    /* The rest should be unset */
-    tt_assert(!e->unreachable_since);
-    tt_assert(!e->can_retry);
-    tt_assert(!e->pb.path_bias_noticed);
-    tt_assert(!e->pb.path_bias_warned);
-    tt_assert(!e->pb.path_bias_extreme);
-    tt_assert(!e->pb.path_bias_disabled);
-    tt_assert(!e->pb.path_bias_use_noticed);
-    tt_assert(!e->pb.path_bias_use_extreme);
-    tt_assert(!e->last_attempted);
-  }
-
- done:
-  state_lines_free(entry_state_lines);
-  or_state_free(state);
-  tor_free(msg);
-}
-
-/** Similar to test_entry_guards_parse_state_simple() but aims to test
-    the PathBias-related details of the entry guard. */
-static void
-test_entry_guards_parse_state_pathbias(void *arg)
-{
-  or_options_t *options = get_options_mutable();
-  options->UseDeprecatedGuardAlgorithm = 1;
-  or_state_t *state = or_state_new();
-  const smartlist_t *all_entry_guards = get_entry_guards();
-  char *msg = NULL;
-  int retval;
-  smartlist_t *entry_state_lines = smartlist_new();
-
-  /* Path bias details of the fake guard */
-  const double circ_attempts = 9;
-  const double circ_successes = 8;
-  const double successful_closed = 4;
-  const double collapsed = 2;
-  const double unusable = 0;
-  const double timeouts = 1;
-
-  (void) arg;
-
-  /* The global entry guards smartlist should be empty now. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 0);
-
-  { /* Prepare the state entry */
-
-    /* Prepare the smartlist to hold the key/value of each line */
-    smartlist_t *state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuard");
-    smartlist_add_asprintf(state_line,
-             "givethanks B29D536DD1752D542E1FBB3C9CE4449D51298212 NoDirCache");
-    smartlist_add(entry_state_lines, state_line);
-
-    state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuardAddedBy");
-    smartlist_add_asprintf(state_line,
-      "B29D536DD1752D542E1FBB3C9CE4449D51298212 0.2.5.3-alpha-dev "
-                           "%s", get_yesterday_date_str());
-    smartlist_add(entry_state_lines, state_line);
-
-    state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuardUnlistedSince");
-    smartlist_add_asprintf(state_line, "2014-06-08 16:16:50");
-    smartlist_add(entry_state_lines, state_line);
-
-    state_line = smartlist_new();
-    smartlist_add_asprintf(state_line, "EntryGuardPathBias");
-    smartlist_add_asprintf(state_line, "%f %f %f %f %f %f",
-                           circ_attempts, circ_successes, successful_closed,
-                           collapsed, unusable, timeouts);
-    smartlist_add(entry_state_lines, state_line);
-  }
-
-  /* Inject our lines in the state */
-  state_insert_entry_guard_helper(state, entry_state_lines);
-
-  /* Parse state */
-  retval = entry_guards_parse_state(state, 1, &msg);
-  tt_int_op(retval, OP_GE, 0);
-
-  /* Test that the guard was registered */
-  all_entry_guards = get_entry_guards();
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 1);
-
-  { /* Test the path bias of this guard */
-    const entry_guard_t *e = smartlist_get(all_entry_guards, 0);
-
-    tt_assert(!e->is_dir_cache);
-    tt_assert(!e->can_retry);
-
-    /* XXX tt_double_op doesn't support equality. Cast to int for now. */
-    tt_int_op((int)e->pb.circ_attempts, OP_EQ, (int)circ_attempts);
-    tt_int_op((int)e->pb.circ_successes, OP_EQ, (int)circ_successes);
-    tt_int_op((int)e->pb.successful_circuits_closed, OP_EQ,
-              (int)successful_closed);
-    tt_int_op((int)e->pb.timeouts, OP_EQ, (int)timeouts);
-    tt_int_op((int)e->pb.collapsed_circuits, OP_EQ, (int)collapsed);
-    tt_int_op((int)e->pb.unusable_circuits, OP_EQ, (int)unusable);
-  }
-
- done:
-  or_state_free(state);
-  state_lines_free(entry_state_lines);
-  tor_free(msg);
-}
-
-/* Simple test of entry_guards_set_from_config() by specifying a
-   particular EntryNode and making sure it gets picked. */
-static void
-test_entry_guards_set_from_config(void *arg)
-{
-  or_options_t *options = get_options_mutable();
-  options->UseDeprecatedGuardAlgorithm = 1;
-  guard_selection_t *gs = get_guard_selection_info();
-  const smartlist_t *all_entry_guards =
-    get_entry_guards_for_guard_selection(gs);
-  const char *entrynodes_str = "test003r";
-  const node_t *chosen_entry = NULL;
-  int retval;
-
-  (void) arg;
-
-  /* Prase EntryNodes as a routerset. */
-  options->EntryNodes = routerset_new();
-  retval = routerset_parse(options->EntryNodes,
-                           entrynodes_str,
-                           "test_entrynodes");
-  tt_int_op(retval, OP_GE, 0);
-
-  /* Read nodes from EntryNodes */
-  entry_guards_set_from_config(gs, options);
-
-  /* Test that only one guard was added. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 1);
-
-  /* Make sure it was the guard we specified. */
-  chosen_entry = choose_random_entry(NULL);
-  tt_str_op(chosen_entry->ri->nickname, OP_EQ, entrynodes_str);
-
- done:
-  routerset_free(options->EntryNodes);
-}
-
-static void
-test_entry_is_time_to_retry(void *arg)
-{
-  entry_guard_t *test_guard;
-  time_t now;
-  int retval;
-  (void)arg;
-
-  now = time(NULL);
-
-  test_guard = tor_malloc_zero(sizeof(entry_guard_t));
-
-  test_guard->last_attempted = now - 10;
-  test_guard->unreachable_since = now - 1;
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->unreachable_since = now - (6*60*60 - 1);
-  test_guard->last_attempted = now - (60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->last_attempted = now - (60*60 - 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,0);
-
-  test_guard->unreachable_since = now - (6*60*60 + 1);
-  test_guard->last_attempted = now - (4*60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->unreachable_since = now - (3*24*60*60 - 1);
-  test_guard->last_attempted = now - (4*60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->unreachable_since = now - (3*24*60*60 + 1);
-  test_guard->last_attempted = now - (18*60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->unreachable_since = now - (7*24*60*60 - 1);
-  test_guard->last_attempted = now - (18*60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->last_attempted = now - (18*60*60 - 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,0);
-
-  test_guard->unreachable_since = now - (7*24*60*60 + 1);
-  test_guard->last_attempted = now - (36*60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
-  test_guard->unreachable_since = now - (7*24*60*60 + 1);
-  test_guard->last_attempted = now - (36*60*60 + 1);
-
-  retval = entry_is_time_to_retry(test_guard,now);
-  tt_int_op(retval,OP_EQ,1);
-
- done:
-  tor_free(test_guard);
-}
-
-/** XXX Do some tests that entry_is_live() */
-static void
-test_entry_is_live(void *arg)
-{
-  smartlist_t *our_nodelist = NULL;
-  guard_selection_t *gs = get_guard_selection_info();
-  const smartlist_t *all_entry_guards =
-    get_entry_guards_for_guard_selection(gs);
-  const node_t *test_node = NULL;
-  const entry_guard_t *test_entry = NULL;
-  const char *msg;
-  int which_node;
-
-  (void) arg;
-
-  /* The global entry guards smartlist should be empty now. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ, 0);
-
-  /* Walk the nodelist and add all nodes as entry guards. */
-  our_nodelist = nodelist_get_list();
-  tt_int_op(smartlist_len(our_nodelist), OP_EQ, HELPER_NUMBER_OF_DESCRIPTORS);
-
-  SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
-    const node_t *node_tmp;
-    node_tmp = add_an_entry_guard(gs, node, 0, 1, 0, 0);
-    tt_assert(node_tmp);
-
-    tt_int_op(node->is_stable, OP_EQ, 0);
-    tt_int_op(node->is_fast, OP_EQ, 0);
-  } SMARTLIST_FOREACH_END(node);
-
-  /* Make sure the nodes were added as entry guards. */
-  tt_int_op(smartlist_len(all_entry_guards), OP_EQ,
-            HELPER_NUMBER_OF_DESCRIPTORS);
-
-  /* Now get a random test entry that we will use for this unit test. */
-  which_node = 3;  /* (chosen by fair dice roll) */
-  test_entry = smartlist_get(all_entry_guards, which_node);
-
-  /* Let's do some entry_is_live() tests! */
-
-  /* Require the node to be stable, but it's not. Should fail.
-     Also enable 'assume_reachable' because why not. */
-  test_node = entry_is_live(test_entry,
-                            ENTRY_NEED_UPTIME | ENTRY_ASSUME_REACHABLE,
-                            &msg);
-  tt_assert(!test_node);
-
-  /* Require the node to be fast, but it's not. Should fail. */
-  test_node = entry_is_live(test_entry,
-                            ENTRY_NEED_CAPACITY | ENTRY_ASSUME_REACHABLE,
-                            &msg);
-  tt_assert(!test_node);
-
-  /* Don't impose any restrictions on the node. Should succeed. */
-  test_node = entry_is_live(test_entry, 0, &msg);
-  tt_assert(test_node);
-  tt_ptr_op(test_node, OP_EQ, node_get_by_id(test_entry->identity));
-
-  /* Require descriptor for this node. It has one so it should succeed. */
-  test_node = entry_is_live(test_entry, ENTRY_NEED_DESCRIPTOR, &msg);
-  tt_assert(test_node);
-  tt_ptr_op(test_node, OP_EQ, node_get_by_id(test_entry->identity));
-
- done:
-  ; /* XXX */
-}
-#endif
-
 #define TEST_IPV4_ADDR "123.45.67.89"
 #define TEST_IPV6_ADDR "[1234:5678:90ab:cdef::]"
 
@@ -1473,14 +747,6 @@ test_entry_guard_parse_from_state_broken(void *arg)
   gs_df = get_guard_selection_by_name("default", GS_TYPE_NORMAL, 0);
   tt_assert(gs_df != NULL);
   tt_int_op(smartlist_len(gs_df->sampled_entry_guards), OP_EQ, 1);
-  guard_selection_t *gs_legacy =
-    get_guard_selection_by_name("legacy", GS_TYPE_LEGACY, 0);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  tt_assert(gs_legacy != NULL);
-  tt_int_op(smartlist_len(gs_legacy->chosen_entry_guards), OP_EQ, 0);
-#else
-  tt_assert(gs_legacy == NULL);
-#endif
 
  done:
   config_free_lines(lines);
@@ -1520,17 +786,6 @@ test_entry_guard_get_guard_selection_by_name(void *arg)
   tt_assert(gs3 != gs1);
   tt_assert(gs3 == get_guard_selection_info());
 
-  or_options_t *options = get_options_mutable();
-  options->UseDeprecatedGuardAlgorithm = 1;
-  update_guard_selection_choice(options);
-  guard_selection_t *gs4 = get_guard_selection_info();
-  tt_assert(gs4 != gs3);
-  tt_assert(gs4 == get_guard_selection_by_name("legacy", GS_TYPE_LEGACY, 1));
-
-  options->UseDeprecatedGuardAlgorithm = 0;
-  update_guard_selection_choice(options);
-  tt_assert(gs3 == get_guard_selection_info());
-
  done:
   entry_guards_free_all();
 }
@@ -1555,14 +810,6 @@ test_entry_guard_choose_selection_initial(void *arg)
   tt_int_op(type, OP_EQ, GS_TYPE_BRIDGE);
   get_options_mutable()->UseBridges = 0;
 
-  /* If we're using legacy guards, we get the legacy selection */
-  get_options_mutable()->UseDeprecatedGuardAlgorithm = 1;
-  name = choose_guard_selection(get_options(),
-                                dummy_consensus, NULL, &type);
-  tt_str_op(name, OP_EQ, "legacy");
-  tt_int_op(type, OP_EQ, GS_TYPE_LEGACY);
-  get_options_mutable()->UseDeprecatedGuardAlgorithm = 0;
-
   /* If we discard >99% of our guards, though, we should be in the restricted
    * set. */
   tt_assert(get_options_mutable()->EntryNodes == NULL);
@@ -3361,12 +2608,6 @@ test_enty_guard_should_expire_waiting(void *arg)
   tor_free(fake_state);
 }
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-static const struct testcase_setup_t fake_network = {
-  fake_network_setup, fake_network_cleanup
-};
-#endif
-
 static const struct testcase_setup_t big_fake_network = {
   big_fake_network_setup, big_fake_network_cleanup
 };
@@ -3383,33 +2624,6 @@ static const struct testcase_setup_t upgrade_circuits = {
       (void*)(arg) }
 
 struct testcase_t entrynodes_tests[] = {
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  { "entry_is_time_to_retry", test_entry_is_time_to_retry,
-    TT_FORK, NULL, NULL },
-  { "choose_random_entry_no_guards", test_choose_random_entry_no_guards,
-    TT_FORK, &fake_network, NULL },
-  { "choose_random_entry_one_possible_guard",
-    test_choose_random_entry_one_possible_guard,
-    TT_FORK, &fake_network, NULL },
-  { "populate_live_entry_guards_1guard",
-    test_populate_live_entry_guards_1guard,
-    TT_FORK, &fake_network, NULL },
-  { "populate_live_entry_guards_3guards",
-    test_populate_live_entry_guards_3guards,
-    TT_FORK, &fake_network, NULL },
-  { "entry_guards_parse_state_simple",
-    test_entry_guards_parse_state_simple,
-    TT_FORK, &fake_network, NULL },
-  { "entry_guards_parse_state_pathbias",
-    test_entry_guards_parse_state_pathbias,
-    TT_FORK, &fake_network, NULL },
-  { "entry_guards_set_from_config",
-    test_entry_guards_set_from_config,
-    TT_FORK, &fake_network, NULL },
-  { "entry_is_live",
-    test_entry_is_live,
-    TT_FORK, &fake_network, NULL },
-#endif
   { "node_preferred_orport",
     test_node_preferred_orport,
     0, NULL, NULL },

+ 0 - 84
src/test/test_routerlist.c

@@ -204,55 +204,6 @@ mock_usable_consensus_flavor(void)
   return mock_usable_consensus_flavor_value;
 }
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-static smartlist_t *mock_is_guard_list = NULL;
-
-static int
-mock_is_node_used_as_guard(const node_t *n)
-{
-  if (mock_is_guard_list) {
-    SMARTLIST_FOREACH_BEGIN(mock_is_guard_list, node_t *, e) {
-      if (e == n) return 1;
-    } SMARTLIST_FOREACH_END(e);
-  }
-
-  return 0;
-}
-
-static void
-mark_node_used_as_guard(node_t *n)
-{
-  if (!n) return;
-
-  if (!mock_is_guard_list) {
-    mock_is_guard_list = smartlist_new();
-  }
-
-  if (!mock_is_node_used_as_guard(n)) {
-    smartlist_add(mock_is_guard_list, n);
-  }
-}
-
-static void
-mark_node_unused_as_guard(node_t *n)
-{
-  if (!n) return;
-
-  if (!mock_is_guard_list) return;
-
-  smartlist_remove(mock_is_guard_list, n);
-}
-
-static void
-clear_mock_guard_list(void)
-{
-  if (mock_is_guard_list) {
-    smartlist_free(mock_is_guard_list);
-    mock_is_guard_list = NULL;
-  }
-}
-#endif
-
 static void
 test_router_pick_directory_server_impl(void *arg)
 {
@@ -273,9 +224,6 @@ test_router_pick_directory_server_impl(void *arg)
   (void)arg;
 
   MOCK(usable_consensus_flavor, mock_usable_consensus_flavor);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  MOCK(is_node_used_as_guard, mock_is_node_used_as_guard);
-#endif
 
   /* With no consensus, we must be bootstrapping, regardless of time or flavor
    */
@@ -388,34 +336,6 @@ test_router_pick_directory_server_impl(void *arg)
   node_router1->is_valid = 1;
   node_router3->is_valid = 1;
 
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  flags |= PDS_FOR_GUARD;
-  mark_node_used_as_guard(node_router1);
-  mark_node_used_as_guard(node_router2);
-  mark_node_used_as_guard(node_router3);
-  rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL);
-  tt_assert(rs == NULL);
-  mark_node_unused_as_guard(node_router1);
-  rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL);
-  tt_assert(rs != NULL);
-  tt_assert(tor_memeq(rs->identity_digest, router1_id, DIGEST_LEN));
-  rs = NULL;
-  mark_node_unused_as_guard(node_router2);
-  mark_node_unused_as_guard(node_router3);
-#endif
-
-  /* One not valid, one guard. This should leave one remaining */
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  node_router1->is_valid = 0;
-  mark_node_used_as_guard(node_router2);
-  rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL);
-  tt_assert(rs != NULL);
-  tt_assert(tor_memeq(rs->identity_digest, router3_id, DIGEST_LEN));
-  rs = NULL;
-  node_router1->is_valid = 1;
-  mark_node_unused_as_guard(node_router2);
-#endif
-
   /* Manipulate overloaded */
 
   node_router2->rs->last_dir_503_at = now;
@@ -477,10 +397,6 @@ test_router_pick_directory_server_impl(void *arg)
 
  done:
   UNMOCK(usable_consensus_flavor);
-#ifdef ENABLE_LEGACY_GUARD_ALGORITHM
-  UNMOCK(is_node_used_as_guard);
-  clear_mock_guard_list();
-#endif
 
   if (router1_id)
     tor_free(router1_id);

Some files were not shown because too many files changed in this diff