[or-cvs] r10068: Minor cleanups on hidden service usage patch from Karsten: t (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Mon Apr 30 17:46:19 UTC 2007


Author: nickm
Date: 2007-04-30 13:46:19 -0400 (Mon, 30 Apr 2007)
New Revision: 10068

Modified:
   tor/trunk/
   tor/trunk/src/or/rendcommon.c
   tor/trunk/src/or/rephist.c
Log:
 r12581 at catbus:  nickm | 2007-04-30 13:39:21 -0400
 Minor cleanups on hidden service usage patch from Karsten: tidy documentation; make free_all idempotent (and safe to call even if we have not yet initialized rephist); and stop using "l" as a variable name (it is too easy to confuse with "1").



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

Modified: tor/trunk/src/or/rendcommon.c
===================================================================
--- tor/trunk/src/or/rendcommon.c	2007-04-30 17:46:13 UTC (rev 10067)
+++ tor/trunk/src/or/rendcommon.c	2007-04-30 17:46:19 UTC (rev 10068)
@@ -361,7 +361,7 @@
  * Return -1 if it's malformed or otherwise rejected; return 0 if
  * it's the same or older than one we've already got; return 1 if
  * it's novel. The published flag tells us if we store the descriptor
- * in our role aus directory (1) or if we cache it as client (0).
+ * in our role as directory (1) or if we cache it as client (0).
  */
 int
 rend_cache_store(const char *desc, size_t desc_len, int published)
@@ -397,7 +397,7 @@
     rend_service_descriptor_free(parsed);
     return -1;
   }
-  /* report novel publication to statistic */
+  /* report novel publication to statistics */
   if (published && options->HSAuthorityRecordStats) {
     hs_usage_note_publish_total(query, time(NULL));
   }
@@ -418,7 +418,7 @@
   if (!e) {
     e = tor_malloc_zero(sizeof(rend_cache_entry_t));
     strmap_set_lc(rend_cache, key, e);
-    /* report novel publication to statistic */
+    /* report novel publication to statistics */
     if (published && options->HSAuthorityRecordStats) {
       hs_usage_note_publish_novel(query, time(NULL));
     }
@@ -486,6 +486,7 @@
   (void)r;
 }
 
+/** Return the number of entries in our rendezvous descriptor cache. */
 int
 rend_cache_size(void)
 {

Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c	2007-04-30 17:46:13 UTC (rev 10067)
+++ tor/trunk/src/or/rephist.c	2007-04-30 17:46:19 UTC (rev 10068)
@@ -1197,10 +1197,10 @@
 /** Clears the given ordered list by resetting its attributes and releasing
  * the memory allocated by its elements. */
 static void
-hs_usage_list_clear(hs_usage_list_t *l)
+hs_usage_list_clear(hs_usage_list_t *lst)
 {
   /* walk through elements and free memory */
-  hs_usage_list_elem_t *current = l->start;
+  hs_usage_list_elem_t *current = lst->start;
   hs_usage_list_elem_t *tmp;
   while (current != NULL) {
     tmp = current->next;
@@ -1209,19 +1209,21 @@
     current = tmp;
   }
   /* reset attributes */
-  l->start = NULL;
-  l->total_count = 0;
-  l->total_service_ids = 0;
+  lst->start = NULL;
+  lst->total_count = 0;
+  lst->total_service_ids = 0;
   return;
 }
 
 /** Frees the memory used by the given list. */
 static void
-hs_usage_list_free(hs_usage_list_t *l)
+hs_usage_list_free(hs_usage_list_t *lst)
 {
-  hs_usage_list_clear(l);
+  if (!lst)
+    return;
+  hs_usage_list_clear(lst);
   rephist_total_alloc -= sizeof(hs_usage_list_t);
-  tor_free(l);
+  tor_free(lst);
 }
 
 /** Frees the memory used by the given service-related observations. */
@@ -1229,6 +1231,8 @@
 hs_usage_service_related_observation_free(
                                     hs_usage_service_related_observation_t *s)
 {
+  if (!s)
+    return;
   hs_usage_list_free(s->list);
   rephist_total_alloc -= sizeof(hs_usage_service_related_observation_t);
   tor_free(s);
@@ -1257,20 +1261,23 @@
 hs_usage_free_all(void)
 {
   hs_usage_general_period_related_observations_free(descs);
+  descs = NULL;
   hs_usage_service_related_observation_free(fetch_successful);
   hs_usage_service_related_observation_free(fetch_total);
   hs_usage_service_related_observation_free(publish_novel);
   hs_usage_service_related_observation_free(publish_total);
+  fetch_successful = fetch_total = publish_novel = publish_total = NULL;
   hs_usage_current_observation_period_free(current_period);
+  current_period = NULL;
 }
 
 /** Inserts a new occurence for the given service id to the given ordered
  * list. */
 static void
-hs_usage_insert_value(hs_usage_list_t *l, const char *service_id)
+hs_usage_insert_value(hs_usage_list_t *lst, const char *service_id)
 {
   /* search if there is already an elem with same service_id in list */
-  hs_usage_list_elem_t *current = l->start;
+  hs_usage_list_elem_t *current = lst->start;
   hs_usage_list_elem_t *previous = NULL;
   while (current != NULL && strcmp(current->service_id,service_id)) {
     previous = current;
@@ -1283,14 +1290,14 @@
     /* create elem */
     hs_usage_list_elem_t *e = hs_usage_list_elem_new();
     /* update list attributes (one new elem, one new occurence) */
-    l->total_count++;
-    l->total_service_ids++;
+    lst->total_count++;
+    lst->total_service_ids++;
     /* copy service id to elem */
     strlcpy(e->service_id,service_id,sizeof(e->service_id));
     /* let either l->start or previously last elem point to new elem */
-    if (l->start == NULL) {
+    if (lst->start == NULL) {
       /* this is the first elem */
-      l->start = e;
+      lst->start = e;
     } else {
       /* there were elems in the list before */
       previous->next = e;
@@ -1298,7 +1305,7 @@
   } else {
     /* found! add occurence to elem and consider resorting */
     /* update list attributes (no new elem, but one new occurence) */
-    l->total_count++;
+    lst->total_count++;
     /* add occurence to elem */
     current->count++;
     /* is it another than the first list elem? and has previous elem fewer
@@ -1308,14 +1315,14 @@
       /* remove current elem first */
       previous->next = current->next;
       /* can we prepend elem to all other elements? */
-      if (l->start->count <= current->count) {
+      if (lst->start->count <= current->count) {
         /* yes! prepend elem */
-        current->next = l->start;
-        l->start = current;
+        current->next = lst->start;
+        lst->start = current;
       } else {
         /* no! walk through list a second time and insert at correct place */
-        hs_usage_list_elem_t *insert_current = l->start->next;
-        hs_usage_list_elem_t *insert_previous = l->start;
+        hs_usage_list_elem_t *insert_current = lst->start->next;
+        hs_usage_list_elem_t *insert_previous = lst->start;
         while (insert_current != NULL &&
                insert_current->count > current->count) {
           insert_previous = insert_current;



More information about the tor-commits mailing list