Struct GuardMgrInner

Source
pub(crate) struct GuardMgrInner {
Show 14 fields pub(crate) last_primary_retry_time: Instant, pub(crate) guards: GuardSets, pub(crate) filter: GuardFilter, pub(crate) params: GuardParams, pub(crate) ctrl: UnboundedSender<Msg>, pub(crate) pending: HashMap<RequestId, PendingRequest>, pub(crate) waiting: Vec<PendingRequest>, pub(crate) fallbacks: FallbackState, pub(crate) storage: DynStorageHandle<GuardSets>, pub(crate) send_skew: Sender<Option<SkewEstimate>>, pub(crate) recv_skew: ClockSkewEvents, pub(crate) netdir_provider: Option<Weak<dyn NetDirProvider>>, pub(crate) bridge_desc_provider: Option<Weak<dyn BridgeDescProvider>>, pub(crate) configured_bridges: Option<Arc<[BridgeConfig]>>,
}
Expand description

Helper type that holds the data used by a GuardMgr.

This would just be a GuardMgr, except that it needs to sit inside a Mutex and get accessed by daemon tasks.

Fields§

§last_primary_retry_time: Instant

Last time when marked all of our primary guards as retriable.

We keep track of this time so that we can rate-limit these attempts.

§guards: GuardSets

Persistent guard manager state.

This object remembers one or more persistent set of guards that we can use, along with their relative priorities and statuses.

§filter: GuardFilter

The current filter that we’re using to decide which guards are supported.

§params: GuardParams

Configuration values derived from the consensus parameters.

This is updated whenever the consensus parameters change.

§ctrl: UnboundedSender<Msg>

A mpsc channel, used to tell the task running in daemon::report_status_events about a new event to monitor.

This uses an UnboundedSender so that we don’t have to await while sending the message, which in turn allows the GuardMgr API to be simpler. The risk, however, is that there’s no backpressure in the event that the task running daemon::report_status_events fails to read from this channel.

§pending: HashMap<RequestId, PendingRequest>

Information about guards that we’ve given out, but where we have not yet heard whether the guard was successful.

Upon leaning whether the guard was successful, the pending requests in this map may be either moved to waiting, or discarded.

There can be multiple pending requests corresponding to the same guard.

§waiting: Vec<PendingRequest>

A list of pending requests for which we have heard that the guard was successful, but we have not yet decided whether the circuit may be used.

There can be multiple waiting requests corresponding to the same guard.

§fallbacks: FallbackState

A list of fallback directories used to access the directory system when no other directory information is yet known.

§storage: DynStorageHandle<GuardSets>

Location in which to store persistent state.

§send_skew: Sender<Option<SkewEstimate>>

A sender object to publish changes in our estimated clock skew.

§recv_skew: ClockSkewEvents

A receiver object to hand out to observers who want to know about changes in our estimated clock skew.

§netdir_provider: Option<Weak<dyn NetDirProvider>>

A netdir provider that we can use for adding new guards when insufficient guards are available.

This has to be an Option so it can be initialized from None: at the time a GuardMgr is created, there is no NetDirProvider for it to use.

§bridge_desc_provider: Option<Weak<dyn BridgeDescProvider>>
Available on crate feature bridge-client only.

A netdir provider that we can use for discovering bridge descriptors.

This has to be an Option so it can be initialized from None: at the time a GuardMgr is created, there is no BridgeDescProvider for it to use.

§configured_bridges: Option<Arc<[BridgeConfig]>>
Available on crate feature bridge-client only.

A list of the bridges that we are configured to use, or “None” if we are not configured to use bridges.

Implementations§

Source§

impl GuardMgrInner

Source

pub(crate) fn timely_netdir(&self) -> Option<Arc<NetDir>>

Look up the latest NetDir (if there is one) from our NetDirProvider (if we have one).

Source

pub(crate) fn latest_bridge_desc_list(&self) -> Option<Arc<BridgeDescList>>

Available on crate feature bridge-client only.

Look up the latest BridgeDescList (if there is one) from our BridgeDescProvider (if we have one).

Source

pub(crate) fn with_opt_netdir<F, T>(&mut self, func: F) -> T
where F: FnOnce(&mut Self, Option<&NetDir>) -> T,

Run a function that takes &mut self and an optional NetDir.

We try to use the netdir from our NetDirProvider (if we have one). Therefore, although its parameters are suitable for every GuardSet, its contents might not be. For those, call with_opt_universe instead.

Source

pub(crate) fn latest_bridge_set(&self) -> Option<BridgeSet>

Available on crate feature bridge-client only.

Return the latest BridgeSet based on our BridgeDescProvider and our configured bridges.

Returns None if we are not configured to use bridges.

Source

pub(crate) fn with_opt_universe<F, T>(&mut self, func: F) -> T
where F: FnOnce(&mut Self, Option<&UniverseRef>) -> T,

Run a function that takes &mut self and an optional UniverseRef.

We try to get a universe from the appropriate source for the current active guard set.

Source

pub(crate) fn update(&mut self, wallclock: SystemTime, now: Instant)

Update the status of all guards in the active set, based on the passage of time, our configuration, and the relevant Universe for our active set.

Source

pub(crate) fn replace_bridge_config( &mut self, new_config: &impl GuardMgrConfig, wallclock: SystemTime, now: Instant, ) -> Result<RetireCircuits, GuardMgrConfigError>

Available on crate feature bridge-client only.

