[or-cvs] r10607: Directories no longer return a "304 not modified" when they (in tor/trunk: . src/or)

arma at seul.org arma at seul.org
Fri Jun 15 04:20:51 UTC 2007


Author: arma
Date: 2007-06-15 00:20:51 -0400 (Fri, 15 Jun 2007)
New Revision: 10607

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirserv.c
Log:
Directories no longer return a "304 not modified" when they don't
have the networkstatus the client asked for. Also fix a memory
leak when returning 304 not modified. [Bugfixes on 0.2.0.2-alpha]


Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-06-15 04:14:01 UTC (rev 10606)
+++ tor/trunk/ChangeLog	2007-06-15 04:20:51 UTC (rev 10607)
@@ -21,6 +21,9 @@
   o Minor bugfixes (directory):
     - Fix another crash bug related to extra-info caching.  (Bug found by
       Peter Palfrader.) [Bugfix on 0.2.0.2-alpha]
+    - Directories no longer return a "304 not modified" when they don't
+      have the networkstatus the client asked for. Also fix a memory
+      leak when returning 304 not modified. [Bugfixes on 0.2.0.2-alpha]
 
   o Minor bugfixes (dns):
     - Fix a crash when DNSPort is set more than once. (Patch from Robert

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-06-15 04:14:01 UTC (rev 10606)
+++ tor/trunk/src/or/directory.c	2007-06-15 04:20:51 UTC (rev 10607)
@@ -1806,6 +1806,8 @@
     }
     if (dirserv_statuses_are_old(dir_fps, if_modified_since)) {
       write_http_status_line(conn, 304, "Not modified");
+      /* no need to free dir_fps's elements, since
+       * dirserv_statuses_are_old() already did. */
       smartlist_free(dir_fps);
       return 0;
     }

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2007-06-15 04:14:01 UTC (rev 10606)
+++ tor/trunk/src/or/dirserv.c	2007-06-15 04:20:51 UTC (rev 10607)
@@ -2538,29 +2538,31 @@
     ctr = (ctr + 1) % 128;
 }
 
-/** Return true iff every networkstatus listed in <b>fps</b> is older
- * than <b>cutoff</b>. */
+/** Remove from <b>fps</b> every networkstatus key where both
+ * a) we have a networkstatus document and
+ * b) it is not newer than <b>cutoff</b>.
+ *
+ * Return 1 if no keys remain, else return 0.
+ */
 int
 dirserv_statuses_are_old(smartlist_t *fps, time_t cutoff)
 {
-  SMARTLIST_FOREACH(fps, const char *, digest,
+  SMARTLIST_FOREACH(fps, char *, digest,
   {
     cached_dir_t *d;
     if (router_digest_is_me(digest) && the_v2_networkstatus)
       d = the_v2_networkstatus;
     else
       d = digestmap_get(cached_v2_networkstatus, digest);
-    if (d && d->published > cutoff)
-      return 0;
-    /* XXX020 The above is causing my dir cache to send "304 Not modified"
-     * to clients that never specified an If-Modified-Since header. That's
-     * because d isn't defined for the networkstatus the client is asking
-     * for, so we end up returning 1. Perhaps the right fix above is
-     * "if (!d || d->published >= cutoff)"? -RD
-     */
+    if (d && d->published <= cutoff) {
+      tor_free(digest);
+      SMARTLIST_DEL_CURRENT(fps, digest);
+    }
   });
 
-  return 1;
+  if (smartlist_len(fps))
+    return 0; /* some items were not here or were not old */
+  return 1; /* all items were here and old */
 }
 
 /** Return an approximate estimate of the number of bytes that will



More information about the tor-commits mailing list