[tor-commits] [tor/master] Hiding crypt_path_t: Rename some functions to fit the crypt_path API.

dgoulet at torproject.org dgoulet at torproject.org
Wed May 8 12:21:47 UTC 2019


commit 58fbbc1409f65bbb65c9da03a035a5767820146b
Author: George Kadianakis <desnacked at riseup.net>
Date:   Tue Apr 9 12:38:19 2019 +0300

    Hiding crypt_path_t: Rename some functions to fit the crypt_path API.
    
    Some of these functions are now public and cpath-specific so their name should
    signify the fact they are part of the cpath module:
    
    assert_cpath_layer_ok -> cpath_assert_layer_ok
    assert_cpath_ok -> cpath_assert_ok
    onion_append_hop -> cpath_append_hop
    circuit_init_cpath_crypto -> cpath_init_circuit_crypto
    circuit_free_cpath_node -> cpath_free
    onion_append_to_cpath -> cpath_extend_linked_list
---
 src/core/mainloop/connection.c |  2 +-
 src/core/or/circuitbuild.c     |  8 ++++----
 src/core/or/circuitlist.c      | 10 +++++-----
 src/core/or/crypt_path.c       | 16 ++++++++--------
 src/core/or/crypt_path.h       | 16 ++++++----------
 src/feature/hs/hs_circuit.c    |  6 +++---
 src/feature/rend/rendservice.c |  4 ++--
 src/test/test_circuitpadding.c |  6 +++---
 src/test/test_circuitstats.c   | 16 ++++++++--------
 src/test/test_relaycrypt.c     |  2 +-
 10 files changed, 41 insertions(+), 45 deletions(-)

diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index f6adfa765..de49a1b7e 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -5331,7 +5331,7 @@ assert_connection_ok(connection_t *conn, time_t now)
         tor_assert(entry_conn->socks_request->has_finished);
         if (!conn->marked_for_close) {
           tor_assert(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer);
-          assert_cpath_layer_ok(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer);
+          cpath_assert_layer_ok(ENTRY_TO_EDGE_CONN(entry_conn)->cpath_layer);
         }
       }
     }
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index 1ceb77c4a..b445b9463 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -1409,7 +1409,7 @@ circuit_finish_handshake(origin_circuit_t *circ,
 
   onion_handshake_state_release(&hop->handshake_state);
 
-  if (circuit_init_cpath_crypto(hop, keys, sizeof(keys), 0, 0)<0) {
+  if (cpath_init_circuit_crypto(hop, keys, sizeof(keys), 0, 0)<0) {
     return -END_CIRC_REASON_TORPROTOCOL;
   }
 
@@ -1461,7 +1461,7 @@ circuit_truncated(origin_circuit_t *circ, int reason)
     }
 
     layer->next = victim->next;
-    circuit_free_cpath_node(victim);
+    cpath_free(victim);
   }
 
   log_info(LD_CIRC, "finished");
@@ -2280,7 +2280,7 @@ circuit_append_new_exit(origin_circuit_t *circ, extend_info_t *exit_ei)
   state->chosen_exit = extend_info_dup(exit_ei);
 
   ++circ->build_state->desired_path_len;
-  onion_append_hop(&circ->cpath, exit_ei);
+  cpath_append_hop(&circ->cpath, exit_ei);
   return 0;
 }
 
@@ -2713,7 +2713,7 @@ onion_extend_cpath(origin_circuit_t *circ)
             extend_info_describe(info),
             cur_len+1, build_state_get_exit_nickname(state));
 
-  onion_append_hop(&circ->cpath, info);
+  cpath_append_hop(&circ->cpath, info);
   extend_info_free(info);
   return 0;
 }
diff --git a/src/core/or/circuitlist.c b/src/core/or/circuitlist.c
index 83c651ff1..cd2259c98 100644
--- a/src/core/or/circuitlist.c
+++ b/src/core/or/circuitlist.c
@@ -1148,7 +1148,7 @@ circuit_free_(circuit_t *circ)
 
     if (ocirc->build_state) {
         extend_info_free(ocirc->build_state->chosen_exit);
-        circuit_free_cpath_node(ocirc->build_state->pending_final_cpath);
+        cpath_free(ocirc->build_state->pending_final_cpath);
         cpath_ref_decref(ocirc->build_state->service_pending_final_cpath_ref);
     }
     tor_free(ocirc->build_state);
