[tor-commits] [tor/master] prop224: Function to inc/decrement num rendezvous stream

nickm at torproject.org nickm at torproject.org
Wed Aug 9 00:36:39 UTC 2017


commit 5c4f4acedb8600769889cdff0940806c27b679bd
Author: George Kadianakis <desnacked at riseup.net>
Date:   Mon Jul 31 17:59:12 2017 +0300

    prop224: Function to inc/decrement num rendezvous stream
    
    Add a common function for both legacy and prop224 hidden service to increment
    and decrement the rendezvous stream counter on an origin circuit.
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/or/circuituse.c      |  3 +--
 src/or/connection_edge.c | 10 +---------
 src/or/hs_common.c       | 34 ++++++++++++++++++++++++++++++++++
 src/or/hs_common.h       |  3 +++
 4 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 66006542d..21cc9c540 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -1383,8 +1383,7 @@ circuit_detach_stream(circuit_t *circ, edge_connection_t *conn)
        * number of streams on the circuit associated with the rend service.
        */
       if (circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED) {
-        tor_assert(origin_circ->rend_data);
-        origin_circ->rend_data->nr_streams--;
+        hs_dec_rdv_stream_counter(origin_circ);
       }
       return;
     }
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 9f0cc061e..12ddc7e82 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -3139,15 +3139,7 @@ handle_hs_exit_conn(circuit_t *circ, edge_connection_t *conn)
   conn->on_circuit = circ;
   assert_circuit_ok(circ);
 
-  if (origin_circ->rend_data) {
-    origin_circ->rend_data->nr_streams++;
-  } else if (origin_circ->hs_ident) {
-    origin_circ->hs_ident->num_rdv_streams++;
-  } else {
-    /* The previous if/else at the start of the function guarantee that we'll
-     * never end up in a else situation unless it's freed in between. */
-    tor_assert(0);
-  }
+  hs_inc_rdv_stream_counter(origin_circ);
 
   /* Connect tor to the hidden service destination. */
   connection_exit_connect(conn);
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 2b637eb78..0d3d41b7c 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -1333,3 +1333,37 @@ hs_free_all(void)
   hs_cache_free_all();
 }
 
+/* For the given origin circuit circ, decrement the number of rendezvous
+ * stream counter. This handles every hidden service version. */
+void
+hs_dec_rdv_stream_counter(origin_circuit_t *circ)
+{
+  tor_assert(circ);
+
+  if (circ->rend_data) {
+    circ->rend_data->nr_streams--;
+  } else if (circ->hs_ident) {
+    circ->hs_ident->num_rdv_streams--;
+  } else {
+    /* Should not be called if this circuit is not for hidden service. */
+    tor_assert_nonfatal_unreached();
+  }
+}
+
+/* For the given origin circuit circ, increment the number of rendezvous
+ * stream counter. This handles every hidden service version. */
+void
+hs_inc_rdv_stream_counter(origin_circuit_t *circ)
+{
+  tor_assert(circ);
+
+  if (circ->rend_data) {
+    circ->rend_data->nr_streams++;
+  } else if (circ->hs_ident) {
+    circ->hs_ident->num_rdv_streams++;
+  } else {
+    /* Should not be called if this circuit is not for hidden service. */
+    tor_assert_nonfatal_unreached();
+  }
+}
+
diff --git a/src/or/hs_common.h b/src/or/hs_common.h
index 5004e0208..fd2a1f4e3 100644
--- a/src/or/hs_common.h
+++ b/src/or/hs_common.h
@@ -222,6 +222,9 @@ void hs_get_responsible_hsdirs(const ed25519_public_key_t *blinded_pk,
 
 int hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn);
 
+void hs_inc_rdv_stream_counter(origin_circuit_t *circ);
+void hs_dec_rdv_stream_counter(origin_circuit_t *circ);
+
 #ifdef HS_COMMON_PRIVATE
 
 STATIC void get_disaster_srv(uint64_t time_period_num, uint8_t *srv_out);





More information about the tor-commits mailing list