]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Change who calls microdesc_cache_rebuild().
authorNick Mathewson <nickm@torproject.org>
Tue, 3 May 2011 21:28:28 +0000 (17:28 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 3 May 2011 21:28:28 +0000 (17:28 -0400)
Previously we ensured that it would get called periodically by doing
it from inside the code that added microdescriptors.  That won't work
though: it would interfere with our code that tried to read microdescs
from disk initially.  Instead, we should consider rebuilding the cache
periodically, and on startup.

changes/bug2230_part4 [new file with mode: 0644]
src/or/main.c
src/or/microdesc.c

diff --git a/changes/bug2230_part4 b/changes/bug2230_part4
new file mode 100644 (file)
index 0000000..f7721fa
--- /dev/null
@@ -0,0 +1,6 @@
+  o Minor bugfixes:
+    - Authorities now clean their microdesc cache periodically and when
+      reading from disk initially, not only when adding new descriptors.
+      This prevents a bug where we could lose microdescriptors.  Bugfix
+      on 0.2.2.6-alpha.
+
index a26be39fdf8b830d5000100207c81beae312c7b8..462b51e78337484b96024328c32fe82812ca5fbd 100644 (file)
@@ -1075,6 +1075,8 @@ run_scheduled_events(time_t now)
     rep_history_clean(now - options->RephistTrackTime);
     rend_cache_clean();
     rend_cache_clean_v2_descs_as_dir();
+    if (authdir_mode_v3(options))
+      microdesc_cache_rebuild(NULL, 0);
 #define CLEAN_CACHES_INTERVAL (30*60)
     time_to_clean_caches = now + CLEAN_CACHES_INTERVAL;
   }
index c6bb3c61f64967dfc2aada4cb657833c1f6a4ec5..73d22850096472ea6a043cb24137df6aa3073b58 100644 (file)
@@ -208,8 +208,6 @@ microdescs_add_list_to_cache(microdesc_cache_t *cache,
   if (f)
     finish_writing_to_file(open_file); /*XXX Check me.*/
 
-  microdesc_cache_rebuild(cache, 0/* only as needed */);
-
   return added;
 }
 
@@ -230,6 +228,7 @@ microdesc_cache_clear(microdesc_cache_t *cache)
   }
   cache->total_len_seen = 0;
   cache->n_seen = 0;
+  cache->bytes_dropped = 0;
 }
 
 /** Reload the contents of <b>cache</b> from disk.  If it is empty, load it
@@ -271,7 +270,7 @@ microdesc_cache_reload(microdesc_cache_t *cache)
   log_notice(LD_DIR, "Reloaded microdescriptor cache.  Found %d descriptors.",
              total);
 
-  microdesc_cache_clean(cache, 0, 0);
+  microdesc_cache_rebuild(cache, 0 /* don't force */);
 
   return 0;
 }
@@ -354,6 +353,12 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
   off_t off = 0;
   int orig_size, new_size;
 
+  if (cache == NULL) {
+    cache = the_microdesc_cache;
+    if (cache == NULL)
+      return 0;
+  }
+
   /* Remove dead descriptors */
   microdesc_cache_clean(cache, 0/*cutoff*/, 0/*force*/);