diff options
author | David Goulet <dgoulet@torproject.org> | 2019-05-28 09:44:06 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2019-05-29 09:40:13 -0400 |
commit | 3789f22bcbfbc6de415a838e4c4bfb2555c7d6c3 (patch) | |
tree | 823e4db5b38cec12156f5d3a4dfb9df725eeba64 /src/feature/hs | |
parent | e5deb2bbc73d8830ae6c479a4532e72112f5484a (diff) | |
download | tor-3789f22bcbfbc6de415a838e4c4bfb2555c7d6c3.tar.gz tor-3789f22bcbfbc6de415a838e4c4bfb2555c7d6c3.zip |
hs: Implement a helper to repurpose a circuit
When we repurpose a hidden service circuit, we need to clean up from the HS
circuit map and any HS related data structured contained in the circuit.
This commit adds an helper function that does it when repurposing a hidden
service circuit.
Fixes #29034
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/hs')
-rw-r--r-- | src/feature/hs/hs_circuit.c | 31 | ||||
-rw-r--r-- | src/feature/hs/hs_circuit.h | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c index e3873d2f18..2e59a357b3 100644 --- a/src/feature/hs/hs_circuit.c +++ b/src/feature/hs/hs_circuit.c @@ -24,6 +24,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" @@ -1269,3 +1270,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, |