Commit 0b661f65 authored by Nick Mathewson's avatar Nick Mathewson 🐻
Browse files

r12818@catbus: nickm | 2007-05-20 01:15:50 -0400

 Look for extrainfo bodies in the extrainfo mmap, not in the descriptor mmap.  Duh.  Should fix bug 429.


svn:r10226
parent 6d46ece6
......@@ -1075,12 +1075,14 @@ typedef struct signed_descriptor_t {
/** DOCDOC; routerinfo_t only: for the corresponding extrainfo. */
download_status_t ei_dl_status;
/** Where is the descriptor saved? */
saved_location_t saved_location;
saved_location_t saved_location ;
/** If saved_location is SAVED_IN_CACHE or SAVED_IN_JOURNAL, the offset of
* this descriptor in the corresponding file. */
off_t saved_offset;
/* DOCDOC */
unsigned int do_not_cache : 1;
/* DOCDOC */
unsigned int is_extrainfo : 1;
} signed_descriptor_t;
/** Information about another onion router in the network. */
......
......@@ -294,12 +294,13 @@ router_rebuild_store(int force, int extrainfo)
extrainfo ? &routerlist->mmap_extrainfo : &routerlist->mmap_descriptors;
routerlist_check_bug_417();
routerlist_assert_ok(routerlist);
/* Don't save deadweight. */
routerlist_remove_old_routers();
log_info(LD_DIR, "Rebuilding %s cache",
extrainfo ? "Extra-info" : "router descriptor");
extrainfo ? "extra-info" : "router descriptor");
options = get_options();
fname_len = strlen(options->DataDirectory)+32;
......@@ -371,6 +372,8 @@ router_rebuild_store(int force, int extrainfo)
if (! *mmap_ptr)
log_warn(LD_FS, "Unable to mmap new descriptor file at '%s'.",fname);
log_info(LD_DIR, "Reconstructing pointers into cache");
offset = 0;
SMARTLIST_FOREACH(signed_descriptors, signed_descriptor_t *, sd,
{
......@@ -1553,17 +1556,28 @@ extrainfo_get_by_descriptor_digest(const char *digest)
const char *
signed_descriptor_get_body(signed_descriptor_t *desc)
{
const char *r;
const char *r = NULL;
size_t len = desc->signed_descriptor_len;
tor_mmap_t *mmap;
tor_assert(len > 32);
if (desc->saved_location == SAVED_IN_CACHE && routerlist &&
routerlist->mmap_descriptors) {
tor_assert(desc->saved_offset + len <= routerlist->mmap_descriptors->size);
r = routerlist->mmap_descriptors->data + desc->saved_offset;
} else {
r = desc->signed_descriptor_body;
if (desc->saved_location == SAVED_IN_CACHE && routerlist) {
if (desc->is_extrainfo)
mmap = routerlist->mmap_extrainfo;
else
mmap = routerlist->mmap_descriptors;
if (mmap) {
tor_assert(desc->saved_offset + len <= mmap->size);
r = routerlist->mmap_descriptors->data + desc->saved_offset;
}
}
if (!r) /* no mmap, or not in cache. */
r = desc->signed_descriptor_body;
tor_assert(r);
if (memcmp("router ", r, 7) && memcmp("extra-info ", r, 11)) {
log_err(LD_DIR, "descriptor at %p begins with unexpected string %s",
desc, tor_strndup(r, 64));
}
tor_assert(!memcmp("router ", r, 7) || !memcmp("extra-info ", r, 11));
#if 0
tor_assert(!memcmp("\n-----END SIGNATURE-----\n",
......
......@@ -1195,6 +1195,7 @@ extrainfo_parse_entry_from_string(const char *s, const char *end,
}
extrainfo = tor_malloc_zero(sizeof(extrainfo_t));
extrainfo->cache_info.is_extrainfo = 1;
if (cache_copy)
extrainfo->cache_info.signed_descriptor_body = tor_strndup(s, end-s);
extrainfo->cache_info.signed_descriptor_len = end-s;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment