Browse Source

Add configuration options for directory guards

In addition to all the other ways to make directory gurads not go,
you can now set UseEntryGuardsAsDirGuards to 0.
Nick Mathewson 13 years ago
parent
commit
0f9dfef9d6
4 changed files with 13 additions and 4 deletions
  1. 2 0
      src/or/config.c
  2. 1 1
      src/or/directory.c
  3. 7 3
      src/or/entrynodes.c
  4. 3 0
      src/or/or.h

+ 2 - 0
src/or/config.c

@@ -308,6 +308,7 @@ static config_var_t option_vars_[] = {
   OBSOLETE("NoPublish"),
   OBSOLETE("NoPublish"),
   VAR("NodeFamily",              LINELIST, NodeFamilies,         NULL),
   VAR("NodeFamily",              LINELIST, NodeFamilies,         NULL),
   V(NumCPUs,                     UINT,     "0"),
   V(NumCPUs,                     UINT,     "0"),
+  V(NumDirectoryGuards,          UINT,     "3"),
   V(NumEntryGuards,              UINT,     "3"),
   V(NumEntryGuards,              UINT,     "3"),
   V(ORListenAddress,             LINELIST, NULL),
   V(ORListenAddress,             LINELIST, NULL),
   VPORT(ORPort,                      LINELIST, NULL),
   VPORT(ORPort,                      LINELIST, NULL),
@@ -382,6 +383,7 @@ static config_var_t option_vars_[] = {
   V(UpdateBridgesFromAuthority,  BOOL,     "0"),
   V(UpdateBridgesFromAuthority,  BOOL,     "0"),
   V(UseBridges,                  BOOL,     "0"),
   V(UseBridges,                  BOOL,     "0"),
   V(UseEntryGuards,              BOOL,     "1"),
   V(UseEntryGuards,              BOOL,     "1"),
+  V(UseEntryGuardsAsDirGuards,   BOOL,     "1"),
   V(UseMicrodescriptors,         AUTOBOOL, "auto"),
   V(UseMicrodescriptors,         AUTOBOOL, "auto"),
   V(User,                        STRING,   NULL),
   V(User,                        STRING,   NULL),
   V(UserspaceIOCPBuffers,        BOOL,     "0"),
   V(UserspaceIOCPBuffers,        BOOL,     "0"),

+ 1 - 1
src/or/directory.c

@@ -345,7 +345,7 @@ should_use_directory_guards(const or_options_t *options)
   /* If guards are disabled, or directory guards are disabled, we can't
   /* If guards are disabled, or directory guards are disabled, we can't
    * use directory guards.
    * use directory guards.
    */
    */
-  if (!options->UseEntryGuards)
+  if (!options->UseEntryGuards || !options->UseEntryGuardsAsDirGuards)
     return 0;
     return 0;
   /* If we're configured to fetch directory info aggressively or of a
   /* If we're configured to fetch directory info aggressively or of a
    * nonstandard type, don't use directory guards. */
    * nonstandard type, don't use directory guards. */

+ 7 - 3
src/or/entrynodes.c

@@ -400,10 +400,12 @@ static void
 pick_entry_guards(const or_options_t *options, int for_directory)
 pick_entry_guards(const or_options_t *options, int for_directory)
 {
 {
   int changed = 0;
   int changed = 0;
+  const int num_needed = for_directory ? options->NumDirectoryGuards :
+    options->NumEntryGuards;
 
 
   tor_assert(entry_guards);
   tor_assert(entry_guards);
 
 
-  while (num_live_entry_guards(for_directory) < options->NumEntryGuards) {
+  while (num_live_entry_guards(for_directory) < num_needed) {
     if (!add_an_entry_guard(NULL, 0, 0, for_directory))
     if (!add_an_entry_guard(NULL, 0, 0, for_directory))
       break;
       break;
     changed = 1;
     changed = 1;
@@ -861,6 +863,8 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
   int need_capacity = state ? state->need_capacity : 0;
   int need_capacity = state ? state->need_capacity : 0;
   int preferred_min, consider_exit_family = 0;
   int preferred_min, consider_exit_family = 0;
   int need_descriptor = !for_directory;
   int need_descriptor = !for_directory;
+  const int num_needed = for_directory ? options->NumDirectoryGuards :
+    options->NumEntryGuards;
 
 
   /* Checking dirinfo_type isn't required yet, since we only choose directory
   /* Checking dirinfo_type isn't required yet, since we only choose directory
      guards that can support microdescs, routerinfos, and networkstatuses, AND
      guards that can support microdescs, routerinfos, and networkstatuses, AND
@@ -880,7 +884,7 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
     entry_guards_set_from_config(options);
     entry_guards_set_from_config(options);
 
 
   if (!entry_list_is_constrained(options) &&
   if (!entry_list_is_constrained(options) &&
-      smartlist_len(entry_guards) < options->NumEntryGuards)
+      smartlist_len(entry_guards) < num_needed)
     pick_entry_guards(options, for_directory);
     pick_entry_guards(options, for_directory);
 
 
  retry:
  retry:
@@ -923,7 +927,7 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
          * guard list without needing to. */
          * guard list without needing to. */
         goto choose_and_finish;
         goto choose_and_finish;
       }
       }
-      if (smartlist_len(live_entry_guards) >= options->NumEntryGuards)
+      if (smartlist_len(live_entry_guards) >= num_needed)
         goto choose_and_finish; /* we have enough */
         goto choose_and_finish; /* we have enough */
   } SMARTLIST_FOREACH_END(entry);
   } SMARTLIST_FOREACH_END(entry);
 
 

+ 3 - 0
src/or/or.h

@@ -3614,6 +3614,9 @@ typedef struct {
   int UseEntryGuards; /**< Boolean: Do we try to enter from a smallish number
   int UseEntryGuards; /**< Boolean: Do we try to enter from a smallish number
                        * of fixed nodes? */
                        * of fixed nodes? */
   int NumEntryGuards; /**< How many entry guards do we try to establish? */
   int NumEntryGuards; /**< How many entry guards do we try to establish? */
+  int UseEntryGuardsAsDirGuards; /** Boolean: Do we try to get directory info
+                                  * from a smallish number of fixed nodes? */
+  int NumDirectoryGuards; /**< How many dir guards do we try to establish? */
   int RephistTrackTime; /**< How many seconds do we keep rephist info? */
   int RephistTrackTime; /**< How many seconds do we keep rephist info? */
   int FastFirstHopPK; /**< If Tor believes it is safe, should we save a third
   int FastFirstHopPK; /**< If Tor believes it is safe, should we save a third
                        * of our PK time by sending CREATE_FAST cells? */
                        * of our PK time by sending CREATE_FAST cells? */