Parcourir la source

Vote on 'proto' lines and include them after 'v' lines.

(Despite the increased size of the consensus, this should have
approximately zero effect on the compressed consensus size, since
the "proto" line should be completely implied by the "v" line.)
Nick Mathewson il y a 7 ans
Parent
commit
90a6fe318c
3 fichiers modifiés avec 27 ajouts et 2 suppressions
  1. 22 0
      src/or/dirvote.c
  2. 0 2
      src/or/dirvote.h
  3. 5 0
      src/or/routerparse.c

+ 22 - 0
src/or/dirvote.c

@@ -1563,6 +1563,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
     smartlist_t *matching_descs = smartlist_new();
     smartlist_t *matching_descs = smartlist_new();
     smartlist_t *chosen_flags = smartlist_new();
     smartlist_t *chosen_flags = smartlist_new();
     smartlist_t *versions = smartlist_new();
     smartlist_t *versions = smartlist_new();
+    smartlist_t *protocols = smartlist_new();
     smartlist_t *exitsummaries = smartlist_new();
     smartlist_t *exitsummaries = smartlist_new();
     uint32_t *bandwidths_kb = tor_calloc(smartlist_len(votes),
     uint32_t *bandwidths_kb = tor_calloc(smartlist_len(votes),
                                          sizeof(uint32_t));
                                          sizeof(uint32_t));
@@ -1705,6 +1706,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
       routerstatus_t rs_out;
       routerstatus_t rs_out;
       const char *current_rsa_id = NULL;
       const char *current_rsa_id = NULL;
       const char *chosen_version;
       const char *chosen_version;
+      const char *chosen_protocol_list;
       const char *chosen_name = NULL;
       const char *chosen_name = NULL;
       int exitsummary_disagreement = 0;
       int exitsummary_disagreement = 0;
       int is_named = 0, is_unnamed = 0, is_running = 0;
       int is_named = 0, is_unnamed = 0, is_running = 0;
@@ -1718,6 +1720,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
       smartlist_clear(matching_descs);
       smartlist_clear(matching_descs);
       smartlist_clear(chosen_flags);
       smartlist_clear(chosen_flags);
       smartlist_clear(versions);
       smartlist_clear(versions);
+      smartlist_clear(protocols);
       num_bandwidths = 0;
       num_bandwidths = 0;
       num_mbws = 0;
       num_mbws = 0;
       num_guardfraction_inputs = 0;
       num_guardfraction_inputs = 0;
