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

[tor-commits] [tor/master] Split client-side get_rend_circ into two functions.



commit 855982728085cc9497c70c2b74d8d58b62cab1a1
Author: Fernando Fernandez Mancera <ffernandezmancera@xxxxxxxxx>
Date:   Fri Dec 8 18:10:07 2017 +0100

    Split client-side get_rend_circ into two functions.
    
    Split hs_circuitmap_get_rend_circ_client_side(). One returns only established
    circuits (hs_circuitmap_get_established_rend_circ_client_side()) and the other
    returns all kinds of circuits.
    
    Fixes #23459
    
    Signed-off-by: Fernando Fernandez Mancera <ffernandezmancera@xxxxxxxxx>
---
 changes/ticket23459    |  4 ++++
 src/or/hs_circuitmap.c | 36 ++++++++++++++++++++++++++++++------
 src/or/hs_circuitmap.h |  2 ++
 src/or/hs_client.c     |  3 ++-
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/changes/ticket23459 b/changes/ticket23459
new file mode 100644
index 000000000..a6452e4ee
--- /dev/null
+++ b/changes/ticket23459
@@ -0,0 +1,4 @@
+  o Code simplification and refactoring (circuit rendezvous):
+    - Split get rendezvous circuit on client side on two different functions.
+      One that returns only established circuits and another that returns all
+      kinds of circuits. Closes ticket 23459.
diff --git a/src/or/hs_circuitmap.c b/src/or/hs_circuitmap.c
index 97d6053e9..9d3e37073 100644
--- a/src/or/hs_circuitmap.c
+++ b/src/or/hs_circuitmap.c
@@ -428,30 +428,54 @@ hs_circuitmap_get_rend_circ_client_side(const uint8_t *cookie)
 {
   origin_circuit_t *circ = NULL;
 
-  circ = hs_circuitmap_get_origin_circuit(HS_TOKEN_REND_CLIENT_SIDE,
-                                          REND_TOKEN_LEN, cookie,
-                                          CIRCUIT_PURPOSE_C_REND_READY);
+  circ = hs_circuitmap_get_established_rend_circ_client_side(cookie);
   if (circ) {
     return circ;
   }
 
   circ = hs_circuitmap_get_origin_circuit(HS_TOKEN_REND_CLIENT_SIDE,
                                           REND_TOKEN_LEN, cookie,
-                                 CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED);
+                                          CIRCUIT_PURPOSE_C_ESTABLISH_REND);
+  return circ;
+}
+
+/*  Public function: Return client-side established rendezvous circuit with
+ *  rendezvous <b>cookie</b>. It will look for circuits with the following
+ *  purposes:
+ *
+ * a) CIRCUIT_PURPOSE_C_REND_READY: Established rend circuit (received
+ *    RENDEZVOUS_ESTABLISHED). Waiting for RENDEZVOUS2 from service, and for
+ *    INTRODUCE_ACK from intro point.
+ *
+ * b) CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED: Established rend circuit and
+ *    introduce circuit acked. Waiting for RENDEZVOUS2 from service.
+ *
+ * c) CIRCUIT_PURPOSE_C_REND_JOINED: Established rend circuit and received
+ *    RENDEZVOUS2 from service.
+ *
+ * Return NULL if no such circuit is found in the circuitmap. */
+origin_circuit_t *
+hs_circuitmap_get_established_rend_circ_client_side(const uint8_t *cookie)
+{
+  origin_circuit_t *circ = NULL;
+
+  circ = hs_circuitmap_get_origin_circuit(HS_TOKEN_REND_CLIENT_SIDE,
+                                          REND_TOKEN_LEN, cookie,
+                                          CIRCUIT_PURPOSE_C_REND_READY);
   if (circ) {
     return circ;
   }
 
   circ = hs_circuitmap_get_origin_circuit(HS_TOKEN_REND_CLIENT_SIDE,
                                           REND_TOKEN_LEN, cookie,
-                                          CIRCUIT_PURPOSE_C_REND_JOINED);
+                                 CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED);
   if (circ) {
     return circ;
   }
 
   circ = hs_circuitmap_get_origin_circuit(HS_TOKEN_REND_CLIENT_SIDE,
                                           REND_TOKEN_LEN, cookie,
-                                          CIRCUIT_PURPOSE_C_ESTABLISH_REND);
+                                          CIRCUIT_PURPOSE_C_REND_JOINED);
   return circ;
 }
 
diff --git a/src/or/hs_circuitmap.h b/src/or/hs_circuitmap.h
index 43b2947c1..9e653480b 100644
--- a/src/or/hs_circuitmap.h
+++ b/src/or/hs_circuitmap.h
@@ -45,6 +45,8 @@ struct origin_circuit_t *
 hs_circuitmap_get_rend_circ_service_side(const uint8_t *cookie);
 struct origin_circuit_t *
 hs_circuitmap_get_rend_circ_client_side(const uint8_t *cookie);
+struct origin_circuit_t *
+hs_circuitmap_get_established_rend_circ_client_side(const uint8_t *cookie);
 
 void hs_circuitmap_register_intro_circ_v2_service_side(
                                         struct origin_circuit_t *circ,
diff --git a/src/or/hs_client.c b/src/or/hs_client.c
index 9ac653c72..0dea0bb8c 100644
--- a/src/or/hs_client.c
+++ b/src/or/hs_client.c
@@ -940,7 +940,8 @@ handle_introduce_ack_success(origin_circuit_t *intro_circ)
 
   /* Get the rendezvous circuit for this rendezvous cookie. */
   uint8_t *rendezvous_cookie = intro_circ->hs_ident->rendezvous_cookie;
-  rend_circ = hs_circuitmap_get_rend_circ_client_side(rendezvous_cookie);
+  rend_circ =
+  hs_circuitmap_get_established_rend_circ_client_side(rendezvous_cookie);
   if (rend_circ == NULL) {
     log_warn(LD_REND, "Can't find any rendezvous circuit. Stopping");
     goto end;



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