From db1209a852ac7ecebe26eab40c2da8fa19e3468f Mon Sep 17 00:00:00 2001
From: Roger Dingledine <arma@torproject.org>
Date: Wed, 29 Mar 2006 08:56:39 +0000
Subject: Refactor the decision of whether to include a router's descriptor in
 the v1 directory. No actual changes yet.

svn:r6272
---
 src/or/dirserv.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

(limited to 'src/or/dirserv.c')

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 258ec21ec..f73adf9e1 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -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 **dir_out,
   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 **dir_out,
   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 **dir_out,
     {
       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 **directory, int compress)
 }
 
 /**
- * Generate a fresh directory (authdirservers only.)
+ * Generate a fresh v1 directory (authdirservers only.)
  */
 static int
 dirserv_regenerate_directory(void)
-- 
cgit v1.2.3