[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Remove now useless rev counter state file code.
commit 1d2333405eed9ec616eaa3980db5c4b272bb5aa8
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Thu Jun 14 15:51:00 2018 +0300
Remove now useless rev counter state file code.
We are not using the state file for rev counters anymore, we just generate them
on the fly!
---
src/or/hs_service.c | 185 ---------------------------------------------
src/or/hs_service.h | 9 ---
src/test/test_hs_service.c | 62 ---------------
3 files changed, 256 deletions(-)
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 70d9c1c6f..dd91e97bb 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -1763,7 +1763,6 @@ service_desc_schedule_upload(hs_service_descriptor_t *desc,
/* Update the given descriptor from the given service. The possible update
* actions includes:
* - Picking missing intro points if needed.
- * - Incrementing the revision counter if needed.
*/
static void
update_service_descriptor(hs_service_t *service,
@@ -2338,187 +2337,6 @@ upload_descriptor_to_hsdir(const hs_service_t *service,
return;
}
-/** Return a newly-allocated string for our state file which contains revision
- * counter information for <b>desc</b>. The format is:
- *
- * HidServRevCounter <blinded_pubkey> <rev_counter>
- */
-STATIC char *
-encode_desc_rev_counter_for_state(const hs_service_descriptor_t *desc)
-{
- char *state_str = NULL;
- char blinded_pubkey_b64[ED25519_BASE64_LEN+1];
- uint64_t rev_counter = desc->desc->plaintext_data.revision_counter;
- const ed25519_public_key_t *blinded_pubkey = &desc->blinded_kp.pubkey;
-
- /* Turn the blinded key into b64 so that we save it on state */
- tor_assert(blinded_pubkey);
- if (ed25519_public_to_base64(blinded_pubkey_b64, blinded_pubkey) < 0) {
- goto done;
- }
-
- /* Format is: <blinded key> <rev counter> */
- tor_asprintf(&state_str, "%s %" PRIu64, blinded_pubkey_b64, rev_counter);
-
- log_info(LD_GENERAL, "[!] Adding rev counter %" PRIu64 " for %s!",
- rev_counter, blinded_pubkey_b64);
-
- done:
- return state_str;
-}
-
-/** Update HS descriptor revision counters in our state by removing the old
- * ones and writing down the ones that are currently active. */
-static void
-update_revision_counters_in_state(void)
-{
- config_line_t *lines = NULL;
- config_line_t **nextline = &lines;
- or_state_t *state = get_or_state();
-
- /* Prepare our state structure with the rev counters */
- FOR_EACH_SERVICE_BEGIN(service) {
- FOR_EACH_DESCRIPTOR_BEGIN(service, desc) {
- /* We don't want to save zero counters */
- if (desc->desc->plaintext_data.revision_counter == 0) {
- continue;
- }
-
- *nextline = tor_malloc_zero(sizeof(config_line_t));
- (*nextline)->key = tor_strdup("HidServRevCounter");
- (*nextline)->value = encode_desc_rev_counter_for_state(desc);
- nextline = &(*nextline)->next;
- } FOR_EACH_DESCRIPTOR_END;
- } FOR_EACH_SERVICE_END;
-
- /* Remove the old rev counters, and replace them with the new ones */
- config_free_lines(state->HidServRevCounter);
- state->HidServRevCounter = lines;
-
- /* Set the state as dirty since we just edited it */
- if (!get_options()->AvoidDiskWrites) {
- or_state_mark_dirty(state, 0);
- }
-}
-
-/** Scan the string <b>state_line</b> for the revision counter of the service
- * with <b>blinded_pubkey</b>. Set <b>service_found_out</b> to True if the
- * line is relevant to this service, and return the cached revision
- * counter. Else set <b>service_found_out</b> to False. */
-STATIC uint64_t
-check_state_line_for_service_rev_counter(const char *state_line,
- const ed25519_public_key_t *blinded_pubkey,
- int *service_found_out)
-{
- smartlist_t *items = NULL;
- int ok;
- ed25519_public_key_t pubkey_in_state;
- uint64_t rev_counter = 0;
-
- tor_assert(service_found_out);
- tor_assert(state_line);
- tor_assert(blinded_pubkey);
-
- /* Assume that the line is not for this service */
- *service_found_out = 0;
-
- /* Start parsing the state line */
- items = smartlist_new();
- smartlist_split_string(items, state_line, NULL,
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
- if (smartlist_len(items) < 2) {
- log_warn(LD_GENERAL, "Incomplete rev counter line. Ignoring.");
- goto done;
- }
-
- char *b64_key_str = smartlist_get(items, 0);
- char *saved_rev_counter_str = smartlist_get(items, 1);
-
- /* Parse blinded key to check if it's for this hidden service */
- if (ed25519_public_from_base64(&pubkey_in_state, b64_key_str) < 0) {
- log_warn(LD_GENERAL, "Unable to base64 key in revcount line. Ignoring.");
- goto done;
- }
- /* State line not for this hidden service */
- if (!ed25519_pubkey_eq(&pubkey_in_state, blinded_pubkey)) {
- goto done;
- }
-
- rev_counter = tor_parse_uint64(saved_rev_counter_str,
- 10, 0, UINT64_MAX, &ok, NULL);
- if (!ok) {
- log_warn(LD_GENERAL, "Unable to parse rev counter. Ignoring.");
- goto done;
- }
-
- /* Since we got this far, the line was for this service */
- *service_found_out = 1;
-
- log_info(LD_GENERAL, "Found rev counter for %s: %" PRIu64,
- b64_key_str, rev_counter);
-
- done:
- tor_assert(items);
- SMARTLIST_FOREACH(items, char*, s, tor_free(s));
- smartlist_free(items);
-
- return rev_counter;
-}
-
-/** Dig into our state file and find the current revision counter for the
- * service with blinded key <b>blinded_pubkey</b>. If no revision counter is
- * found, return 0. */
-static uint64_t
-get_rev_counter_for_service(const ed25519_public_key_t *blinded_pubkey)
-{
- or_state_t *state = get_or_state();
- config_line_t *line;
-
- /* Set default value for rev counters (if not found) to 0 */
- uint64_t final_rev_counter = 0;
-
- for (line = state->HidServRevCounter ; line ; line = line->next) {
- int service_found = 0;
- uint64_t rev_counter = 0;
-
- tor_assert(!strcmp(line->key, "HidServRevCounter"));
-
- /* Scan all the HidServRevCounter lines till we find the line for this
- service: */
- rev_counter = check_state_line_for_service_rev_counter(line->value,
- blinded_pubkey,
- &service_found);
- if (service_found) {
- final_rev_counter = rev_counter;
- goto done;
- }
- }
-
- done:
- return final_rev_counter;
-}
-
-/** Update the value of the revision counter for <b>hs_desc</b> and save it on
- our state file. */
-static void
-increment_descriptor_revision_counter(hs_descriptor_t *hs_desc)
-{
- /* Find stored rev counter if it exists */
- uint64_t rev_counter =
- get_rev_counter_for_service(&hs_desc->plaintext_data.blinded_pubkey);
-
- /* Increment the revision counter of <b>hs_desc</b> so the next update (which
- * will trigger an upload) will have the right value. We do this at this
- * stage to only do it once because a descriptor can have many updates before
- * being uploaded. By doing it at upload, we are sure to only increment by 1
- * and thus avoid leaking how many operations we made on the descriptor from
- * the previous one before uploading. */
- rev_counter++;
- hs_desc->plaintext_data.revision_counter = rev_counter;
-
- update_revision_counters_in_state();
-}
-
/** Set the revision counter in <b>hs_desc</b>. We do this by encrypting a
* timestamp using an OPE scheme and using the ciphertext as our revision
* counter.
@@ -2664,9 +2482,6 @@ upload_descriptor_to_all(const hs_service_t *service,
safe_str_client(service->onion_address), fmt_next_time);
}
- /* Update the revision counter of this descriptor */
- increment_descriptor_revision_counter(desc->desc);
-
smartlist_free(responsible_dirs);
return;
}
diff --git a/src/or/hs_service.h b/src/or/hs_service.h
index 4676042b5..a5f49ffef 100644
--- a/src/or/hs_service.h
+++ b/src/or/hs_service.h
@@ -346,19 +346,10 @@ STATIC void build_all_descriptors(time_t now);
STATIC void update_all_descriptors(time_t now);
STATIC void run_upload_descriptor_event(time_t now);
-STATIC char *
-encode_desc_rev_counter_for_state(const hs_service_descriptor_t *desc);
-
STATIC void service_descriptor_free_(hs_service_descriptor_t *desc);
#define service_descriptor_free(d) \
FREE_AND_NULL(hs_service_descriptor_t, \
service_descriptor_free_, (d))
-
-STATIC uint64_t
-check_state_line_for_service_rev_counter(const char *state_line,
- const ed25519_public_key_t *blinded_pubkey,
- int *service_found_out);
-
STATIC int
write_address_to_file(const hs_service_t *service, const char *fname_);
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index e328ca5bd..0350face4 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -1430,66 +1430,6 @@ test_upload_descriptors(void *arg)
UNMOCK(get_or_state);
}
-/** Test the functions that save and load HS revision counters to state. */
-static void
-test_revision_counter_state(void *arg)
-{
- char *state_line_one = NULL;
- char *state_line_two = NULL;
-
- hs_service_descriptor_t *desc_one = service_descriptor_new();
- hs_service_descriptor_t *desc_two = service_descriptor_new();
-
- (void) arg;
-
- /* Prepare both descriptors */
- desc_one->desc->plaintext_data.revision_counter = 42;
- desc_two->desc->plaintext_data.revision_counter = 240;
- memset(&desc_one->blinded_kp.pubkey.pubkey, 66,
- sizeof(desc_one->blinded_kp.pubkey.pubkey));
- memset(&desc_two->blinded_kp.pubkey.pubkey, 240,
- sizeof(desc_one->blinded_kp.pubkey.pubkey));
-
- /* Turn the descriptor rev counters into state lines */
- state_line_one = encode_desc_rev_counter_for_state(desc_one);
- tt_str_op(state_line_one, OP_EQ,
- "QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkI 42");
-
- state_line_two = encode_desc_rev_counter_for_state(desc_two);
- tt_str_op(state_line_two, OP_EQ,
- "8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PA 240");
-
- /* Now let's test our state parsing function: */
- int service_found;
- uint64_t cached_rev_counter;
-
- /* First's try with wrong pubkey and check that no service was found */
- cached_rev_counter =check_state_line_for_service_rev_counter(state_line_one,
- &desc_two->blinded_kp.pubkey,
- &service_found);
- tt_int_op(service_found, OP_EQ, 0);
- tt_u64_op(cached_rev_counter, OP_EQ, 0);
-
- /* Now let's try with the right pubkeys */
- cached_rev_counter =check_state_line_for_service_rev_counter(state_line_one,
- &desc_one->blinded_kp.pubkey,
- &service_found);
- tt_int_op(service_found, OP_EQ, 1);
- tt_u64_op(cached_rev_counter, OP_EQ, 42);
-
- cached_rev_counter =check_state_line_for_service_rev_counter(state_line_two,
- &desc_two->blinded_kp.pubkey,
- &service_found);
- tt_int_op(service_found, OP_EQ, 1);
- tt_u64_op(cached_rev_counter, OP_EQ, 240);
-
- done:
- tor_free(state_line_one);
- tor_free(state_line_two);
- service_descriptor_free(desc_one);
- service_descriptor_free(desc_two);
-}
-
/** Global vars used by test_rendezvous1_parsing() */
static char rend1_payload[RELAY_PAYLOAD_SIZE];
static size_t rend1_payload_len = 0;
@@ -1643,8 +1583,6 @@ struct testcase_t hs_service_tests[] = {
NULL, NULL },
{ "upload_descriptors", test_upload_descriptors, TT_FORK,
NULL, NULL },
- { "revision_counter_state", test_revision_counter_state, TT_FORK,
- NULL, NULL },
{ "rendezvous1_parsing", test_rendezvous1_parsing, TT_FORK,
NULL, NULL },
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits