ipt establisher API: pass a struct to new()

Now new() only has a reasonable number of arguments and removes some
repetition in the mocking arrangements in the IPT Manager.

This is the minimum amount that needs to be done in the commit that
touches both the IPT Establisher and the Manager.
This commit is contained in:
Ian Jackson 2023-08-23 12:45:16 +01:00
parent 7d6f5531ce
commit 0cf3243260
2 changed files with 47 additions and 20 deletions

View File

@ -32,7 +32,7 @@ use tor_rtcompat::Runtime;
use crate::svc::ipt_establish; use crate::svc::ipt_establish;
use crate::timeout_track::{TrackingInstantOffsetNow, TrackingNow}; use crate::timeout_track::{TrackingInstantOffsetNow, TrackingNow};
use crate::{FatalError, OnionServiceConfig, RendRequest, StartupError}; use crate::{FatalError, OnionServiceConfig, RendRequest, StartupError};
use ipt_establish::{IptEstablisher, IptStatus, IptStatusStatus, IptWantsToRetire}; use ipt_establish::{IptEstablisher, IptParameters, IptStatus, IptStatusStatus, IptWantsToRetire};
use IptStatusStatus as ISS; use IptStatusStatus as ISS;
use TrackedStatus as TS; use TrackedStatus as TS;
@ -305,12 +305,22 @@ impl IptRelay {
/// Make a new introduction point at this relay /// Make a new introduction point at this relay
/// ///
/// It becomes the current IPT. /// It becomes the current IPT.
#[allow(unreachable_code, clippy::diverging_sub_expression)] // TODO HSS remove
fn make_new_ipt<R: Runtime, M: Mockable<R>>( fn make_new_ipt<R: Runtime, M: Mockable<R>>(
&mut self, &mut self,
imm: &Immutable<R>, imm: &Immutable<R>,
mockable: &mut M, mockable: &mut M,
) -> Result<(), FatalError> { ) -> Result<(), FatalError> {
let (establisher, mut watch_rx) = mockable.make_new_ipt(imm, self.relay.clone())?; let params = IptParameters {
netdir_provider: imm.dirprovider.clone(),
introduce_tx: imm.output_rend_reqs.clone(),
// TODO HSS IntroPointId lacks a constructor and maybe should change anyway
intro_pt_id: todo!(),
target: self.relay.clone(),
ipt_sid_keypair: todo!(), // TODO HSS
accepting_requests: todo!(), // TODO HSS
};
let (establisher, mut watch_rx) = mockable.make_new_ipt(imm, params)?;
// we'll treat it as Establishing until we find otherwise // we'll treat it as Establishing until we find otherwise
let status_last = TS::Establishing { let status_last = TS::Establishing {
@ -735,7 +745,7 @@ pub(crate) trait Mockable<R>: Debug + Send + Sync + Sized + 'static {
fn make_new_ipt( fn make_new_ipt(
&mut self, &mut self,
imm: &Immutable<R>, imm: &Immutable<R>,
relay: RelayIds, params: IptParameters,
) -> Result<(Self::IptEstablisher, watch::Receiver<IptStatus>), FatalError>; ) -> Result<(Self::IptEstablisher, watch::Receiver<IptStatus>), FatalError>;
/// Call `Publisher::new_intro_points` /// Call `Publisher::new_intro_points`
@ -755,21 +765,15 @@ impl<R: Runtime> Mockable<R> for Real<R> {
rand::thread_rng() rand::thread_rng()
} }
#[allow(unreachable_code)] // TODO HSS remove
fn make_new_ipt( fn make_new_ipt(
&mut self, &mut self,
imm: &Immutable<R>, imm: &Immutable<R>,
relay: RelayIds, params: IptParameters,
) -> Result<(Self::IptEstablisher, watch::Receiver<IptStatus>), FatalError> { ) -> Result<(Self::IptEstablisher, watch::Receiver<IptStatus>), FatalError> {
IptEstablisher::new( IptEstablisher::new(
imm.runtime.clone(), imm.runtime.clone(),
params,
self.circ_pool.clone(), self.circ_pool.clone(),
imm.dirprovider.clone(),
imm.output_rend_reqs.clone(),
todo!(), // TODO HSS IntroPointId lacks a constructor and maybe should change anyway
relay,
todo!(), // TODO HSS keypair ought to be provided by our caller
todo!(), // TODO HSS RequestDisposition ought to be provided by our caller
) )
} }
} }

View File

@ -151,6 +151,27 @@ impl IptError {
} }
} }
/// Parameters for an introduction point
///
/// Consumed by `IptEstablisher::new`.
/// Primarily serves as a convenient way to bundle the many arguments required.
///
/// Does not include:
/// * The runtime (which would force this struct to have a type parameter)
/// * The circuit builder (leaving this out makes it possible to use this
/// struct during mock execution, where we don't call `IptEstablisher::new`).
#[allow(clippy::missing_docs_in_private_items)] // TODO HSS document these and remove
pub(crate) struct IptParameters {
pub(crate) netdir_provider: Arc<dyn NetDirProvider>,
pub(crate) introduce_tx: mpsc::Sender<RendRequest>,
pub(crate) intro_pt_id: IntroPointId,
// TODO HSS: Should this and the following elements be part of some
// configuration object?
pub(crate) target: RelayIds,
pub(crate) ipt_sid_keypair: HsIntroPtSessionIdKeypair,
pub(crate) accepting_requests: RequestDisposition,
}
impl IptEstablisher { impl IptEstablisher {
/// Try to set up, and maintain, an IPT at `target`. /// Try to set up, and maintain, an IPT at `target`.
/// ///
@ -165,19 +186,21 @@ impl IptEstablisher {
/// The returned `watch::Receiver` will yield `Faulty` if the IPT /// The returned `watch::Receiver` will yield `Faulty` if the IPT
/// establisher is shut down (or crashes). /// establisher is shut down (or crashes).
// TODO HSS rename to "launch" since it starts the task? // TODO HSS rename to "launch" since it starts the task?
#[allow(clippy::too_many_arguments)] // TODO HSS refactor.
pub(crate) fn new<R: Runtime>( pub(crate) fn new<R: Runtime>(
runtime: R, runtime: R,
params: IptParameters,
pool: Arc<HsCircPool<R>>, pool: Arc<HsCircPool<R>>,
netdir_provider: Arc<dyn NetDirProvider>,
introduce_tx: mpsc::Sender<RendRequest>,
intro_pt_id: IntroPointId,
// TODO HSS: Should this and the following elements be part of some
// configuration object?
target: RelayIds,
ipt_sid_keypair: HsIntroPtSessionIdKeypair,
accepting_requests: RequestDisposition,
) -> Result<(Self, postage::watch::Receiver<IptStatus>), FatalError> { ) -> Result<(Self, postage::watch::Receiver<IptStatus>), FatalError> {
// This exhaustive deconstruction ensures that we don't
// accidentally forget to handle any of our inputs.
let IptParameters {
netdir_provider,
introduce_tx,
intro_pt_id,
target,
ipt_sid_keypair,
accepting_requests,
} = params;
if matches!(accepting_requests, RequestDisposition::Shutdown) { if matches!(accepting_requests, RequestDisposition::Shutdown) {
return Err(bad_api_usage!( return Err(bad_api_usage!(
"Tried to create a IptEstablisher that that was already shutting down?" "Tried to create a IptEstablisher that that was already shutting down?"