[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r9966: Now that the directory parser checks for missing items, the (in tor/trunk: . src/or)



Author: nickm
Date: 2007-04-16 00:18:29 -0400 (Mon, 16 Apr 2007)
New Revision: 9966

Modified:
   tor/trunk/
   tor/trunk/src/or/routerparse.c
Log:
 r12388@catbus:  nickm | 2007-04-16 00:17:29 -0400
 Now that the directory parser checks for missing items, the rest of the code can just assert that they are there, rather than checking a second time.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12388] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2007-04-16 04:18:21 UTC (rev 9965)
+++ tor/trunk/src/or/routerparse.c	2007-04-16 04:18:29 UTC (rev 9966)
@@ -164,7 +164,7 @@
   T1( "published",           K_PUBLISHED,       CONCAT_ARGS, NO_OBJ ),
   T0N("opt",                 K_OPT,             CONCAT_ARGS, OBJ_OK ),
   T1( "contact",             K_CONTACT,         CONCAT_ARGS, NO_OBJ ),
-  T1( "dir-signing-key",     K_DIR_SIGNING_KEY,     ARGS,    OBJ_OK ),
+  T1( "dir-signing-key",     K_DIR_SIGNING_KEY,     ARGS,    NEED_KEY ),
   T1( "fingerprint",         K_FINGERPRINT,     CONCAT_ARGS, NO_OBJ ),
   T1( "network-status-version", K_NETWORK_STATUS_VERSION,
                                                    ARGS,    NO_OBJ ),
@@ -190,7 +190,7 @@
 
   T( "running-routers",     K_RUNNING_ROUTERS,     ARGS,    NO_OBJ ),
   T( "router-status",       K_ROUTER_STATUS,       ARGS,    NO_OBJ ),
-  T( "published",           K_PUBLISHED,       CONCAT_ARGS, NO_OBJ ),
+  T1("published",           K_PUBLISHED,       CONCAT_ARGS, NO_OBJ ),
   T( "opt",                 K_OPT,             CONCAT_ARGS, OBJ_OK ),
   T( "contact",             K_CONTACT,         CONCAT_ARGS, NO_OBJ ),
   T( "dir-signing-key",     K_DIR_SIGNING_KEY,     ARGS,    OBJ_OK ),
@@ -479,10 +479,8 @@
     log_warn(LD_DIR, "Error tokenizing directory"); goto err;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
-    log_warn(LD_DIR, "Missing published time on directory.");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_PUBLISHED);
+  tor_assert(tok);
   tor_assert(tok->n_args == 1);
 
   if (parse_iso_time(tok->args[0], &published_on) < 0) {
@@ -534,10 +532,8 @@
     goto err;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
-    log_warn(LD_DIR, "Missing published time on running-routers.");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_PUBLISHED);
+  tor_assert(tok);
   tor_assert(tok->n_args == 1);
   if (parse_iso_time(tok->args[0], &published_on) < 0) {
      goto err;
@@ -905,16 +901,14 @@
     }
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
-    log_warn(LD_DIR, "Missing published time on router descriptor"); goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_PUBLISHED);
+  tor_assert(tok);
   tor_assert(tok->n_args == 1);
   if (parse_iso_time(tok->args[0], &router->cache_info.published_on) < 0)
     goto err;
 
