[or-cvs] Track how many bytes we have in signed descriptors. Try to ...

Nick Mathewson nickm at seul.org
Wed Nov 23 05:47:53 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv10575/src/or

Modified Files:
	or.h routerlist.c 
Log Message:
Track how many bytes we have in signed descriptors. Try to make sure we are tracking this right. Somebody should valgrind a dirserver on an example net.  There should be code to dump this value.

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.738
retrieving revision 1.739
diff -u -d -r1.738 -r1.739
--- or.h	19 Nov 2005 18:35:43 -0000	1.738
+++ or.h	23 Nov 2005 05:47:51 -0000	1.739
@@ -875,7 +875,7 @@
 typedef struct {
   /** Map from server identity digest to a member of routers. */
   digestmap_t *identity_map;
-  /** Map from server descriptor digest to a signed_descritptor_t from
+  /** Map from server descriptor digest to a signed_descriptor_t from
    * routers or old_routers. */
   digestmap_t *desc_digest_map;
   /** List of routerinfo_t for all currently live routers we know. */
@@ -883,6 +883,8 @@
   /** List of signed_descriptor_t for older router descriptors we're
    * caching. */
   smartlist_t *old_routers;
+  /** For debugging: tracks RAM usage in signed descriptors. */
+  uint32_t signed_descriptor_bytes;
 } routerlist_t;
 
 /** Information on router used when extending a circuit.  (We don't need a

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.375
retrieving revision 1.376
diff -u -d -r1.375 -r1.376
--- routerlist.c	22 Nov 2005 02:20:05 -0000	1.375
+++ routerlist.c	23 Nov 2005 05:47:51 -0000	1.376
@@ -1150,6 +1150,7 @@
   digestmap_set(rl->desc_digest_map, ri->cache_info.signed_descriptor_digest,
                 &(ri->cache_info));
   smartlist_add(rl->routers, ri);
+  rl->signed_descriptor_bytes += ri->cache_info.signed_descriptor_len;
   // routerlist_assert_ok(rl);
 }
 
@@ -1160,6 +1161,7 @@
     signed_descriptor_t *sd = signed_descriptor_from_routerinfo(ri);
     digestmap_set(rl->desc_digest_map, sd->signed_descriptor_digest, sd);
     smartlist_add(rl->old_routers, sd);
+    rl->signed_descriptor_bytes += sd->signed_descriptor_len;
   } else {
     routerinfo_free(ri);
   }
@@ -1188,6 +1190,7 @@
   } else {
     ri_tmp = digestmap_remove(rl->desc_digest_map,
                               ri->cache_info.signed_descriptor_digest);
+    rl->signed_descriptor_bytes -= ri->cache_info.signed_descriptor_len;
     tor_assert(ri_tmp == ri);
     routerinfo_free(ri);
   }
@@ -1204,6 +1207,7 @@
   smartlist_del(rl->old_routers, idx);
   sd_tmp = digestmap_remove(rl->desc_digest_map,
                             sd->signed_descriptor_digest);
+  rl->signed_descriptor_bytes -= sd->signed_descriptor_len;
   tor_assert(sd_tmp == sd);
   signed_descriptor_free(sd);
   routerlist_assert_ok(rl);
@@ -1225,6 +1229,7 @@
   } else {
     warn(LD_BUG, "Appending entry from routerlist_replace.");
     routerlist_insert(rl, ri_new);
+    rl->signed_descriptor_bytes += ri_new->cache_info.signed_descriptor_len;
     return;
   }
   if (memcmp(ri_old->cache_info.identity_digest, ri_new->cache_info.identity_digest, DIGEST_LEN)) {
@@ -1233,6 +1238,7 @@
   }
   digestmap_set(rl->identity_map, ri_new->cache_info.identity_digest, ri_new);
   digestmap_set(rl->desc_digest_map, ri_new->cache_info.signed_descriptor_digest, &(ri_new->cache_info));
+  rl->signed_descriptor_bytes += ri_new->cache_info.signed_descriptor_len;
 
   if (make_old && get_options()->DirPort) {
     signed_descriptor_t *sd = signed_descriptor_from_routerinfo(ri_old);
@@ -1245,6 +1251,7 @@
       /* digests don't match; digestmap_set didn't replace */
       digestmap_remove(rl->desc_digest_map, ri_old->cache_info.signed_descriptor_digest);
     }
+    rl->signed_descriptor_bytes -= ri_old->cache_info.signed_descriptor_len;
     routerinfo_free(ri_old);
   }
   // routerlist_assert_ok(rl);
@@ -3248,6 +3255,7 @@
   digestmap_iter_t *iter;
   routerinfo_t *r2;
   signed_descriptor_t *sd2;
+  uint32_t bytes = 0;
   if (!routerlist)
     return;
   SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,
@@ -3256,6 +3264,7 @@
     tor_assert(r == r2);
     sd2 = digestmap_get(rl->desc_digest_map, r->cache_info.signed_descriptor_digest);
     tor_assert(&(r->cache_info) == sd2);
+    bytes += r->cache_info.signed_descriptor_len;
   });
   SMARTLIST_FOREACH(rl->old_routers, signed_descriptor_t *, sd,
   {
@@ -3263,7 +3272,9 @@
     tor_assert(sd != &(r2->cache_info));
     sd2 = digestmap_get(rl->desc_digest_map, sd->signed_descriptor_digest);
     tor_assert(sd == sd2);
+    bytes += sd->signed_descriptor_len;
   });
+  tor_assert(bytes == rl->signed_descriptor_bytes);
   iter = digestmap_iter_init(rl->identity_map);
   while (!digestmap_iter_done(iter)) {
     const char *d;



More information about the tor-commits mailing list