[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r12020: Fix up logic for choosing the time at which to download a co (in tor/trunk: . src/or)



Author: nickm
Date: 2007-10-18 10:19:56 -0400 (Thu, 18 Oct 2007)
New Revision: 12020

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/networkstatus.c
Log:
 r15907@catbus:  nickm | 2007-10-18 10:18:53 -0400
 Fix up logic for choosing the time at which to download a consensus: Never attempt it when the current consensus is still the most recent.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r15907] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-10-18 14:19:53 UTC (rev 12019)
+++ tor/trunk/ChangeLog	2007-10-18 14:19:56 UTC (rev 12020)
@@ -40,6 +40,8 @@
     - Delete unverified-consensus when the real consensus is set.
     - Consider retrying a consensus networkstatus fetch immediately after one
       fails: don't wait 60 seconds to notice.
+    - When fetching a consensus as a cache, wait until a newer consensus
+      exists before trying to replace the current one.
 
   o Minor bugfixes (controller):
     - Don't reset trusted dir server list when we set a configuration option.

Modified: tor/trunk/src/or/networkstatus.c
===================================================================
--- tor/trunk/src/or/networkstatus.c	2007-10-18 14:19:53 UTC (rev 12019)
+++ tor/trunk/src/or/networkstatus.c	2007-10-18 14:19:56 UTC (rev 12020)
@@ -761,21 +761,24 @@
   /* XXXX020 call this when DirPort switches on or off. NMNM */
   networkstatus_vote_t *c = networkstatus_get_live_consensus(now);
   if (c) {
+    long dl_interval;
+    long interval = c->fresh_until - c->valid_after;
     time_t start;
-    long interval;
     if (dirserver_mode(options)) {
-      start = c->valid_after + 120; /*XXXX020 make this a macro. */
-      /* XXXX020 too much magic. */
-      interval = (c->fresh_until - c->valid_after) / 2;
+      start = c->fresh_until + 120; /*XXXX020 make this a macro. */
+      dl_interval = interval/2;
     } else {
-      start = c->fresh_until;
+      start = c->fresh_until + (interval*3)/4;
       /* XXXX020 too much magic. */
-      interval = (c->valid_until - c->fresh_until) * 7 / 8;
+      dl_interval = (c->valid_until - start) * 7 / 8;
     }
-    if (interval < 1)
-      interval = 1;
-    tor_assert(start+interval < c->valid_until);
-    time_to_download_next_consensus = start + crypto_rand_int(interval);
+    if (dl_interval < 1)
+      dl_interval = 1;
+    /* We must not try to replace c while it's still the most valid: */
+    tor_assert(c->fresh_until < start);
+    /* We must download the next one before c is invalid: */
+    tor_assert(start+dl_interval < c->valid_until);
+    time_to_download_next_consensus = start + crypto_rand_int(dl_interval);
     {
       char tbuf[ISO_TIME_LEN+1];
       format_local_iso_time(tbuf, time_to_download_next_consensus);