mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
Fix a fun bug: do not rewrite a cached directory back to the cache; otherwise we will think it is recent and not fetch a newer one.
svn:r3319
This commit is contained in:
parent
f8b517fa97
commit
91bafc476e
@ -614,7 +614,7 @@ connection_dir_client_reached_eof(connection_t *conn)
|
||||
tor_free(body); tor_free(headers);
|
||||
return -1;
|
||||
}
|
||||
if (router_load_routerlist_from_directory(body, NULL, 1) < 0) {
|
||||
if (router_load_routerlist_from_directory(body, NULL, 1, 0) < 0) {
|
||||
log_fn(LOG_WARN,"I failed to parse the directory I fetched from %s:%d. Ignoring.", conn->address, conn->port);
|
||||
} else {
|
||||
log_fn(LOG_INFO,"updated routers.");
|
||||
@ -633,7 +633,7 @@ connection_dir_client_reached_eof(connection_t *conn)
|
||||
tor_free(body); tor_free(headers);
|
||||
return -1;
|
||||
}
|
||||
if (!(rrs = router_parse_runningrouters(body))) {
|
||||
if (!(rrs = router_parse_runningrouters(body, 1))) {
|
||||
log_fn(LOG_WARN, "Can't parse runningrouters list (server '%s')", conn->address);
|
||||
tor_free(body); tor_free(headers);
|
||||
return -1;
|
||||
|
@ -820,7 +820,8 @@ static int dirserv_regenerate_directory(void)
|
||||
* necessary, but safe is better than sorry. */
|
||||
new_directory = tor_strdup(the_directory);
|
||||
/* use a new copy of the dir, since get_dir_from_string scribbles on it */
|
||||
if (router_load_routerlist_from_directory(new_directory, get_identity_key(), 1)) {
|
||||
if (router_load_routerlist_from_directory(new_directory,
|
||||
get_identity_key(), 1, 0)) {
|
||||
log_fn(LOG_ERR, "We just generated a directory we can't parse. Dying.");
|
||||
tor_cleanup();
|
||||
exit(0);
|
||||
|
@ -1611,7 +1611,7 @@ routerinfo_t *routerinfo_copy(const routerinfo_t *router);
|
||||
void router_mark_as_down(const char *digest);
|
||||
void routerlist_remove_old_routers(int age);
|
||||
int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey,
|
||||
int check_version);
|
||||
int dir_is_recent, int dir_is_cached);
|
||||
int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
|
||||
addr_policy_t *policy);
|
||||
#define ADDR_POLICY_ACCEPTED 0
|
||||
@ -1696,8 +1696,10 @@ int router_parse_list_from_string(const char **s,
|
||||
int router_parse_routerlist_from_directory(const char *s,
|
||||
routerlist_t **dest,
|
||||
crypto_pk_env_t *pkey,
|
||||
int check_version);
|
||||
running_routers_t *router_parse_runningrouters(const char *str);
|
||||
int check_version,
|
||||
int write_to_cache);
|
||||
running_routers_t *router_parse_runningrouters(const char *str,
|
||||
int write_to_cache);
|
||||
routerinfo_t *router_parse_entry_from_string(const char *s, const char *end);
|
||||
int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
|
||||
addr_policy_t *router_parse_addr_policy_from_string(const char *s);
|
||||
|
@ -60,7 +60,7 @@ int router_reload_router_list(void)
|
||||
stat(filename, &st); /* if s is true, stat probably worked */
|
||||
log_fn(LOG_INFO, "Loading cached directory from %s", filename);
|
||||
is_recent = st.st_mtime > time(NULL) - 60*15;
|
||||
if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) {
|
||||
if (router_load_routerlist_from_directory(s, NULL, is_recent, 1) < 0) {
|
||||
log_fn(LOG_WARN, "Cached directory at '%s' was unparseable; ignoring.", filename);
|
||||
}
|
||||
if (routerlist &&
|
||||
@ -846,14 +846,19 @@ routerlist_remove_old_routers(int age)
|
||||
|
||||
/** Add to the current routerlist each router stored in the
|
||||
* signed directory <b>s</b>. If pkey is provided, check the signature against
|
||||
* pkey; else check against the pkey of the signing directory server. */
|
||||
* pkey; else check against the pkey of the signing directory server.
|
||||
*
|
||||
* DOCDOC dir_is_recent/cached
|
||||
*/
|
||||
int router_load_routerlist_from_directory(const char *s,
|
||||
crypto_pk_env_t *pkey,
|
||||
int dir_is_recent)
|
||||
int dir_is_recent,
|
||||
int dir_is_cached)
|
||||
{
|
||||
routerlist_t *new_list = NULL;
|
||||
if (router_parse_routerlist_from_directory(s, &new_list, pkey,
|
||||
dir_is_recent)) {
|
||||
dir_is_recent,
|
||||
!dir_is_cached)) {
|
||||
log_fn(LOG_WARN, "Couldn't parse directory.");
|
||||
return -1;
|
||||
}
|
||||
|
@ -291,12 +291,15 @@ int check_software_version_against_directory(const char *directory,
|
||||
/** Parse a directory from <b>str</b> and, when done, store the
|
||||
* resulting routerlist in *<b>dest</b>, freeing the old value if necessary.
|
||||
* If <b>pkey</b> is provided, we check the directory signature with pkey.
|
||||
*
|
||||
* DOCDOC check_version, write_to_cache.
|
||||
*/
|
||||
int /* Should be static; exposed for unit tests */
|
||||
router_parse_routerlist_from_directory(const char *str,
|
||||
routerlist_t **dest,
|
||||
crypto_pk_env_t *pkey,
|
||||
int check_version)
|
||||
int check_version,
|
||||
int write_to_cache)
|
||||
{
|
||||
directory_token_t *tok;
|
||||
char digest[DIGEST_LEN];
|
||||
@ -394,7 +397,7 @@ router_parse_routerlist_from_directory(const char *str,
|
||||
|
||||
/* Now that we know the signature is okay, and we have a
|
||||
* publication time, cache the directory. */
|
||||
if (!get_options()->AuthoritativeDir)
|
||||
if (!get_options()->AuthoritativeDir && write_to_cache)
|
||||
dirserv_set_cached_directory(str, published_on, 0);
|
||||
|
||||
if (!(tok = find_first_by_keyword(tokens, K_RECOMMENDED_SOFTWARE))) {
|
||||
@ -480,7 +483,7 @@ router_parse_routerlist_from_directory(const char *str,
|
||||
|
||||
/* DOCDOC */
|
||||
running_routers_t *
|
||||
router_parse_runningrouters(const char *str)
|
||||
router_parse_runningrouters(const char *str, int write_to_cache)
|
||||
{
|
||||
char digest[DIGEST_LEN];
|
||||
running_routers_t *new_list = NULL;
|
||||
@ -520,7 +523,7 @@ router_parse_runningrouters(const char *str)
|
||||
|
||||
/* Now that we know the signature is okay, and we have a
|
||||
* publication time, cache the list. */
|
||||
if (!get_options()->AuthoritativeDir)
|
||||
if (!get_options()->AuthoritativeDir && write_to_cache)
|
||||
dirserv_set_cached_directory(str, published_on, 1);
|
||||
|
||||
if (!(tok = find_first_by_keyword(tokens, K_ROUTER_STATUS))) {
|
||||
|
@ -1161,7 +1161,7 @@ test_dir_format(void)
|
||||
test_eq(dirserv_add_descriptor((const char**)&cp), 1);
|
||||
get_options()->Nickname = tor_strdup("DirServer");
|
||||
test_assert(!dirserv_dump_directory_to_string(&cp,pk3));
|
||||
test_assert(!router_parse_routerlist_from_directory(cp, &dir1, pk3, 1));
|
||||
test_assert(!router_parse_routerlist_from_directory(cp, &dir1, pk3, 1, 0));
|
||||
test_eq(2, smartlist_len(dir1->routers));
|
||||
dirserv_free_fingerprint_list();
|
||||
tor_free(cp);
|
||||
|
Loading…
Reference in New Issue
Block a user