[tor-commits] [tor/main] Add an exported struct to onion handshakes for circuits params

dgoulet at torproject.org dgoulet at torproject.org
Tue Feb 22 20:48:19 UTC 2022


commit 244444e8b1ac36bf9148aa656e4eb9e293daa5b4
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Sep 14 15:15:30 2021 -0400

    Add an exported struct to onion handshakes for circuits params
    
    THis will eventually hold the congestion control parameters that we
    negotiated, plus whatever else is relevant.
---
 src/core/crypto/onion_crypto.c |  7 ++++++-
 src/core/crypto/onion_crypto.h | 14 +++++++++++++-
 src/core/mainloop/cpuworker.c  |  7 ++++++-
 src/core/or/circuitbuild.c     |  4 ++++
 src/core/or/command.c          |  7 ++++++-
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/core/crypto/onion_crypto.c b/src/core/crypto/onion_crypto.c
index 66c21bf655..f93c2c8c58 100644
--- a/src/core/crypto/onion_crypto.c
+++ b/src/core/crypto/onion_crypto.c
@@ -183,9 +183,11 @@ onion_skin_server_handshake(int type,
                       uint8_t *reply_out,
                       size_t reply_out_maxlen,
                       uint8_t *keys_out, size_t keys_out_len,
-                      uint8_t *rend_nonce_out)
+                      uint8_t *rend_nonce_out,
+                      circuit_params_t *params_out)
 {
   int r = -1;
+  memset(params_out, 0, sizeof(*params_out)); // TODO: actually set.
 
   switch (type) {
   case ONION_HANDSHAKE_TYPE_TAP:
@@ -262,11 +264,14 @@ onion_skin_client_handshake(int type,
                       const uint8_t *reply, size_t reply_len,
                       uint8_t *keys_out, size_t keys_out_len,
                       uint8_t *rend_authenticator_out,
+                      circuit_params_t *params_out,
                       const char **msg_out)
 {
   if (handshake_state->tag != type)
     return -1;
 
+  memset(params_out, 0, sizeof(*params_out)); // TODO: actually set.
+
   switch (type) {
   case ONION_HANDSHAKE_TYPE_TAP:
     if (reply_len != TAP_ONIONSKIN_REPLY_LEN) {
diff --git a/src/core/crypto/onion_crypto.h b/src/core/crypto/onion_crypto.h
index bf25552b83..af8dd1f03f 100644
--- a/src/core/crypto/onion_crypto.h
+++ b/src/core/crypto/onion_crypto.h
@@ -22,6 +22,16 @@ typedef struct server_onion_keys_t {
 
 void onion_handshake_state_release(onion_handshake_state_t *state);
 
+/**
+ * Parameters negotiated as part of a circuit handshake.
+ */
+typedef struct circuit_params_t {
+  /* placeholder field for congestion control algorithm. Right now this
+   * is always set to zero */
+  int cc_algorithm;
+  int cc_window;
+} circuit_params_t;
+
 int onion_skin_create(int type,
                       const extend_info_t *node,
                       onion_handshake_state_t *state_out,
@@ -33,12 +43,14 @@ int onion_skin_server_handshake(int type,
                       uint8_t *reply_out,
                       size_t reply_out_maxlen,
                       uint8_t *keys_out, size_t key_out_len,
-                      uint8_t *rend_nonce_out);
+                      uint8_t *rend_nonce_out,
+                      circuit_params_t *negotiated_params_out);
 int onion_skin_client_handshake(int type,
                       const onion_handshake_state_t *handshake_state,
                       const uint8_t *reply, size_t reply_len,
                       uint8_t *keys_out, size_t key_out_len,
                       uint8_t *rend_authenticator_out,
+                      circuit_params_t *negotiated_params_out,
                       const char **msg_out);
 
 server_onion_keys_t *server_onion_keys_new(void);
diff --git a/src/core/mainloop/cpuworker.c b/src/core/mainloop/cpuworker.c
index b7b09784fa..2f6dae36a8 100644
--- a/src/core/mainloop/cpuworker.c
+++ b/src/core/mainloop/cpuworker.c
@@ -416,6 +416,7 @@ cpuworker_onion_handshake_threadfn(void *state_, void *work_)
   const create_cell_t *cc = &req.create_cell;
   created_cell_t *cell_out = &rpl.created_cell;
   struct timeval tv_start = {0,0}, tv_end;
+  circuit_params_t params;
   int n;
   rpl.timed = req.timed;
   rpl.started_at = req.started_at;
@@ -428,7 +429,8 @@ cpuworker_onion_handshake_threadfn(void *state_, void *work_)
                                   cell_out->reply,
                                   sizeof(cell_out->reply),
                                   rpl.keys, CPATH_KEY_MATERIAL_LEN,
-                                  rpl.rend_auth_material);
+                                  rpl.rend_auth_material,
+                                  &params);
   if (n < 0) {
     /* failure */
     log_debug(LD_OR,"onion_skin_server_handshake failed.");
@@ -451,6 +453,9 @@ cpuworker_onion_handshake_threadfn(void *state_, void *work_)
     }
     rpl.success = 1;
   }
+
+  // TODO: pass the parameters back up so we can initialize the cc paremeters.
+
   rpl.magic = CPUWORKER_REPLY_MAGIC;
   if (req.timed) {
     struct timeval tv_diff;
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index dc8d888c97..f67fe196e5 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -1242,6 +1242,7 @@ circuit_finish_handshake(origin_circuit_t *circ,
   }
   tor_assert(hop->state == CPATH_STATE_AWAITING_KEYS);
 
+  circuit_params_t params;
   {
     const char *msg = NULL;
     if (onion_skin_client_handshake(hop->handshake_state.tag,
@@ -1249,6 +1250,7 @@ circuit_finish_handshake(origin_circuit_t *circ,
                                     reply->reply, reply->handshake_len,
                                     (uint8_t*)keys, sizeof(keys),
                                     (uint8_t*)hop->rend_circ_nonce,
+                                    &params,
                                     &msg) < 0) {
       if (msg)
         log_warn(LD_CIRC,"onion_skin_client_handshake failed: %s", msg);
@@ -1258,6 +1260,8 @@ circuit_finish_handshake(origin_circuit_t *circ,
 
   onion_handshake_state_release(&hop->handshake_state);
 
+  // XXXX TODO: use `params` to initialize the congestion control.
+
   if (cpath_init_circuit_crypto(hop, keys, sizeof(keys), 0, 0)<0) {
     return -END_CIRC_REASON_TORPROTOCOL;
   }
diff --git a/src/core/or/command.c b/src/core/or/command.c
index 5fdd8dd135..fd6cebe743 100644
--- a/src/core/or/command.c
+++ b/src/core/or/command.c
@@ -360,6 +360,7 @@ command_process_create_cell(cell_t *cell, channel_t *chan)
     uint8_t rend_circ_nonce[DIGEST_LEN];
     int len;
     created_cell_t created_cell;
+    circuit_params_t params;
 
     memset(&created_cell, 0, sizeof(created_cell));
     len = onion_skin_server_handshake(ONION_HANDSHAKE_TYPE_FAST,
@@ -369,7 +370,8 @@ command_process_create_cell(cell_t *cell, channel_t *chan)
                                        created_cell.reply,
                                        sizeof(created_cell.reply),
                                        keys, CPATH_KEY_MATERIAL_LEN,
-                                       rend_circ_nonce);
+                                       rend_circ_nonce,
+                                       &params);
     tor_free(create_cell);
     if (len < 0) {
       log_warn(LD_OR,"Failed to generate key material. Closing.");
@@ -379,6 +381,9 @@ command_process_create_cell(cell_t *cell, channel_t *chan)
     created_cell.cell_type = CELL_CREATED_FAST;
     created_cell.handshake_len = len;
 
+    // TODO: We should in theory look at params here, though it will always
+    // tell us to use the old-fashioned congestion control.
+
     if (onionskin_answer(circ, &created_cell,
                          (const char *)keys, sizeof(keys),
                          rend_circ_nonce)<0) {





More information about the tor-commits mailing list