|
@@ -48,19 +48,29 @@ extern int has_fetched_directory; /**< from main.c */
|
|
|
int router_reload_router_list(void)
|
|
|
{
|
|
|
char filename[512];
|
|
|
+ int is_recent;
|
|
|
+ struct stat st;
|
|
|
if (get_data_directory(&options)) {
|
|
|
char *s;
|
|
|
tor_snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options));
|
|
|
+ if (stat(filename, &st)) {
|
|
|
+ log_fn(LOG_WARN, "Unable to check status for '%s': %s", filename,
|
|
|
+ strerror(errno));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
s = read_file_to_str(filename,0);
|
|
|
if (s) {
|
|
|
tor_strstrip(s,"\r"); /* XXXX This is a bug workaround for win32. */
|
|
|
log_fn(LOG_INFO, "Loading cached directory from %s", filename);
|
|
|
- if (router_load_routerlist_from_directory(s, NULL, 0) < 0) {
|
|
|
+ is_recent = st.st_mtime > time(NULL) - 60*15;
|
|
|
+ if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) {
|
|
|
log_fn(LOG_WARN, "Cached directory '%s' was unparseable; ignoring.", filename);
|
|
|
}
|
|
|
- if(routerlist && routerlist->published_on > time(NULL) - OLD_MIN_ONION_KEY_LIFETIME/2) {
|
|
|
+ if(routerlist &&
|
|
|
+ ((routerlist->published_on > time(NULL) - OLD_MIN_ONION_KEY_LIFETIME/2)
|
|
|
+ || is_recent)) {
|
|
|
/* XXX use new onion key lifetime when 0.0.8 servers are obsolete */
|
|
|
- directory_has_arrived(); /* do things we've been waiting to do */
|
|
|
+ directory_has_arrived(st.st_mtime); /* do things we've been waiting to do */
|
|
|
}
|
|
|
tor_free(s);
|
|
|
}
|
|
@@ -633,6 +643,12 @@ void router_get_routerlist(routerlist_t **prouterlist) {
|
|
|
*prouterlist = routerlist;
|
|
|
}
|
|
|
|
|
|
+/** Return the publication time on the current routerlist, or 0 if we have no
|
|
|
+ * routerlist. */
|
|
|
+time_t routerlist_get_published_time(void) {
|
|
|
+ return routerlist ? routerlist->published_on : 0;
|
|
|
+}
|
|
|
+
|
|
|
/** Free all storage held by <b>router</b>. */
|
|
|
void routerinfo_free(routerinfo_t *router)
|
|
|
{
|
|
@@ -851,10 +867,6 @@ int router_load_routerlist_from_directory(const char *s,
|
|
|
if (options.AuthoritativeDir) {
|
|
|
/* Learn about the descriptors in the directory. */
|
|
|
dirserv_load_from_directory_string(s);
|
|
|
- } else {
|
|
|
- /* Remember the directory. */
|
|
|
- if(dir_is_recent)
|
|
|
- dirserv_set_cached_directory(s, routerlist->published_on);
|
|
|
}
|
|
|
return 0;
|
|
|
}
|