From 36109fea334deee546a43bd8c7e22bba36f21f98 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 23 Nov 2005 07:06:36 +0000 Subject: [PATCH] e more aggressive about calling routerlist_remove_old_routers() svn:r5444 --- src/or/routerlist.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 1100821b77..f3e3ff3720 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -34,6 +34,8 @@ static int routerdesc_digest_is_recognized(const char *identity, const char *digest); static void routerlist_assert_ok(routerlist_t *rl); +#define MAX_DESCRIPTORS_PER_ROUTER 5 + /****************************************************************************/ /** Global list of a trusted_dir_server_t object for each trusted directory @@ -1137,7 +1139,7 @@ dump_routerlist_mem_usage(int severity) SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, r, livedescs += r->cache_info.signed_descriptor_len); SMARTLIST_FOREACH(routerlist->old_routers, signed_descriptor_t *, sd, - livedescs += sd->signed_descriptor_len); + olddescs += sd->signed_descriptor_len); log(severity, LD_GENERAL, "In %d live descriptors: "U64_FORMAT" bytes. " @@ -1146,6 +1148,13 @@ dump_routerlist_mem_usage(int severity) smartlist_len(routerlist->old_routers), U64_PRINTF_ARG(olddescs)); } +static INLINE int +routerlist_is_overfull(routerlist_t *rl) +{ + return smartlist_len(rl->old_routers) > + smartlist_len(rl->routers)*(MAX_DESCRIPTORS_PER_ROUTER+1); +} + static INLINE int _routerlist_find_elt(smartlist_t *sl, void *ri, int idx) { @@ -1431,6 +1440,9 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg, return -1; } + if (routerlist_is_overfull(routerlist)) + routerlist_remove_old_routers(); + if (authdir) { if (authdir_wants_to_reject_router(router, msg)) { routerinfo_free(router); @@ -1537,8 +1549,6 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg, return 0; } -#define MAX_DESCRIPTORS_PER_ROUTER 5 - static int _compare_old_routers_by_identity(const void **_a, const void **_b) { @@ -3267,7 +3277,6 @@ routerlist_assert_ok(routerlist_t *rl) digestmap_iter_t *iter; routerinfo_t *r2; signed_descriptor_t *sd2; - uint32_t bytes = 0; if (!routerlist) return; SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,