[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r17786: {tor} Document and make more conservative the logic for picking th (tor/trunk/src/or)
Author: nickm
Date: 2008-12-26 12:35:36 -0500 (Fri, 26 Dec 2008)
New Revision: 17786
Modified:
tor/trunk/src/or/routerlist.c
Log:
Document and make more conservative the logic for picking the size of the bloom filter to use for retaining descriptors.
Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c 2008-12-26 17:35:18 UTC (rev 17785)
+++ tor/trunk/src/or/routerlist.c 2008-12-26 17:35:36 UTC (rev 17786)
@@ -3232,7 +3232,6 @@
int caches = directory_caches_dir_info(get_options());
const networkstatus_t *consensus = networkstatus_get_latest_consensus();
const smartlist_t *networkstatus_v2_list = networkstatus_get_v2_list();
- int n_expected_retain = 0;
trusted_dirs_remove_old_certs();
@@ -3241,18 +3240,26 @@
// routerlist_assert_ok(routerlist);
- n_expected_retain = smartlist_len(consensus->routerstatus_list);
- if (caches &&
- networkstatus_v2_list && smartlist_len(networkstatus_v2_list)) {
- SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns,
- n_expected_retain += smartlist_len(ns->entries));
- /* DOCDOC XXX021 too much magic. */
- n_expected_retain /= (smartlist_len(networkstatus_v2_list)/2+1);
+ /* We need to guess how many router descriptors we will wind up wanting to
+ retain, so that we can be sure to allocate a large enough Bloom filter
+ to hold the digest set. Overestimating is fine; underestimating is bad.
+ */
+ {
+ /* We'll probably retain everything in the consensus. */
+ int n_max_retain = smartlist_len(consensus->routerstatus_list);
+ if (caches && networkstatus_v2_list) {
+ /* If we care about v2 statuses, we'll retain at most as many as are
+ listed any of the v2 statues. This will be at least the length of
+ the largest v2 networstatus, and in the worst case, this set will be
+ equal to the sum of the lengths of all v2 consensuses. Take the
+ worst case.
+ */
+ SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns,
+ n_max_retain += smartlist_len(ns->entries));
+ }
+ retain = digestset_new(n_max_retain);
}
- //log_notice(LD_DIR,"n_expected_retain=%d",n_expected_retain);
- retain = digestset_new(n_expected_retain);
-
cutoff = now - OLD_ROUTER_DESC_MAX_AGE;
/* Build a list of all the descriptors that _anybody_ lists. */
if (caches) {