@@ -1737,6 +1740,12 @@ networkstatus_compute_consensus(smartlist_t *votes,
         if (rs->version && rs->version[0])
         if (rs->version && rs->version[0])
           smartlist_add(versions, rs->version);
           smartlist_add(versions, rs->version);
 
 
+        if (rs->protocols) {
+          /* We include this one even if it's empty: voting for an
+           * empty protocol list actually is meaningful. */
+          smartlist_add(protocols, rs->protocols);
+        }
+
         /* Tally up all the flags. */
         /* Tally up all the flags. */
         for (int flag = 0; flag < n_voter_flags[voter_idx]; ++flag) {
         for (int flag = 0; flag < n_voter_flags[voter_idx]; ++flag) {
           if (rs->flags & (U64_LITERAL(1) << flag))
           if (rs->flags & (U64_LITERAL(1) << flag))
@@ -1875,6 +1884,14 @@ networkstatus_compute_consensus(smartlist_t *votes,
         chosen_version = NULL;
         chosen_version = NULL;
       }
       }
 
 
+      /* Pick the protocol list */
+      if (smartlist_len(protocols)) {
+        smartlist_sort_strings(protocols);
+        chosen_protocol_list = get_most_frequent_member(protocols);
+      } else {
+        chosen_protocol_list = NULL;
+      }
+
       /* If it's a guard and we have enough guardfraction votes,
       /* If it's a guard and we have enough guardfraction votes,
          calculate its consensus guardfraction value. */
          calculate its consensus guardfraction value. */
       if (is_guard && num_guardfraction_inputs > 2 &&
       if (is_guard && num_guardfraction_inputs > 2 &&
@@ -2028,6 +2045,10 @@ networkstatus_compute_consensus(smartlist_t *votes,
         smartlist_add(chunks, tor_strdup(chosen_version));
         smartlist_add(chunks, tor_strdup(chosen_version));
       }
       }
       smartlist_add(chunks, tor_strdup("\n"));
       smartlist_add(chunks, tor_strdup("\n"));
+      if (chosen_protocol_list &&
+          consensus_method >= MIN_METHOD_FOR_RS_PROTOCOLS) {
+        smartlist_add_asprintf(chunks, "proto %s\n", chosen_protocol_list);
+      }
       /*     Now the weight line. */
       /*     Now the weight line. */
       if (rs_out.has_bandwidth) {
       if (rs_out.has_bandwidth) {
         char *guardfraction_str = NULL;
         char *guardfraction_str = NULL;
@@ -2068,6 +2089,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
     smartlist_free(matching_descs);
     smartlist_free(matching_descs);
     smartlist_free(chosen_flags);
     smartlist_free(chosen_flags);
     smartlist_free(versions);
     smartlist_free(versions);
+    smartlist_free(protocols);
     smartlist_free(exitsummaries);
     smartlist_free(exitsummaries);
     tor_free(bandwidths_kb);
     tor_free(bandwidths_kb);
     tor_free(measured_bws_kb);
     tor_free(measured_bws_kb);

+ 0 - 2
src/or/dirvote.h

@@ -103,11 +103,9 @@
  * protocols. */
  * protocols. */
 #define MIN_METHOD_FOR_RECOMMENDED_PROTOCOLS 24
 #define MIN_METHOD_FOR_RECOMMENDED_PROTOCOLS 24
 
 
-#if 0
 /** Lowest consensus method where authorities add protocols to routerstatus
 /** Lowest consensus method where authorities add protocols to routerstatus
  * entries. */
  * entries. */
 #define MIN_METHOD_FOR_RS_PROTOCOLS 24
 #define MIN_METHOD_FOR_RS_PROTOCOLS 24
-#endif
 
 
 /** Default bandwidth to clip unmeasured bandwidths to using method >=
 /** Default bandwidth to clip unmeasured bandwidths to using method >=
  * MIN_METHOD_TO_CLIP_UNMEASURED_BW.  (This is not a consensus method; do not
  * MIN_METHOD_TO_CLIP_UNMEASURED_BW.  (This is not a consensus method; do not

+ 5 - 0
src/or/routerparse.c

@@ -388,6 +388,7 @@ static token_rule_t rtrstatus_token_table[] = {
   T01("w",                   K_W,                   ARGS,    NO_OBJ ),
   T01("w",                   K_W,                   ARGS,    NO_OBJ ),
   T0N("m",                   K_M,               CONCAT_ARGS, NO_OBJ ),
   T0N("m",                   K_M,               CONCAT_ARGS, NO_OBJ ),
   T0N("id",                  K_ID,                  GE(2),   NO_OBJ ),
   T0N("id",                  K_ID,                  GE(2),   NO_OBJ ),
+  T01("proto",               K_PROTO,           CONCAT_ARGS, NO_OBJ ),
   T0N("opt",                 K_OPT,             CONCAT_ARGS, OBJ_OK ),
   T0N("opt",                 K_OPT,             CONCAT_ARGS, OBJ_OK ),
   END_OF_TABLE
   END_OF_TABLE
 };
 };
@@ -2992,6 +2993,10 @@ routerstatus_parse_entry_from_string(memarea_t *area,
           }
           }
         }
         }
       }
       }
+      if (t->tp == K_PROTO) {
+        tor_assert(t->n_args == 1);
+        vote_rs->protocols = tor_strdup(t->args[0]);
+      }
     } SMARTLIST_FOREACH_END(t);
     } SMARTLIST_FOREACH_END(t);
   } else if (flav == FLAV_MICRODESC) {
   } else if (flav == FLAV_MICRODESC) {
     tok = find_opt_by_keyword(tokens, K_M);
     tok = find_opt_by_keyword(tokens, K_M);