-  if (!(tok = find_first_by_keyword(tokens, K_ONION_KEY))) {
-    log_warn(LD_DIR, "Missing onion key"); goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_ONION_KEY);
+  tor_assert(tok);
   if (crypto_pk_keysize(tok->key) != PK_BYTES) {
     log_warn(LD_DIR, "Wrong size on onion key: %d bits!",
              (int)crypto_pk_keysize(tok->key)*8);
@@ -923,9 +917,8 @@
   router->onion_pkey = tok->key;
   tok->key = NULL; /* Prevent free */
 
-  if (!(tok = find_first_by_keyword(tokens, K_SIGNING_KEY))) {
-    log_warn(LD_DIR, "Missing identity key"); goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_SIGNING_KEY);
+  tor_assert(tok);
   if (crypto_pk_keysize(tok->key) != PK_BYTES) {
     log_warn(LD_DIR, "Wrong size on identity key: %d bits!",
            (int)crypto_pk_keysize(tok->key)*8);
@@ -1006,10 +999,8 @@
     }
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_ROUTER_SIGNATURE))) {
-    log_warn(LD_DIR, "Missing router signature");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_ROUTER_SIGNATURE);
+  tor_assert(tok);
   if (strcmp(tok->object_type, "SIGNATURE") || tok->object_size != 128) {
     log_warn(LD_DIR, "Bad object type or length on router signature");
     goto err;
@@ -1121,10 +1112,8 @@
     goto err;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
-    log_warn(LD_DIR,"No published time on \"extra-info\"");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_PUBLISHED);
+  tor_assert(tok);
   if (parse_iso_time(tok->args[0], &extrainfo->cache_info.published_on)) {
     log_warn(LD_DIR,"Invalid published time %s on \"extra-info\"",
              escaped(tok->args[0]));
@@ -1137,10 +1126,8 @@
     key = router->identity_pkey;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_ROUTER_SIGNATURE))) {
-    log_warn(LD_DIR, "Missing router signature");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_ROUTER_SIGNATURE);
+  tor_assert(tok);
   if (strcmp(tok->object_type, "SIGNATURE") || tok->object_size != 128) {
     log_warn(LD_DIR, "Bad object type or length on router signature");
     goto err;
@@ -1214,10 +1201,8 @@
     log_warn(LD_DIR, "Impossibly short router status");
     goto err;
   }
-  if (!(tok = find_first_by_keyword(tokens, K_R))) {
-    log_warn(LD_DIR, "Missing 'r' keywork in router status; skipping.");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_R);
+  tor_assert(tok);
   if (tok->n_args < 8) {
     log_warn(LD_DIR,
          "Too few arguments to 'r' keywork in router status; skipping.");
@@ -1362,15 +1347,11 @@
   ns = tor_malloc_zero(sizeof(networkstatus_t));
   memcpy(ns->networkstatus_digest, ns_digest, DIGEST_LEN);
 
-  if (!(tok = find_first_by_keyword(tokens, K_NETWORK_STATUS_VERSION))) {
-    log_warn(LD_DIR, "Couldn't find network-status-version keyword");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_NETWORK_STATUS_VERSION);
+  tor_assert(tok);
 
-  if (!(tok = find_first_by_keyword(tokens, K_DIR_SOURCE))) {
-    log_warn(LD_DIR, "Couldn't find dir-source keyword");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_DIR_SOURCE);
+  tor_assert(tok);
   if (tok->n_args < 3) {
     log_warn(LD_DIR, "Too few arguments to dir-source keyword");
     goto err;
@@ -1389,10 +1370,8 @@
     goto err;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_FINGERPRINT))) {
-    log_warn(LD_DIR, "Couldn't find fingerprint keyword");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_FINGERPRINT);
+  tor_assert(tok);
   if (tok->n_args < 1) {
     log_warn(LD_DIR, "Too few arguments to networkstatus fingerprint");
     goto err;
@@ -1409,10 +1388,8 @@
     tok->args[0] = NULL;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_DIR_SIGNING_KEY)) || !tok->key) {
-    log_warn(LD_DIR, "Missing dir-signing-key");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_DIR_SIGNING_KEY);
+  tor_assert(tok && tok->key);
   ns->signing_key = tok->key;
   tok->key = NULL;
 
@@ -1456,10 +1433,8 @@
     tok->args[0] = NULL;
   }
 
-  if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
-    log_warn(LD_DIR, "Missing published time on network-status.");
-    goto err;
-  }
+  tok = find_first_by_keyword(tokens, K_PUBLISHED);
+  tor_assert(tok);
   tor_assert(tok->n_args == 1);
   if (parse_iso_time(tok->args[0], &ns->published_on) < 0) {
      goto err;