Browse Source

Merge remote-tracking branch 'public/ticket20001_v2'

Nick Mathewson 7 years ago
parent
commit
ed5d2daba1
4 changed files with 66 additions and 1 deletions
  1. 6 0
      changes/ticket20001
  2. 8 1
      src/or/routerparse.c
  3. 8 0
      src/or/routerparse.h
  4. 44 0
      src/test/test_dir.c

+ 6 - 0
changes/ticket20001

@@ -0,0 +1,6 @@
+  o Minor features (client, directory):
+    - Since authorities now omit all routers that lack the Running and Valid
+      flags, we assume that any authority present in the consensus must
+      have those flags. Closes ticket 20001; implements part of proposal
+      272.
+

+ 8 - 1
src/or/routerparse.c

@@ -2760,7 +2760,7 @@ routerstatus_parse_guardfraction(const char *guardfraction_str,
  *
  * Parse according to the syntax used by the consensus flavor <b>flav</b>.
  **/
-static routerstatus_t *
+STATIC routerstatus_t *
 routerstatus_parse_entry_from_string(memarea_t *area,
                                      const char **s, smartlist_t *tokens,
                                      networkstatus_t *vote,
@@ -2874,6 +2874,7 @@ routerstatus_parse_entry_from_string(memarea_t *area,
       }
     }
   } else if (tok) {
+    /* This is a consensus, not a vote. */
     int i;
     for (i=0; i < tok->n_args; ++i) {
       if (!strcmp(tok->args[i], "Exit"))
@@ -2904,6 +2905,12 @@ routerstatus_parse_entry_from_string(memarea_t *area,
         rs->is_v2_dir = 1;
       }
     }
+    /* These are implied true by having been included in a consensus made
+     * with a given method */
+    rs->is_flagged_running = 1; /* Starting with consensus method 4. */
+    if (consensus_method >= MIN_METHOD_FOR_EXCLUDING_INVALID_NODES)
+      rs->is_valid = 1;
+
   }
   int found_protocol_list = 0;
   if ((tok = find_opt_by_keyword(tokens, K_PROTO))) {

+ 8 - 0
src/or/routerparse.h

@@ -112,6 +112,14 @@ MOCK_DECL(STATIC dumped_desc_t *, dump_desc_populate_one_file,
 STATIC void dump_desc_populate_fifo_from_directory(const char *dirname);
 STATIC void dump_desc(const char *desc, const char *type);
 STATIC void dump_desc_fifo_cleanup(void);
+struct memarea_t;
+STATIC routerstatus_t *routerstatus_parse_entry_from_string(
+                                     struct memarea_t *area,
+                                     const char **s, smartlist_t *tokens,
+                                     networkstatus_t *vote,
+                                     vote_routerstatus_t *vote_rs,
+                                     int consensus_method,
+                                     consensus_flavor_t flav);
 #endif
 
 #define ED_DESC_SIGNATURE_PREFIX "Tor router descriptor signature v1"

+ 44 - 0
src/test/test_dir.c

@@ -5388,6 +5388,49 @@ test_dir_find_dl_schedule(void* data)
   mock_options = NULL;
 }
 
+static void
+test_dir_assumed_flags(void *arg)
+{
+  (void)arg;
+  smartlist_t *tokens = smartlist_new();
+  memarea_t *area = memarea_new();
+  routerstatus_t *rs = NULL;
+
+  /* First, we should always assume that the Running flag is set, even
+   * when it isn't listed, since the consensus method is always
+   * higher than 4. */
+  const char *str1 =
+    "r example hereiswhereyouridentitygoes 2015-08-30 12:00:00 "
+       "192.168.0.1 9001 0\n"
+    "m thisoneislongerbecauseitisa256bitmddigest33\n"
+    "s Fast Guard Stable\n";
+
+  const char *cp = str1;
+  rs = routerstatus_parse_entry_from_string(area, &cp, tokens, NULL, NULL,
+                                            23, FLAV_MICRODESC);
+  tt_assert(rs);
+  tt_assert(rs->is_flagged_running);
+  tt_assert(! rs->is_valid);
+  tt_assert(! rs->is_exit);
+  tt_assert(rs->is_fast);
+  routerstatus_free(rs);
+
+  /* With method 24 or later, we can assume "valid" is set. */
+  cp = str1;
+  rs = routerstatus_parse_entry_from_string(area, &cp, tokens, NULL, NULL,
+                                            24, FLAV_MICRODESC);
+  tt_assert(rs);
+  tt_assert(rs->is_flagged_running);
+  tt_assert(rs->is_valid);
+  tt_assert(! rs->is_exit);
+  tt_assert(rs->is_fast);
+
+ done:
+  smartlist_free(tokens);
+  memarea_drop_all(area);
+  routerstatus_free(rs);
+}
+
 #define DIR_LEGACY(name)                             \
   { #name, test_dir_ ## name , TT_FORK, NULL, NULL }
 
@@ -5441,6 +5484,7 @@ struct testcase_t dir_tests[] = {
   DIR_ARG(find_dl_schedule, TT_FORK, "ba"),
   DIR_ARG(find_dl_schedule, TT_FORK, "cf"),
   DIR_ARG(find_dl_schedule, TT_FORK, "ca"),
+  DIR(assumed_flags, 0),
   END_OF_TESTCASES
 };