]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Actually parse the m lines from a microdesc consensus
authorNick Mathewson <nickm@torproject.org>
Thu, 16 Sep 2010 16:55:48 +0000 (12:55 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 27 Sep 2010 22:04:44 +0000 (18:04 -0400)
src/or/or.h
src/or/routerparse.c

index 5a9fbf26f8c85e81e41b822cfe04b48ae257552c..cd542797cab701e51e4eda656aeecb409fad2f15 100644 (file)
@@ -1569,8 +1569,9 @@ typedef struct routerstatus_t {
                                       * has. */
   char identity_digest[DIGEST_LEN]; /**< Digest of the router's identity
                                      * key. */
-  char descriptor_digest[DIGEST_LEN]; /**< Digest of the router's most recent
-                                       * descriptor. */
+  /** Digest of the router's most recent descriptor or microdescriptor.
+   * If it's a descriptor, we only use the first DIGEST_LEN bytes. */
+  char descriptor_digest[DIGEST256_LEN];
   uint32_t addr; /**< IPv4 address for this router. */
   uint16_t or_port; /**< OR port for this router. */
   uint16_t dir_port; /**< Directory port for this router. */
index 96749e5a748dea4ecdd96ee702cde22f667bf95a..05584dc6edb6c5749854060b12da0d0d9421fe08 100644 (file)
@@ -1943,6 +1943,7 @@ routerstatus_parse_entry_from_string(memarea_t *area,
 
   if (!consensus_method)
     flav = FLAV_NS;
+  tor_assert(flav == FLAV_NS || flav == FLAV_MICRODESC);
 
   eos = find_start_of_next_routerstatus(*s);
 
@@ -1955,15 +1956,16 @@ routerstatus_parse_entry_from_string(memarea_t *area,
     goto err;
   }
   tok = find_by_keyword(tokens, K_R);
-  tor_assert(tok->n_args >= 7);
+  tor_assert(tok->n_args >= 7); /* guaranteed by GE(7) in K_R setup */
   if (flav == FLAV_NS) {
     if (tok->n_args < 8) {
       log_warn(LD_DIR, "Too few arguments to r");
       goto err;
     }
-  } else {
-    offset = -1;
+  } else if (flav == FLAV_MICRODESC) {
+    offset = -1; /* There is no identity digest */
   }
+
   if (vote_rs) {
     rs = &vote_rs->status;
   } else {
@@ -2139,6 +2141,16 @@ routerstatus_parse_entry_from_string(memarea_t *area,
         vote_rs->microdesc = line;
       }
     } SMARTLIST_FOREACH_END(t);
+  } else if (flav == FLAV_MICRODESC) {
+    tok = find_opt_by_keyword(tokens, K_M);
+    if (tok) {
+      tor_assert(tok->n_args);
+      if (digest256_from_base64(rs->descriptor_digest, tok->args[0])) {
+        log_warn(LD_DIR, "Error decoding microdescriptor digest %s",
+                 escaped(tok->args[0]));
+        goto err;
+      }
+    }
   }
 
   if (!strcasecmp(rs->nickname, UNNAMED_ROUTER_NICKNAME))