pub struct RelayManager { /* private fields */ }Expand description
Manages circuit relay v2 reservations.
All public methods are safe to call from multiple threads concurrently; the
internal RwLock is a parking_lot lock and never blocks async tasks
for long.
Implementations§
Source§impl RelayManager
impl RelayManager
Sourcepub fn new(max_reservations: usize) -> Self
pub fn new(max_reservations: usize) -> Self
Create a new manager with the given capacity limit.
Sourcepub fn add_reservation(
&self,
reservation: RelayReservation,
) -> Result<(), RelayError>
pub fn add_reservation( &self, reservation: RelayReservation, ) -> Result<(), RelayError>
Insert a new reservation.
Fails with:
RelayError::AlreadyExistsifreservation.relay_peer_idis already tracked.RelayError::AtCapacityif the cap would be exceeded.
Sourcepub fn remove_reservation(&self, relay_peer_id: &str) -> bool
pub fn remove_reservation(&self, relay_peer_id: &str) -> bool
Remove the reservation for relay_peer_id.
Returns true if a reservation existed and was removed.
Sourcepub fn get_reservation(&self, relay_peer_id: &str) -> Option<RelayReservation>
pub fn get_reservation(&self, relay_peer_id: &str) -> Option<RelayReservation>
Look up a reservation by relay peer ID (cloned snapshot).
Sourcepub fn active_reservations(&self, now_ms: u64) -> Vec<RelayReservation>
pub fn active_reservations(&self, now_ms: u64) -> Vec<RelayReservation>
Return all non-expired reservations as of now_ms.
Sourcepub fn expired_reservations(&self, now_ms: u64) -> Vec<String>
pub fn expired_reservations(&self, now_ms: u64) -> Vec<String>
Return the peer IDs of all expired reservations.
Sourcepub fn prune_expired(&self, now_ms: u64) -> usize
pub fn prune_expired(&self, now_ms: u64) -> usize
Remove every expired reservation and return the count of removed entries.
Sourcepub fn reservation_count(&self) -> usize
pub fn reservation_count(&self) -> usize
Total number of tracked reservations (active + expired).
Sourcepub fn is_at_capacity(&self) -> bool
pub fn is_at_capacity(&self) -> bool
Returns true when the manager cannot accept any more reservations.
Auto Trait Implementations§
impl !Freeze for RelayManager
impl !RefUnwindSafe for RelayManager
impl Send for RelayManager
impl Sync for RelayManager
impl Unpin for RelayManager
impl UnsafeUnpin for RelayManager
impl UnwindSafe for RelayManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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