pub struct VanguardMgr<R: Runtime> {
inner: RwLock<Inner>,
runtime: R,
storage: DynStorageHandle<VanguardSets>,
}
vanguards
only.Expand description
The vanguard manager.
Fields§
§inner: RwLock<Inner>
The mutable state.
runtime: R
The runtime.
storage: DynStorageHandle<VanguardSets>
The persistent storage handle, used for writing the vanguard sets to disk if full vanguards are enabled.
Implementations§
Source§impl<R: Runtime> VanguardMgr<R>
impl<R: Runtime> VanguardMgr<R>
Sourcepub fn new<S>(
config: &VanguardConfig,
runtime: R,
state_mgr: S,
has_onion_svc: bool,
) -> Result<Self, VanguardMgrError>
pub fn new<S>( config: &VanguardConfig, runtime: R, state_mgr: S, has_onion_svc: bool, ) -> Result<Self, VanguardMgrError>
Create a new VanguardMgr
.
The state_mgr
handle is used for persisting the “vanguards-full” guard pools to disk.
Sourcepub fn launch_background_tasks(
self: &Arc<Self>,
netdir_provider: &Arc<dyn NetDirProvider>,
) -> Result<(), VanguardMgrError>where
R: Runtime,
pub fn launch_background_tasks(
self: &Arc<Self>,
netdir_provider: &Arc<dyn NetDirProvider>,
) -> Result<(), VanguardMgrError>where
R: Runtime,
Launch the vanguard pool management tasks.
These run until the VanguardMgr
is dropped.
Sourcepub fn reconfigure(
&self,
config: &VanguardConfig,
) -> Result<RetireCircuits, ReconfigureError>
pub fn reconfigure( &self, config: &VanguardConfig, ) -> Result<RetireCircuits, ReconfigureError>
Replace the configuration in this VanguardMgr
with the specified config
.
Sourcepub fn select_vanguard<'a, Rng: RngCore>(
&self,
rng: &mut Rng,
netdir: &'a NetDir,
layer: Layer,
relay_selector: &RelaySelector<'a>,
) -> Result<Vanguard<'a>, VanguardMgrError>
pub fn select_vanguard<'a, Rng: RngCore>( &self, rng: &mut Rng, netdir: &'a NetDir, layer: Layer, relay_selector: &RelaySelector<'a>, ) -> Result<Vanguard<'a>, VanguardMgrError>
Return a Vanguard
relay for use in the specified layer.
The relay_selector
must exclude the relays that would neighbor this vanguard
in the path.
Specifically, it should exclude
- the last relay in the path (the one immediately preceding the vanguard): the same relay cannot be used in consecutive positions in the path (a relay won’t let you extend the circuit to itself).
- the penultimate relay of the path, if there is one: relays don’t allow extending the circuit to their previous hop
If Full
vanguards are in use, this function can be used
for selecting both Layer2
and Layer3
vanguards.
If Lite
vanguards are in use, this function can only be used
for selecting Layer2
vanguards.
It will return an error if a Layer3
is requested.
Returns an error if vanguards are disabled.
Returns a NoSuitableRelay
error
if none of our vanguards satisfy the layer
and neighbor_exlusion
requirements.
Returns a BootstrapRequired
error
if called before the vanguard manager has finished bootstrapping,
or if all the vanguards have become unusable
(by expiring or no longer being listed in the consensus)
and we are unable to replenish them.
§Example
If the partially built path is of the form G - L2
and we are selecting the L3 vanguard,
the RelayExclusion
should contain G
and L2
(to prevent building a path of the form
G - L2 - G
, or G - L2 - L2
).
If the path only contains the L1 guard (G
), then the RelayExclusion
should only
exclude G
.
Sourceasync fn maintain_vanguard_sets(
mgr: Weak<Self>,
netdir_provider: Weak<dyn NetDirProvider>,
config_rx: Receiver<VanguardConfig>,
)
async fn maintain_vanguard_sets( mgr: Weak<Self>, netdir_provider: Weak<dyn NetDirProvider>, config_rx: Receiver<VanguardConfig>, )
The vanguard set management task.
This is a background task that:
- removes vanguards from the L2 and L3 vanguard sets when they expire
- ensures the vanguard sets are repopulated with new vanguards when the number of vanguards drops below a certain threshold
- handles
NetDir
changes, updating the vanguard set sizes as needed
Sourceasync fn run_once(
mgr: Weak<Self>,
netdir_provider: Weak<dyn NetDirProvider>,
netdir_events: &mut BoxStream<'static, DirEvent>,
config_rx: &mut Receiver<VanguardConfig>,
) -> Result<ShutdownStatus, VanguardMgrError>
async fn run_once( mgr: Weak<Self>, netdir_provider: Weak<dyn NetDirProvider>, netdir_events: &mut BoxStream<'static, DirEvent>, config_rx: &mut Receiver<VanguardConfig>, ) -> Result<ShutdownStatus, VanguardMgrError>
Sourcefn timely_netdir(
netdir_provider: &Arc<dyn NetDirProvider>,
) -> Result<Option<Arc<NetDir>>, VanguardMgrError>
fn timely_netdir( netdir_provider: &Arc<dyn NetDirProvider>, ) -> Result<Option<Arc<NetDir>>, VanguardMgrError>
Return a timely NetDir
, if one is available.
Returns None
if no directory information is available.
Sourcefn rotate_expired(
&self,
netdir_provider: &Arc<dyn NetDirProvider>,
now: SystemTime,
) -> Result<Option<Duration>, VanguardMgrError>
fn rotate_expired( &self, netdir_provider: &Arc<dyn NetDirProvider>, now: SystemTime, ) -> Result<Option<Duration>, VanguardMgrError>
Rotate the vanguards that have expired,
returning how long until the next vanguard will expire,
or None
if there are no vanguards in any of our sets.
Sourcepub fn mode(&self) -> VanguardMode
pub fn mode(&self) -> VanguardMode
Get the current VanguardMode
.
Source§impl VanguardMgr<MockRuntime>
Helpers for tests involving vanguards
impl VanguardMgr<MockRuntime>
Helpers for tests involving vanguards
Sourcepub fn new_testing(
rt: &MockRuntime,
mode: VanguardMode,
) -> Result<Arc<VanguardMgr<MockRuntime>>, VanguardMgrError>
Available on crate feature testing
only.
pub fn new_testing( rt: &MockRuntime, mode: VanguardMode, ) -> Result<Arc<VanguardMgr<MockRuntime>>, VanguardMgrError>
testing
only.Create a new VanguardMgr for testing.
Sourcepub async fn init_vanguard_sets(
self: &Arc<VanguardMgr<MockRuntime>>,
netdir: &NetDir,
) -> Result<Arc<TestNetDirProvider>, VanguardMgrError>
Available on crate feature testing
only.
pub async fn init_vanguard_sets( self: &Arc<VanguardMgr<MockRuntime>>, netdir: &NetDir, ) -> Result<Arc<TestNetDirProvider>, VanguardMgrError>
testing
only.Wait until the vanguardmgr has populated its vanguard sets.
Returns a TestNetDirProvider
that can be used to notify
the VanguardMgr
of netdir changes.
Auto Trait Implementations§
impl<R> !Freeze for VanguardMgr<R>
impl<R> !RefUnwindSafe for VanguardMgr<R>
impl<R> Send for VanguardMgr<R>
impl<R> Sync for VanguardMgr<R>
impl<R> Unpin for VanguardMgr<R>where
R: Unpin,
impl<R> !UnwindSafe for VanguardMgr<R>
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.