aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-06-05 09:04:09 -0400
committerNick Mathewson <nickm@torproject.org>2019-06-05 09:04:09 -0400
commitb39a8d315dcbfae002c6ced7434b6afd5a5670d1 (patch)
tree1e8a0f08d70e1cbf18b58bcf63a5941e8ff64460 /src/feature
parent0c16ec4c0775db4a91a99cb935d2528233deafb2 (diff)
parent41b94722e5c93ec06911f9c63296a65ce295c1ea (diff)
downloadtor-b39a8d315dcbfae002c6ced7434b6afd5a5670d1.tar.gz
tor-b39a8d315dcbfae002c6ced7434b6afd5a5670d1.zip
Merge remote-tracking branch 'tor-github/pr/1053'
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/hs/hs_circuit.c31
-rw-r--r--src/feature/hs/hs_circuit.h1
-rw-r--r--src/feature/rend/rendcommon.c11
-rw-r--r--src/feature/rend/rendcommon.h2
4 files changed, 45 insertions, 0 deletions
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c
index a6e86c5ab3..79377eb731 100644
--- a/src/feature/hs/hs_circuit.c
+++ b/src/feature/hs/hs_circuit.c
@@ -25,6 +25,7 @@
#include "feature/nodelist/describe.h"
#include "feature/nodelist/nodelist.h"
#include "feature/rend/rendservice.h"
+#include "feature/rend/rendcommon.h"
#include "feature/stats/rephist.h"
#include "lib/crypt_ops/crypto_dh.h"
#include "lib/crypt_ops/crypto_rand.h"
@@ -1192,3 +1193,33 @@ hs_circ_cleanup(circuit_t *circ)
hs_circuitmap_remove_circuit(circ);
}
}
+
+/* The given circuit will be repurposed so take the appropriate actions. A
+ * cleanup from the HS maps and of all HS related structures is done.
+ *
+ * Once this function returns, the circuit can be safely repurposed. */
+void
+hs_circ_repurpose(circuit_t *circ)
+{
+ origin_circuit_t *origin_circ;
+
+ tor_assert(circ);
+
+ /* Only repurposing an origin circuit is possible for HS. */
+ if (!CIRCUIT_IS_ORIGIN(circ)) {
+ return;
+ }
+ origin_circ = TO_ORIGIN_CIRCUIT(circ);
+
+ /* First, cleanup the circuit from the HS maps. */
+ hs_circ_cleanup(circ);
+
+ /* Depending on the version, different cleanup is done. */
+ if (origin_circ->rend_data) {
+ /* v2. */
+ rend_circ_cleanup(origin_circ);
+ } else if (origin_circ->hs_ident) {
+ /* v3. */
+ hs_ident_circuit_free(origin_circ->hs_ident);
+ }
+}
diff --git a/src/feature/hs/hs_circuit.h b/src/feature/hs/hs_circuit.h
index b8d8b25add..0786f3ee45 100644
--- a/src/feature/hs/hs_circuit.h
+++ b/src/feature/hs/hs_circuit.h
@@ -16,6 +16,7 @@
/* Cleanup function when the circuit is closed or/and freed. */
void hs_circ_cleanup(circuit_t *circ);
+void hs_circ_repurpose(circuit_t *circ);
/* Circuit API. */
int hs_circ_service_intro_has_opened(hs_service_t *service,
diff --git a/src/feature/rend/rendcommon.c b/src/feature/rend/rendcommon.c
index 777de2984c..265ee368f1 100644
--- a/src/feature/rend/rendcommon.c
+++ b/src/feature/rend/rendcommon.c
@@ -1046,3 +1046,14 @@ rend_circuit_pk_digest_eq(const origin_circuit_t *ocirc,
match:
return 1;
}
+
+/* Cleanup the given circuit of all HS v2 data structure. */
+void
+rend_circ_cleanup(origin_circuit_t *circ)
+{
+ tor_assert(circ);
+
+ /* Both fields are set to NULL with these. */
+ crypto_pk_free(circ->intro_key);
+ rend_data_free(circ->rend_data);
+}
diff --git a/src/feature/rend/rendcommon.h b/src/feature/rend/rendcommon.h
index f136863c7a..c9a04846d7 100644
--- a/src/feature/rend/rendcommon.h
+++ b/src/feature/rend/rendcommon.h
@@ -71,6 +71,8 @@ int rend_non_anonymous_mode_enabled(const or_options_t *options);
void assert_circ_anonymity_ok(const origin_circuit_t *circ,
const or_options_t *options);
+void rend_circ_cleanup(origin_circuit_t *circ);
+
#ifdef RENDCOMMON_PRIVATE
STATIC int