From 30a07b2ecd6093bd0f066a842a4fdae220be517d Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Thu, 20 May 2004 05:10:30 +0000 Subject: [PATCH] non-dirservers expire routerinfo's that are more than a day old svn:r1907 --- src/or/dirserv.c | 3 --- src/or/main.c | 2 +- src/or/or.h | 6 ++++++ src/or/routerlist.c | 29 ++++++++++++++++++++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 0e57983a38..3ca942de09 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -9,9 +9,6 @@ * \brief Directory server core implementation. **/ -/** How old do we allow a router to get before removing it? (seconds) */ -#define ROUTER_MAX_AGE (60*60*24) - /** How far in the future do we allow a router to get? (seconds) */ #define ROUTER_ALLOW_SKEW (30*60) diff --git a/src/or/main.c b/src/or/main.c index 996dea0c84..e2f7b37b81 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -439,6 +439,7 @@ static void run_scheduled_events(time_t now) { if(!options.DirPort) { /* NOTE directory servers do not currently fetch directories. * Hope this doesn't bite us later. */ + routerlist_remove_old_routers(); /* purge obsolete entries */ directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 0); } else { /* We're a directory; dump any old descriptors. */ @@ -451,7 +452,6 @@ static void run_scheduled_events(time_t now) { time_to_fetch_directory = now + options.DirFetchPostPeriod; } - /** 2. Every second, we examine pending circuits and prune the * ones which have been pending for more than a few seconds. * We do this before step 3, so it can try building more if diff --git a/src/or/or.h b/src/or/or.h index 149c197d5f..88bd8ee56a 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -128,6 +128,11 @@ /** How often do we rotate TLS contexts? */ #define MAX_SSL_KEY_LIFETIME (120*60) +/** How old do we allow a router to get before removing it, either + * from the descriptor list (for dirservers) or the router list (for others)? + * In seconds. */ +#define ROUTER_MAX_AGE (60*60*24) + #define CIRC_ID_TYPE_LOWER 0 #define CIRC_ID_TYPE_HIGHER 1 @@ -1298,6 +1303,7 @@ void routerlist_clear_trusted_directories(void); void routerinfo_free(routerinfo_t *router); routerinfo_t *routerinfo_copy(const routerinfo_t *router); void router_mark_as_down(char *nickname); +void routerlist_remove_old_routers(void); int router_load_routerlist_from_file(char *routerfile, int trusted); int router_load_routerlist_from_string(const char *s, int trusted); int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey); diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 17ba4a1fcc..a91a3b8cf6 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -348,6 +348,33 @@ int router_add_to_routerlist(routerinfo_t *router) { return 0; } +/** Remove any routers from the routerlist that are more than ROUTER_MAX_AGE + * seconds old. + * + * (This function is just like dirserv_remove_old_servers. One day we should + * merge them.) + */ +void +routerlist_remove_old_routers(void) +{ + int i; + time_t cutoff; + routerinfo_t *router; + if (!routerlist) + return; + + cutoff = time(NULL) - ROUTER_MAX_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. */ + log_fn(LOG_INFO,"Forgetting obsolete routerinfo for node %s.", router->nickname); + routerinfo_free(router); + smartlist_del(routerlist->routers, i--); + } + } +} + /* * Code to parse router descriptors and directories. */ @@ -440,7 +467,7 @@ int is_recommended_version(const char *myversion, } } -/** Replace the current routerlist with the routers stored in the +/** Add to the current routerlist each router stored in the * signed directory s. If pkey is provided, make sure that s is * signed with pkey. */ int router_load_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey)