summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-01-10 04:57:12 +0000
committerNick Mathewson <nickm@torproject.org>2006-01-10 04:57:12 +0000
commit43a4f8c7f301a9e83214b9cbff856b378edfe66b (patch)
tree86cf93e814f723ffc70050b6399530c8a5e1c5d0
parent56c55c343e6d4f89ed1274263ef8c6dfbb45d53b (diff)
downloadtor-43a4f8c7f301a9e83214b9cbff856b378edfe66b.tar.gz
tor-43a4f8c7f301a9e83214b9cbff856b378edfe66b.zip
Be more aggressive about throwing away expired router descriptors: they are of no use to anybody. Better still: dont serve expired descriptors by fingerprint. The only people who ask for them are busted 0.1.1.10 Tors that will throw them away and re-request them after 30 minutes.
svn:r5762
-rw-r--r--src/or/dirserv.c7
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/routerlist.c36
3 files changed, 33 insertions, 12 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index e7a52dda6b..95cb6ae019 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1603,6 +1603,7 @@ dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
smartlist_free(digests);
} else if (!strcmpstart(key, "/tor/server/fp/")) {
smartlist_t *digests = smartlist_create();
+ time_t cutoff = time(NULL) - ROUTER_MAX_AGE;
key += strlen("/tor/server/fp/");
dir_split_resource_into_fingerprints(key, digests, NULL, 1);
SMARTLIST_FOREACH(digests, const char *, d,
@@ -1611,7 +1612,11 @@ dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
smartlist_add(descs_out, &(router_get_my_routerinfo()->cache_info));
} else {
routerinfo_t *ri = router_get_by_digest(d);
- if (ri)
+ /* Don't actually serve a descriptor that everyone will think is
+ * expired. This is an (ugly) workaround to keep buggy 0.1.1.10
+ * Tors from downloading descriptors that they will throw away.
+ */
+ if (ri && ri->cache_info.published_on > cutoff)
smartlist_add(descs_out, &(ri->cache_info));
}
});
diff --git a/src/or/or.h b/src/or/or.h
index bd4b797079..80e5cf91f4 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -191,7 +191,7 @@
/** How old do we allow a router to get before removing it
* from the router list? In seconds. */
#define ROUTER_MAX_AGE (60*60*24)
-/** How old do we let a saved descriptor get before removing it it? */
+/** How old do we let a saved descriptor get before removing it? */
#define OLD_ROUTER_DESC_MAX_AGE (60*60*48)
typedef enum {
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 3dbd0f5f6c..d85ffa1f8a 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -286,13 +286,15 @@ router_reload_router_list(void)
}
tor_free(fname);
- /* Don't cache expired routers. */
- routerlist_remove_old_routers();
-
if (router_journal_len) {
/* Always clear the journal on startup.*/
router_rebuild_store(1);
+ } else {
+ /* Don't cache expired routers. (This is in an else because
+ * router_rebuild_store() also calls remove_old_routers().) */
+ routerlist_remove_old_routers();
}
+
return 0;
}
@@ -1750,8 +1752,9 @@ routerlist_remove_old_routers(void)
{
int i, hi=-1;
const char *cur_id = NULL;
- time_t cutoff;
+ time_t now, cutoff;
routerinfo_t *router;
+ signed_descriptor_t *sd;
digestmap_t *retain;
or_options_t *options = get_options();
if (!routerlist || !networkstatus_list)
@@ -1766,8 +1769,9 @@ routerlist_remove_old_routers(void)
});
}
- cutoff = time(NULL) - ROUTER_MAX_AGE;
- /* Remove old members of routerlist->routers. */
+ now = time(NULL);
+ cutoff = now - ROUTER_MAX_AGE;
+ /* Remove too-old members of routerlist->routers. */
for (i = 0; i < smartlist_len(routerlist->routers); ++i) {
router = smartlist_get(routerlist->routers, i);
if (router->cache_info.published_on <= cutoff &&
@@ -1779,10 +1783,22 @@ routerlist_remove_old_routers(void)
}
}
- /* Now we're looking at routerlist->old_routers. First, check whether
- * we have too many router descriptors, total. We're okay with having too
- * many for some given router, so long as the total number doesn't approach
- * MAX_DESCRIPTORS_PER_ROUTER*len(router).
+ /* Remove far-too-old members of routerlist->old_routers. */
+ cutoff = now - OLD_ROUTER_DESC_MAX_AGE;
+ for (i = 0; i < smartlist_len(routerlist->old_routers); ++i) {
+ sd = smartlist_get(routerlist->old_routers, i);
+ if (sd->published_on <= cutoff &&
+ !digestmap_get(retain, sd->signed_descriptor_digest)) {
+ /* Too old. Remove it. */
+ routerlist_remove_old(routerlist, sd, i--);
+ }
+ }
+
+ /* Now we're looking at routerlist->old_routers for extraneous
+ * members. (We'd keep all the members if we could, but we'd like to save
+ * space.) First, check whether we have too many router descriptors, total.
+ * We're okay with having too many for some given router, so long as the
+ * total number doesn't approach MAX_DESCRIPTORS_PER_ROUTER*len(router).
*/
if (smartlist_len(routerlist->old_routers) <
smartlist_len(routerlist->routers) * (MAX_DESCRIPTORS_PER_ROUTER - 1))