diff options
author | Roger Dingledine <arma@torproject.org> | 2006-03-29 08:56:39 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2006-03-29 08:56:39 +0000 |
commit | db1209a852ac7ecebe26eab40c2da8fa19e3468f (patch) | |
tree | 39e4733571b7925117193736e2509723599ee748 /src/or/dirserv.c | |
parent | 1fa7b3cef72d88077709c2c2fd7521c189c05572 (diff) | |
download | tor-db1209a852ac7ecebe26eab40c2da8fa19e3468f.tar.gz tor-db1209a852ac7ecebe26eab40c2da8fa19e3468f.zip |
Refactor the decision of whether to include a router's descriptor
in the v1 directory. No actual changes yet.
svn:r6272
Diffstat (limited to 'src/or/dirserv.c')
-rw-r--r-- | src/or/dirserv.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 258ec21ecb..f73adf9e11 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -743,7 +743,19 @@ format_versions_list(config_line_t *ln) return result; } -/** Generate a new directory and write it into a newly allocated string. +/** Return 1 if <b>ri</b>'s descriptor is worth including in the v1 + * directory, else return 0. + */ +static int +live_enough_for_v1_dir(routerinfo_t *ri, time_t now) +{ + time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH; + if (ri->cache_info.published_on < cutoff) + return 0; + return 1; +} + +/** Generate a new v1 directory and write it into a newly allocated string. * Point *<b>dir_out</b> to the allocated string. Sign the * directory with <b>private_key</b>. Return 0 on success, -1 on * failure. @@ -763,7 +775,6 @@ dirserv_dump_directory_to_string(char **dir_out, size_t identity_pkey_len; routerlist_t *rl = router_get_routerlist(); time_t now = time(NULL); - time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH; tor_assert(dir_out); *dir_out = NULL; @@ -785,7 +796,7 @@ dirserv_dump_directory_to_string(char **dir_out, buf_len = 2048+strlen(recommended_versions)+ strlen(router_status); SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, - if (ri->cache_info.published_on >= cutoff) + if (live_enough_for_v1_dir(ri, now)) buf_len += ri->cache_info.signed_descriptor_len+1); buf = tor_malloc(buf_len); /* We'll be comparing against buf_len throughout the rest of the @@ -811,7 +822,7 @@ dirserv_dump_directory_to_string(char **dir_out, { size_t len = ri->cache_info.signed_descriptor_len; const char *body; - if (ri->cache_info.published_on < cutoff) + if (!live_enough_for_v1_dir(ri, now)) continue; if (cp+len+1 >= buf+buf_len) goto truncated; @@ -1065,7 +1076,7 @@ dirserv_get_directory(const char **directory, int compress) } /** - * Generate a fresh directory (authdirservers only.) + * Generate a fresh v1 directory (authdirservers only.) */ static int dirserv_regenerate_directory(void) |