mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
now we can tell dirserv_dump_directory_to_string() whether we want
it to include down/invalid descriptors or not. svn:r6618
This commit is contained in:
parent
88dadc917c
commit
b4e415ba3c
@ -760,11 +760,12 @@ live_enough_for_v1_dir(routerinfo_t *ri, time_t now)
|
|||||||
/** Generate a new v1 directory and write it into a newly allocated string.
|
/** Generate a new v1 directory and write it into a newly allocated string.
|
||||||
* Point *<b>dir_out</b> to the allocated string. Sign the
|
* Point *<b>dir_out</b> to the allocated string. Sign the
|
||||||
* directory with <b>private_key</b>. Return 0 on success, -1 on
|
* directory with <b>private_key</b>. Return 0 on success, -1 on
|
||||||
* failure.
|
* failure. If <b>complete</b> is set, give us all the descriptors;
|
||||||
|
* otherwise leave out non-running and non-valid ones.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
dirserv_dump_directory_to_string(char **dir_out,
|
dirserv_dump_directory_to_string(char **dir_out,
|
||||||
crypto_pk_env_t *private_key)
|
crypto_pk_env_t *private_key, int complete)
|
||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
char *router_status;
|
char *router_status;
|
||||||
@ -798,7 +799,7 @@ dirserv_dump_directory_to_string(char **dir_out,
|
|||||||
buf_len = 2048+strlen(recommended_versions)+
|
buf_len = 2048+strlen(recommended_versions)+
|
||||||
strlen(router_status);
|
strlen(router_status);
|
||||||
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri,
|
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri,
|
||||||
if (live_enough_for_v1_dir(ri, now))
|
if (complete || live_enough_for_v1_dir(ri, now))
|
||||||
buf_len += ri->cache_info.signed_descriptor_len+1);
|
buf_len += ri->cache_info.signed_descriptor_len+1);
|
||||||
buf = tor_malloc(buf_len);
|
buf = tor_malloc(buf_len);
|
||||||
/* We'll be comparing against buf_len throughout the rest of the
|
/* We'll be comparing against buf_len throughout the rest of the
|
||||||
@ -824,7 +825,7 @@ dirserv_dump_directory_to_string(char **dir_out,
|
|||||||
{
|
{
|
||||||
size_t len = ri->cache_info.signed_descriptor_len;
|
size_t len = ri->cache_info.signed_descriptor_len;
|
||||||
const char *body;
|
const char *body;
|
||||||
if (!live_enough_for_v1_dir(ri, now))
|
if (!complete && !live_enough_for_v1_dir(ri, now))
|
||||||
continue;
|
continue;
|
||||||
if (cp+len+1 >= buf+buf_len)
|
if (cp+len+1 >= buf+buf_len)
|
||||||
goto truncated;
|
goto truncated;
|
||||||
@ -1086,7 +1087,7 @@ dirserv_regenerate_directory(void)
|
|||||||
char *new_directory=NULL;
|
char *new_directory=NULL;
|
||||||
|
|
||||||
if (dirserv_dump_directory_to_string(&new_directory,
|
if (dirserv_dump_directory_to_string(&new_directory,
|
||||||
get_identity_key())) {
|
get_identity_key(), 0)) {
|
||||||
log_warn(LD_BUG, "Error creating directory.");
|
log_warn(LD_BUG, "Error creating directory.");
|
||||||
tor_free(new_directory);
|
tor_free(new_directory);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1910,7 +1910,8 @@ int dirserv_thinks_router_is_blatantly_unreachable(routerinfo_t *router,
|
|||||||
time_t now);
|
time_t now);
|
||||||
int list_server_status(smartlist_t *routers, char **router_status_out);
|
int list_server_status(smartlist_t *routers, char **router_status_out);
|
||||||
int dirserv_dump_directory_to_string(char **dir_out,
|
int dirserv_dump_directory_to_string(char **dir_out,
|
||||||
crypto_pk_env_t *private_key);
|
crypto_pk_env_t *private_key,
|
||||||
|
int complete);
|
||||||
void directory_set_dirty(void);
|
void directory_set_dirty(void);
|
||||||
size_t dirserv_get_directory(const char **cp, int compress);
|
size_t dirserv_get_directory(const char **cp, int compress);
|
||||||
size_t dirserv_get_runningrouters(const char **rr, int compress);
|
size_t dirserv_get_runningrouters(const char **rr, int compress);
|
||||||
|
@ -1320,7 +1320,7 @@ test_dir_format(void)
|
|||||||
test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0);
|
test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0);
|
||||||
test_eq(dirserv_add_descriptor(buf,&m), 2);
|
test_eq(dirserv_add_descriptor(buf,&m), 2);
|
||||||
get_options()->Nickname = tor_strdup("DirServer");
|
get_options()->Nickname = tor_strdup("DirServer");
|
||||||
test_assert(!dirserv_dump_directory_to_string(&cp,pk3));
|
test_assert(!dirserv_dump_directory_to_string(&cp,pk3, 0));
|
||||||
crypto_pk_get_digest(pk3, d);
|
crypto_pk_get_digest(pk3, d);
|
||||||
test_assert(!router_parse_directory(cp));
|
test_assert(!router_parse_directory(cp));
|
||||||
test_eq(2, smartlist_len(dir1->routers));
|
test_eq(2, smartlist_len(dir1->routers));
|
||||||
|
Loading…
Reference in New Issue
Block a user