Commit e95ae1c9 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

let purging routerinfos and descriptors take an age argument


svn:r2171
parent bd24c68a
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -510,11 +510,11 @@ list_running_servers(char **nicknames_out)
  return 0;
}

/** Remove any descriptors from the directory that are more than ROUTER_MAX_AGE
/** Remove any descriptors from the directory that are more than <b>age</b>
 * seconds old.
 */
void
dirserv_remove_old_servers(void)
dirserv_remove_old_servers(int age)
{
  int i;
  time_t cutoff;
@@ -522,10 +522,10 @@ dirserv_remove_old_servers(void)
  if (!descriptor_list)
    descriptor_list = smartlist_create();

  cutoff = time(NULL) - ROUTER_MAX_AGE;
  cutoff = time(NULL) - age;
  for (i = 0; i < smartlist_len(descriptor_list); ++i) {
    ent = smartlist_get(descriptor_list, i);
    if (ent->published < cutoff) {
    if (ent->published <= cutoff) {
      /* descriptor_list[i] is too old.  Remove it. */
      free_descriptor_entry(ent);
      smartlist_del(descriptor_list, i--);
@@ -556,7 +556,7 @@ dirserv_dump_directory_to_string(char *s, unsigned int maxlen,

  if (list_running_servers(&cp))
    return -1;
  dirserv_remove_old_servers();
  dirserv_remove_old_servers(ROUTER_MAX_AGE);
  published_on = time(NULL);
  strftime(published, 32, "%Y-%m-%d %H:%M:%S", gmtime(&published_on));
  snprintf(s, maxlen,
+3 −2
Original line number Diff line number Diff line
@@ -544,11 +544,12 @@ static void run_scheduled_events(time_t now) {
      server_is_advertised = 0;
    }

    routerlist_remove_old_routers(); /* purge obsolete entries */
    /* purge obsolete entries */
    routerlist_remove_old_routers(ROUTER_MAX_AGE);

    if(authdir_mode()) {
      /* We're a directory; dump any old descriptors. */
      dirserv_remove_old_servers();
      dirserv_remove_old_servers(ROUTER_MAX_AGE);
    }
    if(server_mode()) {
      /* dirservers try to reconnect, in case connections have failed;
+2 −2
Original line number Diff line number Diff line
@@ -1160,7 +1160,7 @@ void dirserv_free_fingerprint_list();
int dirserv_add_descriptor(const char **desc);
int dirserv_load_from_directory_string(const char *dir);
void dirserv_free_descriptors();
void dirserv_remove_old_servers(void);
void dirserv_remove_old_servers(int age);
int dirserv_dump_directory_to_string(char *s, unsigned int maxlen,
                                     crypto_pk_env_t *private_key);
void directory_set_dirty(void);
@@ -1385,7 +1385,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(const char *digest);
void routerlist_remove_old_routers(void);
void routerlist_remove_old_routers(int age);
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);
+5 −4
Original line number Diff line number Diff line
@@ -488,14 +488,14 @@ int router_add_to_routerlist(routerinfo_t *router) {
  return 0;
}

/** Remove any routers from the routerlist that are more than ROUTER_MAX_AGE
/** Remove any routers from the routerlist that are more than <b>age</b>
 * seconds old.
 *
 * (This function is just like dirserv_remove_old_servers. One day we should
 * merge them.)
 */
void
routerlist_remove_old_routers(void)
routerlist_remove_old_routers(int age)
{
  int i;
  time_t cutoff;
@@ -503,10 +503,11 @@ routerlist_remove_old_routers(void)
  if (!routerlist)
    return;

  cutoff = time(NULL) - ROUTER_MAX_AGE;
  cutoff = time(NULL) - age;
  for (i = 0; i < smartlist_len(routerlist->routers); ++i) {
    router = smartlist_get(routerlist->routers, i);
    if (router->published_on < cutoff &&
    if (router->published_on <= cutoff &&
/* XXX008 don't get fooled by cached dir ports */
      !router->dir_port) {
      /* Too old.  Remove it. But never remove dirservers! */
      log_fn(LOG_INFO,"Forgetting obsolete routerinfo for node %s.", router->nickname);