aboutsummaryrefslogtreecommitdiff
path: root/src/or/microdesc.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-09-28 14:13:49 -0400
committerNick Mathewson <nickm@torproject.org>2011-09-28 14:13:49 -0400
commit4a10845075d14df285e52ea4bdd72ff12c10c959 (patch)
tree71fb9014fa5682c2f174a545f6e40c97d7ce6af8 /src/or/microdesc.c
parenta4b7525c3ce596d4221575806d44652aaa9047a9 (diff)
downloadtor-4a10845075d14df285e52ea4bdd72ff12c10c959.tar
tor-4a10845075d14df285e52ea4bdd72ff12c10c959.tar.gz
Add some debugging code to microdesc.[ch]
Diffstat (limited to 'src/or/microdesc.c')
-rw-r--r--src/or/microdesc.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 0517e47ea..92f5c0358 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -499,6 +499,28 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
return 0;
}
+/** Make sure that the reference count of every microdescriptor in cache is
+ * accurate. */
+void
+microdesc_check_counts(void)
+{
+ microdesc_t **mdp;
+ if (!the_microdesc_cache)
+ return;
+
+ HT_FOREACH(mdp, microdesc_map, &the_microdesc_cache->map) {
+ microdesc_t *md = *mdp;
+ unsigned int found=0;
+ const smartlist_t *nodes = nodelist_get_list();
+ SMARTLIST_FOREACH(nodes, node_t *, node, {
+ if (node->md == md) {
+ ++found;
+ }
+ });
+ tor_assert(found == md->held_by_nodes);
+ }
+}
+
/** Deallocate a single microdescriptor. Note: the microdescriptor MUST have
* previously been removed from the cache if it had ever been inserted. */
void
@@ -535,8 +557,8 @@ microdesc_free(microdesc_t *md)
log_warn(LD_BUG, "microdesc_free() called, but md was still referenced "
"%d node(s); held_by_nodes == %u", found, md->held_by_nodes);
} else {
- log_warn(LD_BUG, "microdesc_free() called with held_by_nodes set, but "
- "md was not refrenced by any nodes");
+ log_warn(LD_BUG, "microdesc_free() called with held_by_nodes set to %u, "
+ "but md was not referenced by any nodes", md->held_by_nodes);
}
tor_fragile_assert();
}