mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
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
This commit is contained in:
parent
56c55c343e
commit
43a4f8c7f3
@ -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));
|
||||
}
|
||||
});
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user