pub struct BloomTokenLog(/* private fields */);Expand description
Bloom filter-based TokenLog
Parameterizable over an approximate maximum number of bytes to allocate. Starts out by storing used tokens in a hash set. Once the hash set becomes too large, converts it to a bloom filter. This achieves a memory profile of linear growth with an upper bound.
Divides time into periods based on lifetime and stores two filters at any given moment, for
each of the two periods currently non-expired tokens could expire in. As such, turns over
filters as time goes on to avoid bloom filter false positive rate increasing infinitely over
time.
Implementations§
Source§impl BloomTokenLog
impl BloomTokenLog
Sourcepub fn new_expected_items(max_bytes: usize, expected_hits: u64) -> BloomTokenLog
pub fn new_expected_items(max_bytes: usize, expected_hits: u64) -> BloomTokenLog
Construct with an approximate maximum memory usage and expected number of validation token usages per expiration period
Calculates the optimal bloom filter k number automatically.
Sourcepub fn new(max_bytes: usize, k_num: u32) -> BloomTokenLog
pub fn new(max_bytes: usize, k_num: u32) -> BloomTokenLog
Construct with an approximate maximum memory usage and a bloom filter k number
If choosing a custom k number, note that BloomTokenLog always maintains two filters
between them and divides the allocation budget of max_bytes evenly between them. As such,
each bloom filter will contain max_bytes * 4 bits.
Trait Implementations§
Source§impl Default for BloomTokenLog
Default to 20 MiB max memory consumption and expected one million hits
impl Default for BloomTokenLog
Default to 20 MiB max memory consumption and expected one million hits
With the default validation token lifetime of 2 weeks, this corresponds to one token usage per 1.21 seconds.
Source§fn default() -> BloomTokenLog
fn default() -> BloomTokenLog
Source§impl TokenLog for BloomTokenLog
impl TokenLog for BloomTokenLog
Source§fn check_and_insert(
&self,
nonce: u128,
issued: SystemTime,
lifetime: Duration,
) -> Result<(), TokenReuseError>
fn check_and_insert( &self, nonce: u128, issued: SystemTime, lifetime: Duration, ) -> Result<(), TokenReuseError>
Auto Trait Implementations§
impl !Freeze for BloomTokenLog
impl RefUnwindSafe for BloomTokenLog
impl Send for BloomTokenLog
impl Sync for BloomTokenLog
impl Unpin for BloomTokenLog
impl UnwindSafe for BloomTokenLog
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
§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