* \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)
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. */
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
/** 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
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);
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.
*/
}
}
-/** Replace the current routerlist with the routers stored in the
+/** Add to the current routerlist each router stored in the
* signed directory <b>s</b>. If pkey is provided, make sure that <b>s</b> is
* signed with pkey. */
int router_load_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey)