mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
prop224: Move get_intro_circuit() to hs_circuit.c
Make this function public so we can use it both in hs_circuit.c and hs_service.c to avoid code duplication. Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
6c3d525c36
commit
2cae4f4100
@ -215,17 +215,7 @@ count_opened_desc_intro_point_circuits(const hs_service_t *service,
|
|||||||
DIGEST256MAP_FOREACH(desc->intro_points.map, key,
|
DIGEST256MAP_FOREACH(desc->intro_points.map, key,
|
||||||
const hs_service_intro_point_t *, ip) {
|
const hs_service_intro_point_t *, ip) {
|
||||||
circuit_t *circ;
|
circuit_t *circ;
|
||||||
origin_circuit_t *ocirc;
|
origin_circuit_t *ocirc = hs_circ_service_get_intro_circ(ip);
|
||||||
if (ip->base.is_only_legacy) {
|
|
||||||
uint8_t digest[DIGEST_LEN];
|
|
||||||
if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ocirc = hs_circuitmap_get_intro_circ_v2_service_side(digest);
|
|
||||||
} else {
|
|
||||||
ocirc =
|
|
||||||
hs_circuitmap_get_intro_circ_v3_service_side(&ip->auth_key_kp.pubkey);
|
|
||||||
}
|
|
||||||
if (ocirc == NULL) {
|
if (ocirc == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -665,6 +655,29 @@ retry_service_rendezvous_point(const origin_circuit_t *circ)
|
|||||||
/* Public API */
|
/* Public API */
|
||||||
/* ========== */
|
/* ========== */
|
||||||
|
|
||||||
|
/* Return an introduction point circuit matching the given intro point object.
|
||||||
|
* NULL is returned is no such circuit can be found. */
|
||||||
|
origin_circuit_t *
|
||||||
|
hs_circ_service_get_intro_circ(const hs_service_intro_point_t *ip)
|
||||||
|
{
|
||||||
|
origin_circuit_t *circ = NULL;
|
||||||
|
|
||||||
|
tor_assert(ip);
|
||||||
|
|
||||||
|
if (ip->base.is_only_legacy) {
|
||||||
|
uint8_t digest[DIGEST_LEN];
|
||||||
|
if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
circ = hs_circuitmap_get_intro_circ_v2_service_side(digest);
|
||||||
|
} else {
|
||||||
|
circ = hs_circuitmap_get_intro_circ_v3_service_side(
|
||||||
|
&ip->auth_key_kp.pubkey);
|
||||||
|
}
|
||||||
|
end:
|
||||||
|
return circ;
|
||||||
|
}
|
||||||
|
|
||||||
/* Called when we fail building a rendezvous circuit at some point other than
|
/* Called when we fail building a rendezvous circuit at some point other than
|
||||||
* the last hop: launches a new circuit to the same rendezvous point. This
|
* the last hop: launches a new circuit to the same rendezvous point. This
|
||||||
* supports legacy service. */
|
* supports legacy service. */
|
||||||
|
@ -30,6 +30,9 @@ int hs_circ_launch_rendezvous_point(const hs_service_t *service,
|
|||||||
const uint8_t *rendezvous_cookie);
|
const uint8_t *rendezvous_cookie);
|
||||||
void hs_circ_retry_service_rendezvous_point(origin_circuit_t *circ);
|
void hs_circ_retry_service_rendezvous_point(origin_circuit_t *circ);
|
||||||
|
|
||||||
|
origin_circuit_t *hs_circ_service_get_intro_circ(
|
||||||
|
const hs_service_intro_point_t *ip);
|
||||||
|
|
||||||
/* Cell API. */
|
/* Cell API. */
|
||||||
int hs_circ_handle_intro_established(const hs_service_t *service,
|
int hs_circ_handle_intro_established(const hs_service_t *service,
|
||||||
const hs_service_intro_point_t *ip,
|
const hs_service_intro_point_t *ip,
|
||||||
|
@ -578,29 +578,6 @@ get_extend_info_from_intro_point(const hs_service_intro_point_t *ip,
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return an introduction point circuit matching the given intro point object.
|
|
||||||
* NULL is returned is no such circuit can be found. */
|
|
||||||
static origin_circuit_t *
|
|
||||||
get_intro_circuit(const hs_service_intro_point_t *ip)
|
|
||||||
{
|
|
||||||
origin_circuit_t *circ = NULL;
|
|
||||||
|
|
||||||
tor_assert(ip);
|
|
||||||
|
|
||||||
if (ip->base.is_only_legacy) {
|
|
||||||
uint8_t digest[DIGEST_LEN];
|
|
||||||
if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
circ = hs_circuitmap_get_intro_circ_v2_service_side(digest);
|
|
||||||
} else {
|
|
||||||
circ = hs_circuitmap_get_intro_circ_v3_service_side(
|
|
||||||
&ip->auth_key_kp.pubkey);
|
|
||||||
}
|
|
||||||
end:
|
|
||||||
return circ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the number of introduction points that are established for the
|
/* Return the number of introduction points that are established for the
|
||||||
* given descriptor. */
|
* given descriptor. */
|
||||||
static unsigned int
|
static unsigned int
|
||||||
@ -656,7 +633,7 @@ close_intro_circuits(hs_service_intropoints_t *intro_points)
|
|||||||
|
|
||||||
DIGEST256MAP_FOREACH(intro_points->map, key,
|
DIGEST256MAP_FOREACH(intro_points->map, key,
|
||||||
const hs_service_intro_point_t *, ip) {
|
const hs_service_intro_point_t *, ip) {
|
||||||
origin_circuit_t *ocirc = get_intro_circuit(ip);
|
origin_circuit_t *ocirc = hs_circ_service_get_intro_circ(ip);
|
||||||
if (ocirc) {
|
if (ocirc) {
|
||||||
/* Reason is FINISHED because service has been removed and thus the
|
/* Reason is FINISHED because service has been removed and thus the
|
||||||
* circuit is considered old/uneeded. When freed, the circuit is removed
|
* circuit is considered old/uneeded. When freed, the circuit is removed
|
||||||
@ -1587,7 +1564,7 @@ cleanup_intro_points(hs_service_t *service, time_t now)
|
|||||||
DIGEST256MAP_FOREACH_MODIFY(desc->intro_points.map, key,
|
DIGEST256MAP_FOREACH_MODIFY(desc->intro_points.map, key,
|
||||||
hs_service_intro_point_t *, ip) {
|
hs_service_intro_point_t *, ip) {
|
||||||
const node_t *node = get_node_from_intro_point(ip);
|
const node_t *node = get_node_from_intro_point(ip);
|
||||||
origin_circuit_t *ocirc = get_intro_circuit(ip);
|
origin_circuit_t *ocirc = hs_circ_service_get_intro_circ(ip);
|
||||||
int has_expired = intro_point_should_expire(ip, now);
|
int has_expired = intro_point_should_expire(ip, now);
|
||||||
|
|
||||||
/* We cleanup an intro point if it has expired or if we do not know the
|
/* We cleanup an intro point if it has expired or if we do not know the
|
||||||
@ -1733,7 +1710,7 @@ launch_intro_point_circuits(hs_service_t *service, time_t now)
|
|||||||
|
|
||||||
/* Skip the intro point that already has an existing circuit
|
/* Skip the intro point that already has an existing circuit
|
||||||
* (established or not). */
|
* (established or not). */
|
||||||
if (get_intro_circuit(ip)) {
|
if (hs_circ_service_get_intro_circ(ip)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user