struct Context<'c, R: Runtime, M: MocksForConnect<R>> {
runtime: &'c R,
circpool: &'c M::HsCircPool,
netdir: Arc<NetDir>,
config: Arc<Config>,
secret_keys: HsClientSecretKeys,
hsid: HsId,
hs_blind_id: HsBlindId,
subcredential: Subcredential,
mocks: M,
}
Expand description
Common context for a single request to connect to a hidden service
This saves on passing this same set of (immutable) values (or subsets thereof)
to each method in the principal functional code, everywhere.
It also provides a convenient type to be Self
.
Its lifetime is one request to make a new client circuit to a hidden service, including all the retries and timeouts.
Fields§
§runtime: &'c R
Runtime
circpool: &'c M::HsCircPool
Circpool
netdir: Arc<NetDir>
Netdir
config: Arc<Config>
Configuration
secret_keys: HsClientSecretKeys
Secret keys to use
hsid: HsId
HS ID
hs_blind_id: HsBlindId
Blinded HS ID
subcredential: Subcredential
The subcredential to use during this time period
mocks: M
Mock data
Implementations§
Source§impl<'c, R: Runtime, M: MocksForConnect<R>> Context<'c, R, M>
impl<'c, R: Runtime, M: MocksForConnect<R>> Context<'c, R, M>
Sourcefn new(
runtime: &'c R,
circpool: &'c M::HsCircPool,
netdir: Arc<NetDir>,
config: Arc<Config>,
hsid: HsId,
secret_keys: HsClientSecretKeys,
mocks: M,
) -> Result<Self, ConnError>
fn new( runtime: &'c R, circpool: &'c M::HsCircPool, netdir: Arc<NetDir>, config: Arc<Config>, hsid: HsId, secret_keys: HsClientSecretKeys, mocks: M, ) -> Result<Self, ConnError>
Make a new Context
from the input data
Sourceasync fn connect(
&self,
data: &mut Data,
) -> Result<Arc<<<M as MocksForConnect<R>>::HsCircPool as MockableCircPool<R>>::ClientCirc>, ConnError>
async fn connect( &self, data: &mut Data, ) -> Result<Arc<<<M as MocksForConnect<R>>::HsCircPool as MockableCircPool<R>>::ClientCirc>, ConnError>
Actually make a HS connection, updating our recorded state as necessary
Called by the connect
function in this module.
This function handles all necessary retrying of fallible operations, (and, therefore, must also limit the total work done for a particular call).
Sourceasync fn descriptor_ensure<'d>(
&self,
data: &'d mut Option<TimerangeBound<HsDesc>>,
) -> Result<&'d HsDesc, CE>
async fn descriptor_ensure<'d>( &self, data: &'d mut Option<TimerangeBound<HsDesc>>, ) -> Result<&'d HsDesc, CE>
Ensure that Data.desc
contains the HS descriptor
If we have a previously-downloaded descriptor, which is still valid, just returns a reference to it.
Otherwise, tries to obtain the descriptor by downloading it from hsdir(s).
Does all necessary retries and timeouts. Returns an error if no valid descriptor could be found.
Sourceasync fn descriptor_fetch_attempt(
&self,
hsdir: &Relay<'_>,
) -> Result<TimerangeBound<HsDesc>, DescriptorErrorDetail>
async fn descriptor_fetch_attempt( &self, hsdir: &Relay<'_>, ) -> Result<TimerangeBound<HsDesc>, DescriptorErrorDetail>
Make one attempt to fetch the descriptor from a specific hsdir
No timeout
On success, returns the descriptor.
While the returned descriptor is TimerangeBound
, its validity at the current time has
been checked.
Sourceasync fn intro_rend_connect(
&self,
desc: &HsDesc,
data: &mut HashMap<RelayIdForExperience, IptExperience>,
) -> Result<Arc<<<M as MocksForConnect<R>>::HsCircPool as MockableCircPool<R>>::ClientCirc>, CE>
async fn intro_rend_connect( &self, desc: &HsDesc, data: &mut HashMap<RelayIdForExperience, IptExperience>, ) -> Result<Arc<<<M as MocksForConnect<R>>::HsCircPool as MockableCircPool<R>>::ClientCirc>, CE>
Given the descriptor, try to connect to service
Does all necessary retries, timeouts, etc.
Sourceasync fn establish_rendezvous(
&'c self,
using_rend_pt: &mut Option<Redacted<RelayIds>>,
) -> Result<Rendezvous<'c, R, M>, FAE>
async fn establish_rendezvous( &'c self, using_rend_pt: &mut Option<Redacted<RelayIds>>, ) -> Result<Rendezvous<'c, R, M>, FAE>
Make one attempt to establish a rendezvous circuit
This doesn’t really depend on anything, other than (obviously) the isolation implied by our circuit pool. In particular it doesn’t depend on the introduction point.
Does not apply a timeout.
On entry using_rend_pt
is None
.
This function will store Some
when it finds out which relay
it is talking to and starts to converse with it.
That way, if a timeout occurs, the caller can add that information to the error.
Sourceasync fn exchange_introduce(
&'c self,
ipt: &UsableIntroPt<'_>,
rendezvous: &mut Option<Rendezvous<'c, R, M>>,
proof_of_work: Option<ProofOfWork>,
) -> Result<(Rendezvous<'c, R, M>, Introduced<R, M>), FAE>
async fn exchange_introduce( &'c self, ipt: &UsableIntroPt<'_>, rendezvous: &mut Option<Rendezvous<'c, R, M>>, proof_of_work: Option<ProofOfWork>, ) -> Result<(Rendezvous<'c, R, M>, Introduced<R, M>), FAE>
Attempt (once) to send an INTRODUCE1 and wait for the INTRODUCE_ACK
take
s the input rendezvous
(but only takes it if it gets that far)
and, if successful, returns it.
(This arranges that the rendezvous is “used up” precisely if
we sent its secret somewhere.)
Although this function handles the Rendezvous
,
nothing in it actually involves the rendezvous point.
So if there’s a failure, it’s purely to do with the introduction point.
Does not apply a timeout.
Sourceasync fn complete_rendezvous(
&'c self,
ipt: &UsableIntroPt<'_>,
rendezvous: Rendezvous<'c, R, M>,
introduced: Introduced<R, M>,
) -> Result<Arc<<<M as MocksForConnect<R>>::HsCircPool as MockableCircPool<R>>::ClientCirc>, FAE>
async fn complete_rendezvous( &'c self, ipt: &UsableIntroPt<'_>, rendezvous: Rendezvous<'c, R, M>, introduced: Introduced<R, M>, ) -> Result<Arc<<<M as MocksForConnect<R>>::HsCircPool as MockableCircPool<R>>::ClientCirc>, FAE>
Attempt (once) to connect a rendezvous circuit using the given intro pt
Timeouts here might be due to the IPT, RPT, service, or any of the intermediate relays.
If, rather than a timeout, we actually encounter some kind of error,
we’ll return the appropriate FailedAttemptError
.
(Who is responsible may vary, so the FailedAttemptError
variant will reflect that.)
Does not apply a timeout
Sourcefn estimate_timeout(&self, actions: &[(u32, TimeoutsAction)]) -> Duration
fn estimate_timeout(&self, actions: &[(u32, TimeoutsAction)]) -> Duration
Helper to estimate a timeout for a complicated operation
actions
is a list of (count, action)
, where each entry
represents doing action
, count
times sequentially.
Combines the timeout estimates and returns an overall timeout.
Auto Trait Implementations§
impl<'c, R, M> Freeze for Context<'c, R, M>where
M: Freeze,
impl<'c, R, M> RefUnwindSafe for Context<'c, R, M>
impl<'c, R, M> Send for Context<'c, R, M>
impl<'c, R, M> Sync for Context<'c, R, M>
impl<'c, R, M> Unpin for Context<'c, R, M>where
M: Unpin,
impl<'c, R, M> UnwindSafe for Context<'c, R, M>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.