[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Be more aggressive about throwing away expired router descr...
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv31006/src/or
Modified Files:
dirserv.c or.h routerlist.c
Log Message:
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.
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.288
retrieving revision 1.289
diff -u -p -d -r1.288 -r1.289
--- dirserv.c 8 Jan 2006 21:33:15 -0000 1.288
+++ dirserv.c 10 Jan 2006 04:57:12 -0000 1.289
@@ -1603,6 +1603,7 @@ dirserv_get_routerdescs(smartlist_t *des
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 *des
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));
}
});
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.776
retrieving revision 1.777
diff -u -p -d -r1.776 -r1.777
--- or.h 9 Jan 2006 23:13:53 -0000 1.776
+++ or.h 10 Jan 2006 04:57:12 -0000 1.777
@@ -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 {
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.420
retrieving revision 1.421
diff -u -p -d -r1.420 -r1.421
--- routerlist.c 9 Jan 2006 23:39:07 -0000 1.420
+++ routerlist.c 10 Jan 2006 04:57:12 -0000 1.421
@@ -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))