mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
prop224: Move and refactor rend_client_reextend_intro_circuit()
This moves it to hs_client.c so it can be used by both system (legacy and prop224). For now, only the legacy system uses it. Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
88f64eee68
commit
88b843608a
3 changed files with 49 additions and 42 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "circpathbias.h"
|
||||
#include "connection.h"
|
||||
#include "hs_ntor.h"
|
||||
#include "circuitbuild.h"
|
||||
|
||||
/* Get all connections that are waiting on a circuit and flag them back to
|
||||
* waiting for a hidden service descriptor for the given service key
|
||||
|
@ -977,3 +978,46 @@ hs_client_receive_rendezvous2(origin_circuit_t *circ,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* Extend the introduction circuit circ to another valid introduction point
|
||||
* for the hidden service it is trying to connect to, or mark it and launch a
|
||||
* new circuit if we can't extend it. Return 0 on success or possible
|
||||
* success. Return -1 and mark the introduction circuit for close on permanent
|
||||
* failure.
|
||||
*
|
||||
* On failure, the caller is responsible for marking the associated rendezvous
|
||||
* circuit for close. */
|
||||
int
|
||||
hs_client_reextend_intro_circuit(origin_circuit_t *circ)
|
||||
{
|
||||
int ret = -1;
|
||||
extend_info_t *ei;
|
||||
|
||||
tor_assert(circ);
|
||||
|
||||
ei = (circ->hs_ident) ?
|
||||
client_get_random_intro(&circ->hs_ident->identity_pk) :
|
||||
rend_client_get_random_intro(circ->rend_data);
|
||||
if (ei == NULL) {
|
||||
log_warn(LD_REND, "No usable introduction points left. Closing.");
|
||||
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (circ->remaining_relay_early_cells) {
|
||||
log_info(LD_REND, "Re-extending circ %u, this time to %s.",
|
||||
(unsigned int) TO_CIRCUIT(circ)->n_circ_id,
|
||||
safe_str_client(extend_info_describe(ei)));
|
||||
ret = circuit_extend_to_new_exit(circ, ei);
|
||||
} else {
|
||||
log_info(LD_REND, "Closing intro circ %u (out of RELAY_EARLY cells).",
|
||||
(unsigned int) TO_CIRCUIT(circ)->n_circ_id);
|
||||
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
|
||||
/* connection_ap_handshake_attach_circuit will launch a new intro circ. */
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
end:
|
||||
extend_info_free(ei);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,5 +43,7 @@ void hs_client_desc_has_arrived(const hs_ident_dir_conn_t *ident);
|
|||
extend_info_t *hs_client_get_random_intro_from_edge(
|
||||
const edge_connection_t *edge_conn);
|
||||
|
||||
int hs_client_reextend_intro_circuit(origin_circuit_t *circ);
|
||||
|
||||
#endif /* TOR_HS_CLIENT_H */
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "directory.h"
|
||||
#include "hs_common.h"
|
||||
#include "hs_circuit.h"
|
||||
#include "hs_client.h"
|
||||
#include "main.h"
|
||||
#include "networkstatus.h"
|
||||
#include "nodelist.h"
|
||||
|
@ -89,46 +90,6 @@ rend_client_send_establish_rendezvous(origin_circuit_t *circ)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Extend the introduction circuit <b>circ</b> to another valid
|
||||
* introduction point for the hidden service it is trying to connect
|
||||
* to, or mark it and launch a new circuit if we can't extend it.
|
||||
* Return 0 on success or possible success. Return -1 and mark the
|
||||
* introduction circuit for close on permanent failure.
|
||||
*
|
||||
* On failure, the caller is responsible for marking the associated
|
||||
* rendezvous circuit for close. */
|
||||
static int
|
||||
rend_client_reextend_intro_circuit(origin_circuit_t *circ)
|
||||
{
|
||||
extend_info_t *extend_info;
|
||||
int result;
|
||||
extend_info = rend_client_get_random_intro(circ->rend_data);
|
||||
if (!extend_info) {
|
||||
log_warn(LD_REND,
|
||||
"No usable introduction points left for %s. Closing.",
|
||||
safe_str_client(rend_data_get_address(circ->rend_data)));
|
||||
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
|
||||
return -1;
|
||||
}
|
||||
// XXX: should we not re-extend if hs_circ_has_timed_out?
|
||||
if (circ->remaining_relay_early_cells) {
|
||||
log_info(LD_REND,
|
||||
"Re-extending circ %u, this time to %s.",
|
||||
(unsigned)circ->base_.n_circ_id,
|
||||
safe_str_client(extend_info_describe(extend_info)));
|
||||
result = circuit_extend_to_new_exit(circ, extend_info);
|
||||
} else {
|
||||
log_info(LD_REND,
|
||||
"Closing intro circ %u (out of RELAY_EARLY cells).",
|
||||
(unsigned)circ->base_.n_circ_id);
|
||||
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
|
||||
/* connection_ap_handshake_attach_circuit will launch a new intro circ. */
|
||||
result = 0;
|
||||
}
|
||||
extend_info_free(extend_info);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Called when we're trying to connect an ap conn; sends an INTRODUCE1 cell
|
||||
* down introcirc if possible.
|
||||
*/
|
||||
|
@ -202,7 +163,7 @@ rend_client_send_introduction(origin_circuit_t *introcirc,
|
|||
introcirc->build_state->chosen_exit)),
|
||||
smartlist_len(entry->parsed->intro_nodes));
|
||||
|
||||
if (rend_client_reextend_intro_circuit(introcirc)) {
|
||||
if (hs_client_reextend_intro_circuit(introcirc)) {
|
||||
status = -2;
|
||||
goto perm_err;
|
||||
} else {
|
||||
|
@ -437,7 +398,7 @@ rend_client_introduction_acked(origin_circuit_t *circ,
|
|||
INTRO_POINT_FAILURE_GENERIC)>0) {
|
||||
/* There are introduction points left. Re-extend the circuit to
|
||||
* another intro point and try again. */
|
||||
int result = rend_client_reextend_intro_circuit(circ);
|
||||
int result = hs_client_reextend_intro_circuit(circ);
|
||||
/* XXXX If that call failed, should we close the rend circuit,
|
||||
* too? */
|
||||
return result;
|
||||
|
|
Loading…
Add table
Reference in a new issue