pub struct RwhodStatusRegistry {
max_entries: usize,
by_hostname: HashMap<String, WhodStatusUpdate>,
by_recvtime: BTreeSet<(DateTime<Utc>, String)>,
}Expand description
A bounded collection of rwhod status updates, keyed by hostname.
This exists to put a hard cap on memory usage regardless of how many
distinct hostnames a (potentially malicious) sender on the LAN tries to
report. When the registry is at capacity and an update for a
previously-unseen hostname comes in, the entry with the oldest
recvtime is evicted to make room for it. Hosts that keep broadcasting
periodically naturally stay “recent” and are never evicted by this.
Fields§
§max_entries: usize§by_hostname: HashMap<String, WhodStatusUpdate>§by_recvtime: BTreeSet<(DateTime<Utc>, String)>Implementations§
Source§impl RwhodStatusRegistry
impl RwhodStatusRegistry
pub fn new(max_entries: usize) -> Self
Sourcepub fn upsert(&mut self, status_update: WhodStatusUpdate)
pub fn upsert(&mut self, status_update: WhodStatusUpdate)
Insert or refresh a status update, keyed by its hostname.
If the registry is at capacity and status_update is for a
previously-unseen hostname, the entry with the oldest recvtime
will be evicted to make room for it.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn values(&self) -> impl Iterator<Item = &WhodStatusUpdate>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RwhodStatusRegistry
impl RefUnwindSafe for RwhodStatusRegistry
impl Send for RwhodStatusRegistry
impl Sync for RwhodStatusRegistry
impl Unpin for RwhodStatusRegistry
impl UnsafeUnpin for RwhodStatusRegistry
impl UnwindSafe for RwhodStatusRegistry
Blanket Implementations§
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
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