aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2013-03-07 15:55:01 -0800
committerAndrea Shepard <andrea@torproject.org>2013-03-07 15:55:01 -0800
commitb5224348340238f231f81138c09f7f16541d0f1d (patch)
tree320158cb1b98d674a7259adffa53482b3b7bfc01 /src
parent6e978ab8294eda5bb9a658c8d062bdd0098a9ac5 (diff)
downloadtor-b5224348340238f231f81138c09f7f16541d0f1d.tar.gz
tor-b5224348340238f231f81138c09f7f16541d0f1d.zip
Use DIGESTMAP_FOREACH_MODIFY in dirserv_expire_measured_bw_cache() for concision
Diffstat (limited to 'src')
-rw-r--r--src/or/dirserv.c35
1 files changed, 6 insertions, 29 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index e97def7181..b6ff6f6941 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2100,38 +2100,15 @@ dirserv_clear_measured_bw_cache(void)
void
dirserv_expire_measured_bw_cache(time_t now)
{
- digestmap_iter_t *itr = NULL;
- const char *k = NULL;
- void *e_v = NULL;
- mbw_cache_entry_t *e = NULL;
- int rmv;
if (mbw_cache) {
- /* Start iterating */
- itr = digestmap_iter_init(mbw_cache);
- while (!digestmap_iter_done(itr)) {
- rmv = 0;
- digestmap_iter_get(itr, &k, &e_v);
- e = (mbw_cache_entry_t *)e_v;
- if (e) {
- /* Check for expiration and remove if so */
- if (now > e->as_of + MAX_MEASUREMENT_AGE) {
- tor_free(e);
- rmv = 1;
- }
- } else {
- /* Weird; remove it and complain */
- log_warn(LD_BUG, "Saw NULL entry in measured bandwidth cache");
- rmv = 1;
+ /* Iterate through the cache and check each entry */
+ DIGESTMAP_FOREACH_MODIFY(mbw_cache, k, mbw_cache_entry_t *, e) {
+ if (now > e->as_of + MAX_MEASUREMENT_AGE) {
+ tor_free(e);
+ MAP_DEL_CURRENT(k);
}
-
- /* Advance, or remove and advance */
- if (rmv) {
- itr = digestmap_iter_next_rmv(mbw_cache, itr);
- } else {
- itr = digestmap_iter_next(mbw_cache, itr);
- }
- }
+ } DIGESTMAP_FOREACH_END;
/* Check if we cleared the whole thing and free if so */
if (digestmap_size(mbw_cache) == 0) {