mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
Add some debugging code to microdesc.[ch]
This commit is contained in:
parent
a4b7525c3c
commit
4a10845075
@ -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();
|
||||
}
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
microdesc_cache_t *get_microdesc_cache(void);
|
||||
|
||||
void microdesc_check_counts(void);
|
||||
|
||||
smartlist_t *microdescs_add_to_cache(microdesc_cache_t *cache,
|
||||
const char *s, const char *eos, saved_location_t where,
|
||||
int no_save, time_t listed_at,
|
||||
|
Loading…
Reference in New Issue
Block a user