Replace our bridge configuration with the one from new_config.

Source

pub(crate) fn update_active_set_params_and_filter( &mut self, netdir: Option<&NetDir>, )

Update our parameters, our selection (based on network parameters and configuration), and make sure the active GuardSet has the right configuration itself.

We should call this whenever the NetDir’s parameters change, or whenever our filter changes. We do not need to call it for new elements arriving in our Universe, since those do not affect anything here.

We should also call this whenever a new GuardSet becomes active for any reason other than just having called this function.

(This function is only invoked from update, which should be called under the above circumstances.)

Source

pub(crate) fn update_guardset_internal<U: Universe>( params: &GuardParams, now: SystemTime, universe_type: UniverseType, active_guards: &mut GuardSet, universe: Option<&U>, ) -> ExtendedStatus

Update the status of every guard in active_guards, and expand it as needed.

This function doesn’t take &self, to make sure that we are only affecting a single GuardSet, and to avoid confusing the borrow checker.

We should call this whenever the contents of the universe have changed.

We should also call this whenever a new GuardSet becomes active.

Source

pub(crate) fn update_desired_descriptors(&mut self, now: Instant)

Available on crate feature bridge-client only.

If using bridges, tell the BridgeDescProvider which descriptors we want. We need to check this after we select our primary guards.

Source

pub(crate) fn replace_guards_with( &mut self, new_guards: GuardSets, wallclock: SystemTime, now: Instant, )

Replace the active guard state with new_state, preserving non-persistent state for any guards that are retained.

Source

pub(crate) fn select_guard_set_based_on_filter(&mut self, netdir: &NetDir)

Update which guard set is active based on the current filter and the provided netdir.

After calling this function, the new guard set’s filter may be out-of-date: be sure to call set_filter as appropriate.

Source

pub(crate) fn maybe_retry_primary_guards(&mut self, now: Instant)

Mark all of our primary guards as retriable, if we haven’t done so since long enough before now.

We want to call this function whenever a guard attempt succeeds, if the internet seemed to be down when the guard attempt was first launched.

Source

pub(crate) fn set_filter( &mut self, filter: GuardFilter, wallclock: SystemTime, now: Instant, )

Replace the current GuardFilter with filter.

Source

pub(crate) fn handle_msg( &mut self, request_id: RequestId, status: GuardStatus, skew: Option<ClockSkew>, runtime: &impl SleepProvider, )

Called when the circuit manager reports (via GuardMonitor) that a guard succeeded or failed.

Changes the guard’s status as appropriate, and updates the pending request as needed.

Source

pub(crate) fn record_external_success<T>( &mut self, identity: &T, external_activity: ExternalActivity, now: SystemTime, )
where T: HasRelayIds + ?Sized,

Helper to implement GuardMgr::note_external_success().

(This has to be a separate function so that we can borrow params while we have mut self borrowed.)

Source

pub(crate) fn skew_observations(&self) -> impl Iterator<Item = &SkewObservation>

Return an iterator over all of the clock skew observations we’ve made for guards or fallbacks.

Source

pub(crate) fn update_skew(&mut self, now: Instant)

Recalculate our estimated clock skew, and publish it to anybody who cares.

Source

pub(crate) fn guard_usability_status( &self, pending: &PendingRequest, now: Instant, ) -> Option<bool>

If the circuit built because of a given PendingRequest may now be used (or discarded), return Some(true) or Some(false) respectively.

Return None if we can’t yet give an answer about whether such a circuit is usable.

Source

pub(crate) fn expire_and_answer_pending_requests(&mut self, now: Instant)

For requests that have been “waiting” for an answer for too long, expire them and tell the circuit manager that their circuits are unusable.

Source

pub(crate) fn lookup_ids<T>(&self, identity: &T) -> Vec<FirstHopId>
where T: HasRelayIds + ?Sized,

Return every currently extant FirstHopId for a guard or fallback directory matching (or possibly matching) the provided keys.

An identity is possibly matching if it contains some of the IDs in the provided identity, and it has no contradictory identities, but it does not necessarily contain all of those identities.

§TODO

This function should probably not exist; it’s only used so that dirmgr can report successes or failures, since by the time it observes them it doesn’t know whether its circuit came from a guard or a fallback. To solve that, we’ll need CircMgr to record and report which one it was using, which will take some more plumbing.

TODO relay: we will have to make the change above when we implement relays; otherwise, it would be possible for an attacker to exploit it to mislead us about our guard status.

Source

pub(crate) fn run_periodic_events( &mut self, wallclock: SystemTime, now: Instant, ) -> Duration

Run any periodic events that update guard status, and return a duration after which periodic events should next be run.

Source

pub(crate) fn select_guard_with_expand( &mut self, usage: &GuardUsage, now: Instant, wallclock: SystemTime, ) -> Result<(ListKind, FirstHop), PickGuardError>

Try to select a guard, expanding the sample if the first attempt fails.

Source

pub(crate) fn select_guard_once( &self, usage: &GuardUsage, now: Instant, ) -> Result<(ListKind, FirstHop), PickGuardError>

Helper: try to pick a single guard, without retrying on failure.

Source

pub(crate) fn select_fallback( &self, now: Instant, ) -> Result<(ListKind, FirstHop), PickGuardError>

Helper: Select a fallback directory.

Called when we have no guard information to use. Return values are as for GuardMgr::select_guard()

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows 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) -> R
where R: 'a,

Mutably borrows 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
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T