@@ -1272,10 +1272,10 @@ circuit_clear_cpath(origin_circuit_t *circ)
   while (cpath->next && cpath->next != head) {
     victim = cpath;
     cpath = victim->next;
-    circuit_free_cpath_node(victim);
+    cpath_free(victim);
   }
 
-  circuit_free_cpath_node(cpath);
+  cpath_free(cpath);
 
   circ->cpath = NULL;
 }
@@ -1338,7 +1338,7 @@ cpath_ref_decref(crypt_path_reference_t *cpath_ref)
 {
   if (cpath_ref != NULL) {
     if (--(cpath_ref->refcount) == 0) {
-      circuit_free_cpath_node(cpath_ref->cpath);
+      cpath_free(cpath_ref->cpath);
       tor_free(cpath_ref);
     }
   }
@@ -2830,7 +2830,7 @@ assert_circuit_ok,(const circuit_t *c))
                !smartlist_contains(circuits_pending_chans, c));
   }
   if (origin_circ && origin_circ->cpath) {
-    assert_cpath_ok(origin_circ->cpath);
+    cpath_assert_ok(origin_circ->cpath);
   }
   if (c->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED) {
     tor_assert(or_circ);
diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c
index ea07ec495..13063e5da 100644
--- a/src/core/or/crypt_path.c
+++ b/src/core/or/crypt_path.c
@@ -41,7 +41,7 @@ crypt_path_new(void)
  * This function is used to extend cpath by another hop.
  */
 void
-onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop)
+cpath_extend_linked_list(crypt_path_t **head_ptr, crypt_path_t *new_hop)
 {
   if (*head_ptr) {
     new_hop->next = (*head_ptr);
@@ -58,12 +58,12 @@ onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop)
  * corresponding router <b>choice</b>, and append it to the
  * end of the cpath <b>head_ptr</b>. */
 int
-onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
+cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
 {
   crypt_path_t *hop = crypt_path_new();
 
   /* link hop into the cpath, at the end. */
-  onion_append_to_cpath(head_ptr, hop);
+  cpath_extend_linked_list(head_ptr, hop);
 
   hop->state = CPATH_STATE_CLOSED;
 
@@ -79,12 +79,12 @@ onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
  * correct. Trigger an assert if anything is invalid.
  */
 void
-assert_cpath_ok(const crypt_path_t *cp)
+cpath_assert_ok(const crypt_path_t *cp)
 {
   const crypt_path_t *start = cp;
 
   do {
-    assert_cpath_layer_ok(cp);
+    cpath_assert_layer_ok(cp);
     /* layers must be in sequence of: "open* awaiting? closed*" */
     if (cp != start) {
       if (cp->state == CPATH_STATE_AWAITING_KEYS) {
@@ -102,7 +102,7 @@ assert_cpath_ok(const crypt_path_t *cp)
  * correct. Trigger an assert if anything is invalid.
  */
 void
-assert_cpath_layer_ok(const crypt_path_t *cp)
+cpath_assert_layer_ok(const crypt_path_t *cp)
 {
 //  tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */
 //  tor_assert(cp->port);
@@ -147,7 +147,7 @@ assert_cpath_layer_ok(const crypt_path_t *cp)
  * Return 0 if init was successful, else -1 if it failed.
  */
 int
-circuit_init_cpath_crypto(crypt_path_t *cpath,
+cpath_init_circuit_crypto(crypt_path_t *cpath,
                           const char *key_data, size_t key_data_len,
                           int reverse, int is_hs_v3)
 {
@@ -160,7 +160,7 @@ circuit_init_cpath_crypto(crypt_path_t *cpath,
 
 /** Deallocate space associated with the cpath node <b>victim</b>. */
 void
-circuit_free_cpath_node(crypt_path_t *victim)
+cpath_free(crypt_path_t *victim)
 {
   if (!victim || BUG(!victim->private))
     return;
diff --git a/src/core/or/crypt_path.h b/src/core/or/crypt_path.h
index 874ff2b2a..4a0117360 100644
--- a/src/core/or/crypt_path.h
+++ b/src/core/or/crypt_path.h
@@ -8,24 +8,20 @@
 
 crypt_path_t *crypt_path_new(void);
 
-/* rename */
-void assert_cpath_layer_ok(const crypt_path_t *cp);
+void cpath_assert_layer_ok(const crypt_path_t *cp);
 
-/* rename */
-void assert_cpath_ok(const crypt_path_t *cp);
+void cpath_assert_ok(const crypt_path_t *cp);
 
-/* rename */
-int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
+int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
 
-int circuit_init_cpath_crypto(crypt_path_t *cpath,
+int cpath_init_circuit_crypto(crypt_path_t *cpath,
                               const char *key_data, size_t key_data_len,
                               int reverse, int is_hs_v3);
 
 void
-circuit_free_cpath_node(crypt_path_t *victim);
+cpath_free(crypt_path_t *victim);
 
-/* rename */
-void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop);
+void cpath_extend_linked_list(crypt_path_t **head_ptr, crypt_path_t *new_hop);
 
 void
 cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt);
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c
index 3356db9d9..7d17aff72 100644
--- a/src/feature/hs/hs_circuit.c
+++ b/src/feature/hs/hs_circuit.c
@@ -89,7 +89,7 @@ create_rend_cpath(const uint8_t *ntor_key_seed, size_t seed_len,
   /* Setup the cpath */
   cpath = crypt_path_new();
 
-  if (circuit_init_cpath_crypto(cpath, (char*)keys, sizeof(keys),
+  if (cpath_init_circuit_crypto(cpath, (char*)keys, sizeof(keys),
                                 is_service_side, 1) < 0) {
     tor_free(cpath);
     goto err;
@@ -126,7 +126,7 @@ create_rend_cpath_legacy(origin_circuit_t *circ, const uint8_t *rend_cell_body)
     goto err;
   }
   /* ... and set up cpath. */
-  if (circuit_init_cpath_crypto(hop,
+  if (cpath_init_circuit_crypto(hop,
                                 keys+DIGEST_LEN, sizeof(keys)-DIGEST_LEN,
                                 0, 0) < 0)
     goto err;
@@ -177,7 +177,7 @@ finalize_rend_circuit(origin_circuit_t *circ, crypt_path_t *hop,
   circ->hs_circ_has_timed_out = 0;
 
   /* Append the hop to the cpath of this circuit */
-  onion_append_to_cpath(&circ->cpath, hop);
+  cpath_extend_linked_list(&circ->cpath, hop);
 
   /* In legacy code, 'pending_final_cpath' points to the final hop we just
    * appended to the cpath. We set the original pointer to NULL so that we
diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c
index 38da4cfe7..0ecd0e6ff 100644
--- a/src/feature/rend/rendservice.c
+++ b/src/feature/rend/rendservice.c
@@ -2163,7 +2163,7 @@ rend_service_receive_introduction(origin_circuit_t *circuit,
 
   cpath->rend_dh_handshake_state = dh;
   dh = NULL;
-  if (circuit_init_cpath_crypto(cpath,
+  if (cpath_init_circuit_crypto(cpath,
                                 keys+DIGEST_LEN, sizeof(keys)-DIGEST_LEN,
                                 1, 0)<0)
     goto err;
@@ -3547,7 +3547,7 @@ rend_service_rendezvous_has_opened(origin_circuit_t *circuit)
   hop->package_window = circuit_initial_package_window();
   hop->deliver_window = CIRCWINDOW_START;
 
-  onion_append_to_cpath(&circuit->cpath, hop);
+  cpath_extend_linked_list(&circuit->cpath, hop);
   circuit->build_state->pending_final_cpath = NULL; /* prevent double-free */
 
   /* Change the circuit purpose. */
diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c
index 6fa790c40..e33e56af3 100644
--- a/src/test/test_circuitpadding.c
+++ b/src/test/test_circuitpadding.c
@@ -145,7 +145,7 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan)
   circuit_set_n_circid_chan(circ, circ->n_circ_id, nchan);
 
   tmp_cpath = crypt_path_new();
-  if (circuit_init_cpath_crypto(tmp_cpath, whatevs_key,
+  if (cpath_init_circuit_crypto(tmp_cpath, whatevs_key,
                                 sizeof(whatevs_key), 0, 0)<0) {
     log_warn(LD_BUG,"Circuit initialization failed");
     return NULL;
@@ -1621,7 +1621,7 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
 
   // Add a hop to cpath
   crypt_path_t *hop = crypt_path_new();
-  onion_append_to_cpath(&TO_ORIGIN_CIRCUIT(client)->cpath, hop);
+  cpath_extend_linked_list(&TO_ORIGIN_CIRCUIT(client)->cpath, hop);
 
   hop->state = CPATH_STATE_OPEN;
 
@@ -1634,7 +1634,7 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
           digest, NULL, NULL, NULL,
           &addr, padding);
 
-  circuit_init_cpath_crypto(hop, whatevs_key, sizeof(whatevs_key), 0, 0);
+  cpath_init_circuit_crypto(hop, whatevs_key, sizeof(whatevs_key), 0, 0);
 
   hop->package_window = circuit_initial_package_window();
   hop->deliver_window = CIRCWINDOW_START;
diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c
index 1cbcb14f2..2a09622f0 100644
--- a/src/test/test_circuitstats.c
+++ b/src/test/test_circuitstats.c
@@ -28,7 +28,7 @@ origin_circuit_t *subtest_fourhop_circuit(struct timeval, int);
 origin_circuit_t *add_opened_threehop(void);
 origin_circuit_t *build_unopened_fourhop(struct timeval);
 
-int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
+int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
 
 static int marked_for_close;
 /* Mock function because we are not trying to test the close circuit that does
@@ -57,9 +57,9 @@ add_opened_threehop(void)
   or_circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
   or_circ->build_state->desired_path_len = DEFAULT_ROUTE_LEN;
 
-  onion_append_hop(&or_circ->cpath, &fakehop);
-  onion_append_hop(&or_circ->cpath, &fakehop);
-  onion_append_hop(&or_circ->cpath, &fakehop);
+  cpath_append_hop(&or_circ->cpath, &fakehop);
+  cpath_append_hop(&or_circ->cpath, &fakehop);
+  cpath_append_hop(&or_circ->cpath, &fakehop);
 
   or_circ->has_opened = 1;
   TO_CIRCUIT(or_circ)->state = CIRCUIT_STATE_OPEN;
@@ -82,10 +82,10 @@ build_unopened_fourhop(struct timeval circ_start_time)
   or_circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
   or_circ->build_state->desired_path_len = 4;
 
-  onion_append_hop(&or_circ->cpath, fakehop);
-  onion_append_hop(&or_circ->cpath, fakehop);
-  onion_append_hop(&or_circ->cpath, fakehop);
-  onion_append_hop(&or_circ->cpath, fakehop);
+  cpath_append_hop(&or_circ->cpath, fakehop);
+  cpath_append_hop(&or_circ->cpath, fakehop);
+  cpath_append_hop(&or_circ->cpath, fakehop);
+  cpath_append_hop(&or_circ->cpath, fakehop);
 
   tor_free(fakehop);
 
diff --git a/src/test/test_relaycrypt.c b/src/test/test_relaycrypt.c
index a3a102e73..1977958d1 100644
--- a/src/test/test_relaycrypt.c
+++ b/src/test/test_relaycrypt.c
@@ -54,7 +54,7 @@ testing_circuitset_setup(const struct testcase_t *testcase)
     relay_crypto_init(&hop->private->crypto, KEY_MATERIAL[i],
                       sizeof(KEY_MATERIAL[i]), 0, 0);
     hop->state = CPATH_STATE_OPEN;
-    onion_append_to_cpath(&cs->origin_circ->cpath, hop);
+    cpath_extend_linked_list(&cs->origin_circ->cpath, hop);
     tt_ptr_op(hop, OP_EQ, cs->origin_circ->cpath->prev);
   }
 





More information about the tor-commits mailing list