mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-09-21 13:34:59 +02:00
r12581@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"). svn:r10068
This commit is contained in:
parent
18ba9fe81f
commit
b27b09ae1e
@ -361,7 +361,7 @@ rend_cache_lookup_desc(const char *query, int version, const char **desc,
|
||||
* 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_cache_store(const char *desc, size_t desc_len, int published)
|
||||
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 @@ rend_cache_store(const char *desc, size_t desc_len, int published)
|
||||
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 @@ rend_process_relay_cell(circuit_t *circ, int command, size_t length,
|
||||
(void)r;
|
||||
}
|
||||
|
||||
/** Return the number of entries in our rendezvous descriptor cache. */
|
||||
int
|
||||
rend_cache_size(void)
|
||||
{
|
||||
|
@ -1197,10 +1197,10 @@ hs_usage_init(void)
|
||||
/** 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 @@ hs_usage_list_clear(hs_usage_list_t *l)
|
||||
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 @@ static void
|
||||
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 @@ void
|
||||
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 @@ hs_usage_insert_value(hs_usage_list_t *l, const char *service_id)
|
||||
/* 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 @@ hs_usage_insert_value(hs_usage_list_t *l, const char *service_id)
|
||||
} 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 @@ hs_usage_insert_value(hs_usage_list_t *l, const char *service_id)
|
||||
/* 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;
|
||||
|
Loading…
Reference in New Issue
Block a user