[or-cvs] Refactor the decision of whether to include a router"s desc...

arma at seul.org arma at seul.org
Wed Mar 29 08:56:42 UTC 2006


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	dirserv.c 
Log Message:
Refactor the decision of whether to include a router's descriptor
in the v1 directory. No actual changes yet.


Index: dirserv.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.317
retrieving revision 1.318
diff -u -p -d -r1.317 -r1.318
--- dirserv.c	28 Mar 2006 12:01:58 -0000	1.317
+++ dirserv.c	29 Mar 2006 08:56:39 -0000	1.318
@@ -743,7 +743,19 @@ format_versions_list(config_line_t *ln)
   return result;
 }
 
-/** Generate a new directory and write it into a newly allocated string.
+/** Return 1 if <b>ri</b>'s descriptor is worth including in the v1
+ * directory, else return 0.
+ */
+static int
+live_enough_for_v1_dir(routerinfo_t *ri, time_t now)
+{
+  time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
+  if (ri->cache_info.published_on < cutoff)
+    return 0;
+  return 1;
+}
+
+/** Generate a new v1 directory and write it into a newly allocated string.
  * Point *<b>dir_out</b> to the allocated string.  Sign the
  * directory with <b>private_key</b>.  Return 0 on success, -1 on
  * failure.
@@ -763,7 +775,6 @@ dirserv_dump_directory_to_string(char **
   size_t identity_pkey_len;
   routerlist_t *rl = router_get_routerlist();
   time_t now = time(NULL);
-  time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
 
   tor_assert(dir_out);
   *dir_out = NULL;
@@ -785,7 +796,7 @@ dirserv_dump_directory_to_string(char **
   buf_len = 2048+strlen(recommended_versions)+
     strlen(router_status);
   SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri,
-                    if (ri->cache_info.published_on >= cutoff)
+                    if (live_enough_for_v1_dir(ri, now))
                       buf_len += ri->cache_info.signed_descriptor_len+1);
   buf = tor_malloc(buf_len);
   /* We'll be comparing against buf_len throughout the rest of the
@@ -811,7 +822,7 @@ dirserv_dump_directory_to_string(char **
     {
       size_t len = ri->cache_info.signed_descriptor_len;
       const char *body;
-      if (ri->cache_info.published_on < cutoff)
+      if (!live_enough_for_v1_dir(ri, now))
         continue;
       if (cp+len+1 >= buf+buf_len)
         goto truncated;
@@ -1065,7 +1076,7 @@ dirserv_get_directory(const char **direc
 }
 
 /**
- * Generate a fresh directory (authdirservers only.)
+ * Generate a fresh v1 directory (authdirservers only.)
  */
 static int
 dirserv_regenerate_directory(void)



More information about the tor-commits mailing list