[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/main] hs: Build INTRODUCE extension in the encrypted section



commit 38e9d9b465f5ae825d054b7baf06a851ad6b371a
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Thu Feb 3 21:06:28 2022 +0000

    hs: Build INTRODUCE extension in the encrypted section
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/feature/hs/hs_cell.c    | 28 ++++++++++++++++++++++++++--
 src/feature/hs/hs_cell.h    |  2 ++
 src/feature/hs/hs_circuit.c |  8 ++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/feature/hs/hs_cell.c b/src/feature/hs/hs_cell.c
index 116395b3c8..4b961a6add 100644
--- a/src/feature/hs/hs_cell.c
+++ b/src/feature/hs/hs_cell.c
@@ -18,6 +18,7 @@
 #include "core/or/origin_circuit_st.h"
 
 /* Trunnel. */
+#include "trunnel/congestion_control.h"
 #include "trunnel/ed25519_cert.h"
 #include "trunnel/extension.h"
 #include "trunnel/hs/cell_establish_intro.h"
@@ -372,6 +373,26 @@ introduce1_encrypt_and_encode(trn_cell_introduce1_t *cell,
   tor_free(encrypted);
 }
 
+/** Build and set the INTRODUCE congestion control extension in the given
+ * extensions. */
+static void
+build_introduce_cc_extension(trn_extension_t *extensions)
+{
+  trn_extension_field_t *field = NULL;
+
+  /* Build CC request extension. */
+  field = trn_extension_field_new();
+  trn_extension_field_set_field_type(field,
+                                     TRUNNEL_EXT_TYPE_CC_FIELD_REQUEST);
+
+  /* No payload indicating a request to use congestion control. */
+  trn_extension_field_set_field_len(field, 0);
+
+  /* Build final extension. */
+  trn_extension_add_fields(extensions, field);
+  trn_extension_set_num(extensions, trn_extension_get_num(extensions) + 1);
+}
+
 /** Using the INTRODUCE1 data, setup the ENCRYPTED section in cell. This means
  * set it, encrypt it and encode it. */
 static void
@@ -387,10 +408,13 @@ introduce1_set_encrypted(trn_cell_introduce1_t *cell,
   enc_cell = trn_cell_introduce_encrypted_new();
   tor_assert(enc_cell);
 
-  /* Set extension data. None are used. */
+  /* Setup extension(s) if any. */
   ext = trn_extension_new();
   tor_assert(ext);
-  trn_extension_set_num(ext, 0);
+  /* Build congestion control extension is enabled. */
+  if (data->cc_enabled) {
+    build_introduce_cc_extension(ext);
+  }
   trn_cell_introduce_encrypted_set_extensions(enc_cell, ext);
 
   /* Set the rendezvous cookie. */
diff --git a/src/feature/hs/hs_cell.h b/src/feature/hs/hs_cell.h
index c25fd45567..43be038a93 100644
--- a/src/feature/hs/hs_cell.h
+++ b/src/feature/hs/hs_cell.h
@@ -40,6 +40,8 @@ typedef struct hs_cell_introduce1_data_t {
   const curve25519_keypair_t *client_kp;
   /** Rendezvous point link specifiers. */
   smartlist_t *link_specifiers;
+  /** Congestion control parameters. */
+  unsigned int cc_enabled : 1;
 } hs_cell_introduce1_data_t;
 
 /** This data structure contains data that we need to parse an INTRODUCE2 cell
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c
index 3347bdca07..10a6f51eb3 100644
--- a/src/feature/hs/hs_circuit.c
+++ b/src/feature/hs/hs_circuit.c
@@ -37,6 +37,7 @@
 #include "trunnel/ed25519_cert.h"
 #include "trunnel/hs/cell_establish_intro.h"
 
+#include "core/or/congestion_control_st.h"
 #include "core/or/cpath_build_state_st.h"
 #include "core/or/crypt_path_st.h"
 #include "feature/nodelist/node_st.h"
@@ -549,6 +550,7 @@ setup_introduce1_data(const hs_desc_intro_point_t *ip,
     /* We can't rendezvous without the curve25519 onion key. */
     goto end;
   }
+
   /* Success, we have valid introduce data. */
   ret = 0;
 
@@ -1072,6 +1074,12 @@ hs_circ_send_introduce1(origin_circuit_t *intro_circ,
     goto close;
   }
 
+  /* If the rend circ was set up for congestion control, add that to the
+   * intro data, to signal it in an extension */
+  if (TO_CIRCUIT(rend_circ)->ccontrol) {
+    intro1_data.cc_enabled = 1;
+  }
+
   /* Final step before we encode a cell, we setup the circuit identifier which
    * will generate both the rendezvous cookie and client keypair for this
    * connection. Those are put in the ident. */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits