aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-11-01 17:34:17 +0000
committerNick Mathewson <nickm@torproject.org>2005-11-01 17:34:17 +0000
commit9e82f0cdb70839b5893147da446bb35a7b0ce3e6 (patch)
treeec92fdd89c48ed6517a6f999743d7a5ef3cb5c8b /src/or
parent80758473f833c110249f8ff4601c79bb4b19ec30 (diff)
downloadtor-9e82f0cdb70839b5893147da446bb35a7b0ce3e6.tar
tor-9e82f0cdb70839b5893147da446bb35a7b0ce3e6.tar.gz
enable code to remove members of old_routers when it gets big.
svn:r5345
Diffstat (limited to 'src/or')
-rw-r--r--src/or/main.c2
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/routerlist.c62
3 files changed, 30 insertions, 36 deletions
diff --git a/src/or/main.c b/src/or/main.c
index 525a81c57..1c2cade0b 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -719,7 +719,7 @@ run_scheduled_events(time_t now)
* (if we've passed our internal checks). */
if (time_to_fetch_directory < now) {
/* purge obsolete entries */
- routerlist_remove_old_routers(ROUTER_MAX_AGE);
+ routerlist_remove_old_routers();
networkstatus_list_clean(now);
if (authdir_mode(options)) {
diff --git a/src/or/or.h b/src/or/or.h
index 8386b53bb..84e5e8589 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2159,7 +2159,7 @@ void networkstatus_free(networkstatus_t *networkstatus);
void routerlist_free_all(void);
routerinfo_t *routerinfo_copy(const routerinfo_t *router);
void router_mark_as_down(const char *digest);
-void routerlist_remove_old_routers(int age);
+void routerlist_remove_old_routers(void);
void networkstatus_list_clean(time_t now);
int router_add_to_routerlist(routerinfo_t *router, const char **msg,
int from_cache);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 7cb7ce095..05407d1e7 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -199,7 +199,7 @@ router_rebuild_store(int force)
return 0;
/* Don't save deadweight. */
- routerlist_remove_old_routers(ROUTER_MAX_AGE);
+ routerlist_remove_old_routers();
options = get_options();
fname_len = strlen(options->DataDirectory)+32;
@@ -281,7 +281,7 @@ router_reload_router_list(void)
tor_free(fname);
/* Don't cache expired routers. */
- routerlist_remove_old_routers(ROUTER_MAX_AGE);
+ routerlist_remove_old_routers();
if (router_journal_len) {
/* Always clear the journal on startup.*/
@@ -1172,7 +1172,7 @@ routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int idx, int make_old)
// routerlist_assert_ok(rl);
}
-void
+static void
routerlist_remove_old(routerlist_t *rl, routerinfo_t *ri, int idx)
{
routerinfo_t *ri_tmp;
@@ -1495,30 +1495,6 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
#define MAX_DESCRIPTORS_PER_ROUTER 5
-/** Remove any routers from the routerlist that are more than <b>age</b>
- * seconds old.
- */
-void
-routerlist_remove_old_routers(int age)
-{
- int i;
- time_t cutoff;
- routerinfo_t *router;
- if (!routerlist)
- return;
-
- cutoff = time(NULL) - age;
- for (i = 0; i < smartlist_len(routerlist->routers); ++i) {
- router = smartlist_get(routerlist->routers, i);
- if (router->published_on <= cutoff) {
- /* Too old. Remove it. */
- info(LD_DIR, "Forgetting obsolete (too old) routerinfo for router '%s'",
- router->nickname);
- routerlist_remove(routerlist, router, i--, 1);
- }
- }
-}
-
static int
_compare_old_routers_by_identity(const void **_a, const void **_b)
{
@@ -1622,18 +1598,36 @@ routerlist_remove_old_cached_routers_with_id(time_t cutoff, int lo, int hi)
tor_free(lifespans);
}
+/** Deactivate any routers from the routerlist that are more than <b>age</b>
+ * seconds old; remove old routers from the list of cached routers if we have
+ * too many.
+ */
void
-routerlist_remove_old_cached_routers(void)
+routerlist_remove_old_routers(void)
{
int i, hi=-1;
const char *cur_id = NULL;
time_t cutoff;
+ routerinfo_t *router;
if (!routerlist)
return;
- /* First, check whether we have too many router descriptors, total. We're
- * okay with having too many for some given router, so long as the total
- * number doesn't much exceed
+ cutoff = time(NULL) - ROUTER_MAX_AGE;
+ /* Remove old members of routerlist->routers. */
+ for (i = 0; i < smartlist_len(routerlist->routers); ++i) {
+ router = smartlist_get(routerlist->routers, i);
+ if (router->published_on <= cutoff) {
+ /* Too old. Remove it. */
+ info(LD_DIR, "Forgetting obsolete (too old) routerinfo for router '%s'",
+ router->nickname);
+ routerlist_remove(routerlist, router, i--, 1);
+ }
+ }
+
+ /* Now we're looking at routerlist->old_routers. First, check whether
+ * we have too many router descriptors, total. We're okay with having too
+ * many for some given router, so long as the total number doesn't approach
+ * MAX_DESCRIPTORS_PER_ROUTER*len(router).
*/
if (smartlist_len(routerlist->old_routers) <
smartlist_len(routerlist->routers) * (MAX_DESCRIPTORS_PER_ROUTER - 1))
@@ -1641,8 +1635,6 @@ routerlist_remove_old_cached_routers(void)
smartlist_sort(routerlist->old_routers, _compare_old_routers_by_identity);
- cutoff = time(NULL) - ROUTER_MAX_AGE;
-
/* Iterate through the list from back to front, so when we remove descriptors
* we don't mess up groups we haven't gotten to. */
for (i = smartlist_len(routerlist->old_routers)-1; i >= 0; --i) {
@@ -1656,7 +1648,9 @@ routerlist_remove_old_cached_routers(void)
hi = i;
}
}
- routerlist_remove_old_cached_routers_with_id(cutoff, 0, hi);
+ if (hi>=0)
+ routerlist_remove_old_cached_routers_with_id(cutoff, 0, hi);
+ routerlist_assert_ok(routerlist);
}
/**