diff --git a/src/or/or.h b/src/or/or.h index 334f5d029f..071b83fdd5 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -755,6 +755,8 @@ typedef struct signed_descriptor_t { char signed_descriptor_digest[DIGEST_LEN]; char identity_digest[DIGEST_LEN]; time_t published_on; + enum { SAVED_NOWHERE=0, SAVED_IN_CACHE, SAVED_IN_JOURNAL } saved_location; + off_t saved_offset; } signed_descriptor_t; /** Information about another onion router in the network. */ @@ -2402,7 +2404,8 @@ int router_append_dirobj_signature(char *buf, size_t buf_len, const char *digest, crypto_pk_env_t *private_key); int router_parse_list_from_string(const char **s, - smartlist_t *dest); + smartlist_t *dest, + int from_cache); int router_parse_routerlist_from_directory(const char *s, routerlist_t **dest, crypto_pk_env_t *pkey, diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 6178605304..4345eb3531 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -186,6 +186,8 @@ router_append_to_journal(signed_descriptor_t *desc) tor_free(fname); return -1; } + desc->saved_location = SAVED_IN_JOURNAL; + desc->saved_offset = router_journal_len; tor_free(fname); router_journal_len += len; @@ -243,6 +245,20 @@ router_rebuild_store(int force) log_warn(LD_FS, "Error writing router store to disk."); goto done; } + for (i = 0; i < 2; ++i) { + smartlist_t *lst = (i == 0) ? routerlist->old_routers : + routerlist->routers; + off_t offset = 0; + SMARTLIST_FOREACH(lst, void *, ptr, + { + signed_descriptor_t *sd = (i==0) ? + ((signed_descriptor_t*)ptr): &((routerinfo_t*)ptr)->cache_info; + + sd->saved_location = SAVED_IN_CACHE; + sd->saved_offset = offset; + offset += sd->signed_descriptor_len; + }); + } tor_snprintf(fname, fname_len, "%s/cached-routers.new", options->DataDirectory); @@ -1920,7 +1936,7 @@ router_load_routers_from_string(const char *s, int from_cache, char fp[HEX_DIGEST_LEN+1]; const char *msg; - router_parse_list_from_string(&s, routers); + router_parse_list_from_string(&s, routers, from_cache); routers_update_status_from_networkstatus(routers, !from_cache); diff --git a/src/or/routerparse.c b/src/or/routerparse.c index bb30d1c0a4..ab1a2ca3bf 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -637,15 +637,17 @@ check_directory_signature(const char *digest, * are not complete. Returns 0 on success and -1 on failure. */ int -router_parse_list_from_string(const char **s, smartlist_t *dest) +router_parse_list_from_string(const char **s, smartlist_t *dest, + int from_cache) { routerinfo_t *router; - const char *end, *cp; + const char *end, *cp, *start; tor_assert(s); tor_assert(*s); tor_assert(dest); + start = *s; while (1) { *s = eat_whitespace(*s); /* Don't start parsing the rest of *s unless it contains a router. */ @@ -683,6 +685,10 @@ router_parse_list_from_string(const char **s, smartlist_t *dest) log_warn(LD_DIR, "Error reading router; skipping"); continue; } + if (from_cache) { + router->cache_info.saved_location = SAVED_IN_CACHE; + router->cache_info.saved_offset = *s - start; + } smartlist_add(dest, router); }