]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
non-dirservers expire routerinfo's that are more than a day old
authorRoger Dingledine <arma@torproject.org>
Thu, 20 May 2004 05:10:30 +0000 (05:10 +0000)
committerRoger Dingledine <arma@torproject.org>
Thu, 20 May 2004 05:10:30 +0000 (05:10 +0000)
svn:r1907

src/or/dirserv.c
src/or/main.c
src/or/or.h
src/or/routerlist.c

index 0e57983a38ab57b279724810c1d964e889fa2024..3ca942de099a350c4b1ebc83dc3f39d1e11845d1 100644 (file)
@@ -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)
 
index 996dea0c84f182c3b0551fb51f83d8f0af5d5781..e2f7b37b81ffbad7326105873c986b09473ee498 100644 (file)
@@ -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
index 149c197d5f325e07901b60c7bffb125785362287..88bd8ee56aaf7cc1ec6c31656a52ba8e1ebe1549 100644 (file)
 /** 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);
index 17ba4a1fcc8200a79622a4361c2672b92bfefb4f..a91a3b8cf640118927f4e633403e48b373eb7f20 100644 (file)
@@ -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 <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)