Browse Source

r19202@catbus: nickm | 2008-04-04 17:18:47 -0400
Make last_served_at optional; make last_listed_as_valid_until take account (partially) of v2 statuses.


svn:r14299

Nick Mathewson 17 years ago
parent
commit
85db675911
3 changed files with 27 additions and 3 deletions
  1. 4 0
      src/or/dirserv.c
  2. 18 2
      src/or/networkstatus.c
  3. 5 1
      src/or/or.h

+ 4 - 0
src/or/dirserv.c

@@ -2939,7 +2939,9 @@ connection_dirserv_finish_spooling(dir_connection_t *conn)
 static int
 connection_dirserv_add_servers_to_outbuf(dir_connection_t *conn)
 {
+#ifdef TRACK_SERVED_TIME
   time_t now = time(NULL);
+#endif
   int by_fp = (conn->dir_spool_src == DIR_SPOOL_SERVER_BY_FP ||
                conn->dir_spool_src == DIR_SPOOL_EXTRA_BY_FP);
   int extra = (conn->dir_spool_src == DIR_SPOOL_EXTRA_BY_FP ||
@@ -2967,7 +2969,9 @@ connection_dirserv_add_servers_to_outbuf(dir_connection_t *conn)
        * unknown bridge descriptor has shown up between then and now. */
       continue;
     }
+#ifdef TRACK_SERVED_TIME
     sd->last_served_at = now;
+#endif
     body = signed_descriptor_get_body(sd);
     if (conn->zlib_state) {
       int last = ! smartlist_len(conn->fingerprint_stack);

+ 18 - 2
src/or/networkstatus.c

@@ -697,11 +697,24 @@ router_set_networkstatus_v2(const char *s, time_t arrived_at,
   if (!found)
     smartlist_add(networkstatus_v2_list, ns);
 
-  SMARTLIST_FOREACH(ns->entries, routerstatus_t *, rs,
+/*XXXX021 magic. */
+/*DOCDOC */
+#define V2_NETWORKSTATUS_LIFETIME (3*60*60)
+
+  {
+    time_t live_until = ns->published_on + V2_NETWORKSTATUS_LIFETIME;
+    SMARTLIST_FOREACH(ns->entries, routerstatus_t *, rs,
     {
-      if (!router_get_by_descriptor_digest(rs->descriptor_digest))
+      signed_descriptor_t *sd =
+        router_get_by_descriptor_digest(rs->descriptor_digest);
+      if (sd) {
+        if (sd->last_listed_as_valid_until < live_until)
+          sd->last_listed_as_valid_until = live_until;
+      } else {
         rs->need_to_mirror = 1;
+      }
     });
+  }
 
   log_info(LD_DIR, "Setting networkstatus %s %s (published %s)",
            source == NS_FROM_CACHE?"cached from":
@@ -1286,6 +1299,7 @@ notify_control_networkstatus_changed(const networkstatus_t *old_c,
   if (old_remain)
     rs_old = smartlist_get(old_c->routerstatus_list, idx);
 
+  /* XXXX021 candidate for a foreach_matched macro. */
   SMARTLIST_FOREACH(new_c->routerstatus_list, routerstatus_t *, rs_new,
   {
     if (!old_remain) {
@@ -1323,6 +1337,7 @@ networkstatus_copy_old_consensus_info(networkstatus_t *new_c,
     return;
 
   rs_old = smartlist_get(old_c->routerstatus_list, idx);
+  /* XXXX021 candidate for a FOREACH_MATCHED macro. */
   SMARTLIST_FOREACH(new_c->routerstatus_list, routerstatus_t *, rs_new,
   {
     int r;
@@ -1709,6 +1724,7 @@ routers_update_status_from_consensus_networkstatus(smartlist_t *routers,
   idx = 0;
   rs = smartlist_get(ns->routerstatus_list, idx);
 
+  /* Candidate for a FOREACH_MATCHED macro.XXX021 */
   SMARTLIST_FOREACH(routers, routerinfo_t *, router,
   {
     const char *digest = router->cache_info.identity_digest;

+ 5 - 1
src/or/or.h

@@ -1219,10 +1219,14 @@ typedef struct signed_descriptor_t {
    * routerlist->old_routers? -1 for none. */
   int routerlist_index;
   /** The valid-until time of the most recent consensus that listed this
-   * descriptor.  0 for "never listed in a consensus, so far as we know." */
+   * descriptor, or a bit after the publication time of the most recent v2
+   * networkstatus that listed it.  0 for "never listed in a consensus or
+   * status, so far as we know." */
   time_t last_listed_as_valid_until;
+#ifdef TRACK_SERVED_TIME
   /** DOCDOC */
   time_t last_served_at; /*XXXX021 remove if not useful. */
+#endif
   /* If true, we do not ever try to save this object in the cache. */
   unsigned int do_not_cache : 1;
   /* If true, this item is meant to represent an extrainfo. */