]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hs-v2: Move v2 circuit cleanup actions into hs_circ_cleanup()
authorDavid Goulet <dgoulet@torproject.org>
Wed, 30 Oct 2019 18:48:04 +0000 (14:48 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 20 Nov 2019 15:25:52 +0000 (10:25 -0500)
Refactor to decomplexify circuit_about_to_free() and finally have one single
entry point into the HS subsystems (v2 and v3) for when a circuit is freed.

With this, hs_circ_cleanup() becomes the one and only entry point when a
circuit is freed which then routes to the right subsystem version for any
actions to be taken.

This moves a big chunk of code from circuituse.c to rendclient.c. No behavior
change. Next commit will refactor it to reduce our technical debt.

Part of #32020

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/circuitlist.c
src/feature/hs/hs_circuit.c
src/feature/rend/rendclient.c
src/feature/rend/rendclient.h

index 9a0b9241da44cfdccc29d20899a1442466f10d64..3ae482a5b27e98bd2e1c7ec36e64107e7c87e499 100644 (file)
@@ -2343,43 +2343,6 @@ circuit_about_to_free(circuit_t *circ)
      orig_reason);
   }
 
-  if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
-    origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
-    int timed_out = (reason == END_CIRC_REASON_TIMEOUT);
-    tor_assert(circ->state == CIRCUIT_STATE_OPEN);
-    tor_assert(ocirc->build_state->chosen_exit);
-    if (orig_reason != END_CIRC_REASON_IP_NOW_REDUNDANT &&
-        ocirc->rend_data) {
-      /* treat this like getting a nack from it */
-      log_info(LD_REND, "Failed intro circ %s to %s (awaiting ack). %s",
-          safe_str_client(rend_data_get_address(ocirc->rend_data)),
-          safe_str_client(build_state_get_exit_nickname(ocirc->build_state)),
-          timed_out ? "Recording timeout." : "Removing from descriptor.");
-      rend_client_report_intro_point_failure(ocirc->build_state->chosen_exit,
-                                             ocirc->rend_data,
-                                             timed_out ?
-                                             INTRO_POINT_FAILURE_TIMEOUT :
-                                             INTRO_POINT_FAILURE_GENERIC);
-    }
-  } else if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING &&
-             reason != END_CIRC_REASON_TIMEOUT) {
-    origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
-    if (ocirc->build_state->chosen_exit && ocirc->rend_data) {
-      if (orig_reason != END_CIRC_REASON_IP_NOW_REDUNDANT &&
-          ocirc->rend_data) {
-        log_info(LD_REND, "Failed intro circ %s to %s "
-            "(building circuit to intro point). "
-            "Marking intro point as possibly unreachable.",
-            safe_str_client(rend_data_get_address(ocirc->rend_data)),
-            safe_str_client(build_state_get_exit_nickname(
-                                              ocirc->build_state)));
-        rend_client_report_intro_point_failure(ocirc->build_state->chosen_exit,
-                                              ocirc->rend_data,
-                                              INTRO_POINT_FAILURE_UNREACHABLE);
-      }
-    }
-  }
-
   if (circ->n_chan) {
     circuit_clear_cell_queue(circ, circ->n_chan);
     /* Only send destroy if the channel isn't closing anyway */
index 9d21acf42fdc0c217a1b367c7c310230910641b2..1a3767ce628c739f08c0b21ea28ac793870c5116 100644 (file)
@@ -25,6 +25,7 @@
 #include "feature/nodelist/describe.h"
 #include "feature/nodelist/nodelist.h"
 #include "feature/rend/rendservice.h"
+#include "feature/rend/rendclient.h"
 #include "feature/stats/rephist.h"
 #include "lib/crypt_ops/crypto_dh.h"
 #include "lib/crypt_ops/crypto_rand.h"
@@ -1205,6 +1206,15 @@ hs_circ_cleanup(circuit_t *circ)
 {
   tor_assert(circ);
 
+  /* v2 specific circuits. */
+  if (circuit_is_hs_v2(circ)) {
+    if (circuit_is_hs_client(circ)) {
+      rend_client_circuit_cleanup(circ);
+    }
+  }
+
+  /* From this point on, it is v3 specific. */
+
   /* If it's a service-side intro circ, notify the HS subsystem for the intro
    * point circuit closing so it can be dealt with cleanly. */
   if (circ->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO ||
index 6f4ee8b8c15ed4ae28a163f16e77e355767e13a1..9718398255de7c51649546747f653f675ddfb1ca 100644 (file)
@@ -1250,3 +1250,51 @@ rend_parse_service_authorization(const or_options_t *options,
   }
   return res;
 }
+
+/** The given circuit is being freed. Take appropriate action if it is of
+ * interest to the client subsystem. */
+void
+rend_client_circuit_cleanup(circuit_t *circ)
+{
+  int reason = circ->marked_for_close_reason;
+  int orig_reason = circ->marked_for_close_orig_reason;
+
+  tor_assert(circ);
+
+  if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
+    origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
+    int timed_out = (reason == END_CIRC_REASON_TIMEOUT);
+    tor_assert(circ->state == CIRCUIT_STATE_OPEN);
+    tor_assert(ocirc->build_state->chosen_exit);
+    if (orig_reason != END_CIRC_REASON_IP_NOW_REDUNDANT &&
+        ocirc->rend_data) {
+      /* treat this like getting a nack from it */
+      log_info(LD_REND, "Failed intro circ %s to %s (awaiting ack). %s",
+          safe_str_client(rend_data_get_address(ocirc->rend_data)),
+          safe_str_client(build_state_get_exit_nickname(ocirc->build_state)),
+          timed_out ? "Recording timeout." : "Removing from descriptor.");
+      rend_client_report_intro_point_failure(ocirc->build_state->chosen_exit,
+                                             ocirc->rend_data,
+                                             timed_out ?
+                                             INTRO_POINT_FAILURE_TIMEOUT :
+                                             INTRO_POINT_FAILURE_GENERIC);
+    }
+  } else if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING &&
+             reason != END_CIRC_REASON_TIMEOUT) {
+    origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
+    if (ocirc->build_state->chosen_exit && ocirc->rend_data) {
+      if (orig_reason != END_CIRC_REASON_IP_NOW_REDUNDANT &&
+          ocirc->rend_data) {
+        log_info(LD_REND, "Failed intro circ %s to %s "
+            "(building circuit to intro point). "
+            "Marking intro point as possibly unreachable.",
+            safe_str_client(rend_data_get_address(ocirc->rend_data)),
+            safe_str_client(build_state_get_exit_nickname(
+                                              ocirc->build_state)));
+        rend_client_report_intro_point_failure(ocirc->build_state->chosen_exit,
+                                              ocirc->rend_data,
+                                              INTRO_POINT_FAILURE_UNREACHABLE);
+      }
+    }
+  }
+}
index e5f333238e3f24ba14aff27d8fbc7999dc216908..dd9fa61ce95587c9e3126d1d3a3fddd4da49e42f 100644 (file)
@@ -47,5 +47,7 @@ rend_service_authorization_t *rend_client_lookup_service_authorization(
                                                 const char *onion_address);
 void rend_service_authorization_free_all(void);
 
+void rend_client_circuit_cleanup(circuit_t *circ);
+
 #endif /* !defined(TOR_RENDCLIENT_H) */