Merge branch 'retry_rend' into 'main'

hss: Retry rendezvous circuit attempts.

Closes #1013

See merge request tpo/core/arti!1547
This commit is contained in:
Nick Mathewson 2023-08-24 19:41:39 +00:00
commit 2ad87bfc0c
5 changed files with 30 additions and 8 deletions

1
Cargo.lock generated
View File

@ -4639,6 +4639,7 @@ dependencies = [
"postage",
"rand 0.8.5",
"rand_core 0.6.4",
"retry-error",
"safelog",
"serde",
"serde_json",

View File

@ -35,6 +35,7 @@ once_cell = "1"
postage = { version = "0.5.0", default-features = false, features = ["futures-traits"] }
rand = "0.8.5"
rand_core = "0.6.2"
retry-error = { version = "0.5.0", path = "../retry-error" }
safelog = { path = "../safelog", version = "0.3.3" }
serde = { version = "1.0.103", features = ["derive"] }
thiserror = "1"

View File

@ -5,6 +5,7 @@
use std::sync::Arc;
use futures::{stream::BoxStream, StreamExt as _};
use retry_error::RetryError;
use tor_cell::relaycell::{
hs::intro_payload::{IntroduceHandshakePayload, OnionKey},
msg::{Introduce2, Rendezvous1},
@ -59,9 +60,9 @@ pub(crate) enum EstablishSessionError {
/// Got an onion key with an unrecognized type (not ntor).
#[error("Received an unsupported type of onion key")]
UnsupportedOnionKey,
/// Encountered an error while trying to build a circuit to the rendezvous point.
/// Unable to build a circuit to the rendezvous point.
#[error("Could not establish circuit to rendezvous point")]
RendCirc(#[source] tor_circmgr::Error),
RendCirc(#[source] RetryError<tor_circmgr::Error>),
/// Encountered a failure while trying to add a virtual hop to the circuit.
#[error("Could not add virtual hop to circuit")]
VirtualHop(#[source] tor_proto::Error),
@ -226,13 +227,30 @@ impl IntroRequest {
)
};
let max_n_attempts = netdir.params().hs_service_rendezvous_failures_max;
let mut circuit = None;
let mut retry_err: RetryError<tor_circmgr::Error> =
RetryError::in_attempt_to("Establish a circuit to a rendezvous point");
// Open circuit to rendezvous point.
let circuit = hs_pool
.get_or_launch_specific(&netdir, HsCircKind::SvcRend, rend_point)
.await
.map_err(E::RendCirc)?;
// TODO HSS: Maybe we should retry a couple of time if the failure is not
// the fault of the rend_point?
for _attempt in 1..=max_n_attempts.into() {
match hs_pool
.get_or_launch_specific(&netdir, HsCircKind::SvcRend, rend_point.clone())
.await
{
Ok(circ) => {
circuit = Some(circ);
break;
}
Err(e) => {
retry_err.push(e);
// Note that we do not sleep on errors: if there is any
// error that will be solved by waiting, it would probably
// require waiting too long to satisfy the client.
}
}
}
let circuit = circuit.ok_or_else(|| E::RendCirc(retry_err))?;
// We'll need parameters to extend the virtual hop.
let params = circparameters_from_netparameters(netdir.params());

View File

@ -1 +1,2 @@
ADDED: OwnedChanTargetBuilder::from_encoded_linkspecs
ADDED: Clone and Debug for VerbatimLinkSpecCircTarget

View File

@ -9,6 +9,7 @@ use crate::{ChanTarget, CircTarget, EncodedLinkSpec, HasAddrs, HasChanMethod, Ha
/// Onion services and their clients use this type of target when telling a
/// relay to extend a circuit to a target relay (an introduction point or
/// rendezvous point) chosen by some other party.
#[derive(Clone, Debug)]
pub struct VerbatimLinkSpecCircTarget<T> {
/// The underlying CircTarget
target: T,