[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10226: Look for extrainfo bodies in the extrainfo mmap, not in the (in tor/trunk: . src/or)



Author: nickm
Date: 2007-05-20 01:15:53 -0400 (Sun, 20 May 2007)
New Revision: 10226

Modified:
   tor/trunk/
   tor/trunk/src/or/or.h
   tor/trunk/src/or/routerlist.c
   tor/trunk/src/or/routerparse.c
Log:
 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.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12818] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-05-19 22:21:46 UTC (rev 10225)
+++ tor/trunk/src/or/or.h	2007-05-20 05:15:53 UTC (rev 10226)
@@ -1075,12 +1075,14 @@
   /** 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. */

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-05-19 22:21:46 UTC (rev 10225)
+++ tor/trunk/src/or/routerlist.c	2007-05-20 05:15:53 UTC (rev 10226)
@@ -294,12 +294,13 @@
     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 @@
   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 @@
 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 {
+  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(r);
   tor_assert(!memcmp("router ", r, 7) || !memcmp("extra-info ", r, 11));
 #if 0
   tor_assert(!memcmp("\n-----END SIGNATURE-----\n",

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2007-05-19 22:21:46 UTC (rev 10225)
+++ tor/trunk/src/or/routerparse.c	2007-05-20 05:15:53 UTC (rev 10226)
@@ -1195,6 +1195,7 @@
   }
 
   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;