[or-cvs] Remove 1024-router limit in routerparse.c; unify handling o...

Nick Mathewson nickm at seul.org
Fri Jul 16 23:05:43 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv6311/src/or

Modified Files:
	dirserv.c or.h routerlist.c routerparse.c 
Log Message:
Remove 1024-router limit in routerparse.c; unify handling of running-routers lines in running-routers requests and in directories; set is_verified field of routerinfo_ts correctly; use most-recent-info rule to decide whether to change router-is-running status.

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- dirserv.c	13 Jul 2004 18:23:40 -0000	1.59
+++ dirserv.c	16 Jul 2004 23:05:40 -0000	1.60
@@ -469,8 +469,9 @@
     if (router_nickname_is_approved(conn->nickname, conn->identity_digest)) {
       name = tor_strdup(conn->nickname);
     } else {
-      name = tor_malloc(HEX_DIGEST_LEN+1);
-      base16_encode(name, HEX_DIGEST_LEN, conn->identity_digest, DIGEST_LEN);
+      name = tor_malloc(HEX_DIGEST_LEN+2);
+      *name = '$';
+      base16_encode(name+1, HEX_DIGEST_LEN, conn->identity_digest, DIGEST_LEN);
     }
 
     if(conn->state == OR_CONN_STATE_OPEN)

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.380
retrieving revision 1.381
diff -u -d -r1.380 -r1.381
--- or.h	16 Jul 2004 22:23:18 -0000	1.380
+++ or.h	16 Jul 2004 23:05:40 -0000	1.381
@@ -584,6 +584,8 @@
                                       * to exit? */
   /* local info */
   int is_running; /**< As far as we know, is this OR currently running? */
+  time_t status_set_at; /**< When did we last update is_running? */
+  int is_verified; /**< Has a trusted dirserver validated this OR? */
   int is_trusted_dir; /**< Do we trust this OR as a directory server? */
 
 } routerinfo_t;
@@ -1381,6 +1383,9 @@
 void running_routers_free(running_routers_t *rr);
 void routerlist_update_from_runningrouters(routerlist_t *list,
                                            running_routers_t *rr);
+void router_update_status_from_smartlist(routerinfo_t *r,
+                                         time_t list_time,
+                                         smartlist_t *running_list);
 
 /********************************* routerparse.c ************************/
 
@@ -1397,9 +1402,8 @@
 int router_get_dir_hash(const char *s, char *digest);
 int router_get_runningrouters_hash(const char *s, char *digest);
 int router_parse_list_from_string(const char **s,
-                                       routerlist_t **dest,
-                                       int n_good_nicknames,
-                                       const char **good_nickname_lst);
+                                  routerlist_t **dest,
+                                  smartlist_t *good_nickname_list);
 int router_parse_routerlist_from_directory(const char *s,
                                            routerlist_t **dest,
                                            crypto_pk_env_t *pkey);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- routerlist.c	16 Jul 2004 22:23:18 -0000	1.97
+++ routerlist.c	16 Jul 2004 23:05:40 -0000	1.98
@@ -93,6 +93,7 @@
     if(router->is_trusted_dir) {
       tor_assert(router->dir_port > 0);
       router->is_running = 1;
+      router->status_set_at = time(NULL);
       smartlist_add(sl, router);
     }
   }
@@ -391,6 +392,7 @@
     return;
   log_fn(LOG_DEBUG,"Marking %s as down.",router->nickname);
   router->is_running = 0;
+  router->status_set_at = time(NULL);
 }
 
 /** Add <b>router</b> to the routerlist, if we don't already have it.  Replace
@@ -523,7 +525,7 @@
 {
   routerlist_t *new_list=NULL;
 
-  if (router_parse_list_from_string(&s, &new_list, -1, NULL)) {
+  if (router_parse_list_from_string(&s, &new_list, NULL)) {
     log(LOG_WARN, "Error parsing router file");
     return -1;
   }
@@ -743,9 +745,8 @@
 void routerlist_update_from_runningrouters(routerlist_t *list,
                                            running_routers_t *rr)
 {
-  int n_routers, n_names, i, j, running;
+  int n_routers, i;
   routerinfo_t *router;
-  const char *name;
   if (!list)
     return;
   if (list->published_on >= rr->published_on)
@@ -754,26 +755,55 @@
     return;
 
   n_routers = smartlist_len(list->routers);
-  n_names = smartlist_len(rr->running_routers);
   for (i=0; i<n_routers; ++i) {
-    running = 0;
     router = smartlist_get(list->routers, i);
-    for (j=0; j<n_names; ++j) {
-      name = smartlist_get(rr->running_routers, j);
-      if (*name != '!') {
-        if (router_nickname_matches(router, name)) {
+    router_update_status_from_smartlist(router,
+                                        rr->published_on,
+                                        rr->running_routers);
+  }
+  list->running_routers_updated_on = rr->published_on;
+}
+
+/** Update the is_running and is_verified fields of the router <b>router</b>,
+ * based in its status in the list of strings stored in <b>running_list</b>.
+ * All entries in <b>running_list</b> follow one of these formats:
+ * <ol><li> <b>nickname</b> -- router is running and verified.
+ *     <li> !<b>nickname</b> -- router is not-running and verified.
+ *     <li> $<b>hexdigest</b> -- router is running and unverified.
+ *     <li> !$<b>hexdigest</b> -- router is not-running and unverified.
+ * </ol>
+ */
+void router_update_status_from_smartlist(routerinfo_t *router,
+                                         time_t list_time,
+                                         smartlist_t *running_list)
+{
+  int n_names, i, running, approved;
+  const char *name;
+  running = approved = 0;
+
+  n_names = smartlist_len(running_list);
+  for (i=0; i<n_names; ++i) {
+    name = smartlist_get(running_list, i);
+    if (*name != '!') {
+      if (router_nickname_matches(router, name)) {
+        if (router->status_set_at < list_time) {
+          router->status_set_at = list_time;
           router->is_running = 1;
-          break;
         }
-      } else { /* *name == '!' */
-        if (router_nickname_matches(router, name)) {
+        router->is_verified = (name[1] != '$');
+        return;
+      }
+    } else { /* *name == '!' */
+      if (router_nickname_matches(router, name)) {
+        if (router->status_set_at < list_time) {
+          router->status_set_at = list_time;
           router->is_running = 0;
-          break;
         }
+        router->is_verified = (name[1] != '$');
+        return;
       }
     }
   }
-  list->running_routers_updated_on = rr->published_on;
 }
 
 /*

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerparse.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- routerparse.c	16 Jul 2004 22:23:18 -0000	1.12
+++ routerparse.c	16 Jul 2004 23:05:40 -0000	1.13
@@ -291,8 +291,7 @@
   char digest[DIGEST_LEN];
   routerlist_t *new_dir = NULL;
   char *versions = NULL;
-  int n_good_nicknames = 0;
-  char *good_nickname_lst[1024]; /* XXXX008 correct this limit. */
+  smartlist_t *good_nickname_list = NULL;
   time_t published_on;
   int i, r;
   const char *end;
@@ -355,22 +354,21 @@
     goto err;
   }
 
-  n_good_nicknames = tok->n_args;
-  memcpy(good_nickname_lst, tok->args, n_good_nicknames*sizeof(char *));
+  good_nickname_list = smartlist_create();
+  for (i=0; i<tok->n_args; ++i) {
+    smartlist_add(good_nickname_list, tok->args[i]);
+  }
   tok->n_args = 0; /* Don't free the strings in good_nickname_lst yet. */
 
   /* Read the router list from s, advancing s up past the end of the last
    * router. */
   str = end;
   if (router_parse_list_from_string(&str, &new_dir,
-				    n_good_nicknames,
-				    (const char**)good_nickname_lst)) {
+				    good_nickname_list)) {
     log_fn(LOG_WARN, "Error reading routers from directory");
     goto err;
   }
-  for (i = 0; i < n_good_nicknames; ++i) {
-    tor_free(good_nickname_lst[i]); /* now free them */
-  }
+
   new_dir->software_versions = versions; versions = NULL;
   new_dir->published_on = published_on;
 
@@ -402,14 +400,15 @@
   if (new_dir)
     routerlist_free(new_dir);
   tor_free(versions);
-  for (i = 0; i < n_good_nicknames; ++i) {
-    tor_free(good_nickname_lst[i]);
-  }
  done:
   if (tokens) {
     SMARTLIST_FOREACH(tokens, directory_token_t *, tok, token_free(tok));
     smartlist_free(tokens);
   }
+  if (good_nickname_list) {
+    SMARTLIST_FOREACH(good_nickname_list, char *, n, tor_free(n));
+    smartlist_free(good_nickname_list);
+  }
   return r;
 }
 
@@ -531,22 +530,21 @@
 }
 
 
-/** Given a string *<b>s</b> containing a concatenated
- * sequence of router descriptors, parses them and stores the result
- * in *<b>dest</b>.  If good_nickname_lst is provided, then routers whose
- * nicknames are not listed are marked as nonrunning.  Advances *s to
- * a point immediately following the last router entry.  Returns 0 on
+/** Given a string *<b>s</b> containing a concatenated sequence of router
+ * descriptors, parses them and stores the result in *<b>dest</b>.  If
+ * good_nickname_list is provided, then routers are mared as
+ * running/nonrunning and verified/unverified based on their status in the
+ * list.  Otherwise, all routers are marked running and verified.  Advances
+ * *s to a point immediately following the last router entry.  Returns 0 on
  * success and -1 on failure.
  */
 int
 router_parse_list_from_string(const char **s, routerlist_t **dest,
-			      int n_good_nicknames,
-			      const char **good_nickname_list)
+                              smartlist_t *good_nickname_list)
 {
   routerinfo_t *router;
   smartlist_t *routers;
   int rarray_len = 0;
-  int i;
   const char *end;
 
   tor_assert(s && *s);
@@ -573,16 +571,13 @@
       continue;
     }
 
-    if (n_good_nicknames>=0) {
-      router->is_running = 0;
-      for (i = 0; i < n_good_nicknames; ++i) {
-        if (router_nickname_matches(router, good_nickname_list[i])) {
-          router->is_running = 1;
-          break;
-        }
-      }
+    if (good_nickname_list) {
+      router_update_status_from_smartlist(router, time(NULL),
+                                          good_nickname_list);
     } else {
       router->is_running = 1; /* start out assuming all dirservers are up */
+      router->is_verified = 1;
+      router->status_set_at = time(NULL);
     }
     smartlist_add(routers, router);
     log_fn(LOG_DEBUG,"just added router #%d.",rarray_len);



More information about the tor-commits mailing list