pub struct TimePeriod { /* private fields */ }
Expand description
A period of time, as used in the onion service system.
A TimePeriod
is defined as a duration (in seconds), and the number of such
durations that have elapsed since a given offset from the Unix epoch. So
for example, the interval “(86400 seconds length, 15 intervals, 12 hours
offset)”, covers 1970-01-16T12:00:00
up to but not including
1970-01-17T12:00:00
.
These time periods are used to derive a different BlindedOnionIdKey
during
each period from each OnionIdKey
.
Implementations§
Source§impl TimePeriod
impl TimePeriod
Sourcepub fn new(
length: Duration,
when: SystemTime,
epoch_offset: Duration,
) -> Result<Self, TimePeriodError>
pub fn new( length: Duration, when: SystemTime, epoch_offset: Duration, ) -> Result<Self, TimePeriodError>
Construct a time period of a given length
that contains when
.
The length
value is rounded down to the nearest second,
and must then be a whole number of minutes.
The epoch_offset
value is the amount of time after the Unix epoch when
our epoch begins. It is also rounded down to the nearest second.
Return None if the Duration is too large or too small, or if when
cannot be represented as a time period.
Sourcepub fn from_parts(
length: u32,
interval_num: u64,
epoch_offset_in_sec: u32,
) -> Self
pub fn from_parts( length: u32, interval_num: u64, epoch_offset_in_sec: u32, ) -> Self
Compute the TimePeriod
, given its length (in minutes), index (the number of time
periods that have passed since the unix epoch), and offset from the epoch (in seconds).
The epoch_offset_in_sec
value is the number of seconds after the Unix epoch when our
epoch begins, rounded down to the nearest second.
Note that this is not the time_t at which this Time Period begins.
The returned TP begins at the time_t interval_num * length * 60 + epoch_offset_in_sec
and ends length * 60
seconds later.
Sourcepub fn next(&self) -> Option<Self>
pub fn next(&self) -> Option<Self>
Return the time period after this one.
Return None if this is the last representable time period.
Sourcepub fn prev(&self) -> Option<Self>
pub fn prev(&self) -> Option<Self>
Return the time period before this one.
Return None if this is the first representable time period.
Sourcepub fn contains(&self, when: SystemTime) -> bool
pub fn contains(&self, when: SystemTime) -> bool
Return true if this time period contains when
.
§Limitations
This function always returns false if the time period contains any times
that cannot be represented as a SystemTime
.
Sourcepub fn range(&self) -> Result<Range<SystemTime>, TimePeriodError>
pub fn range(&self) -> Result<Range<SystemTime>, TimePeriodError>
Return a range representing the SystemTime
values contained within
this time period.
Return None if this time period contains any times that can be
represented as a SystemTime
.
Sourcepub fn interval_num(&self) -> u64
pub fn interval_num(&self) -> u64
Return the numeric index of this time period.
This function should only be used when encoding the time period for cryptographic purposes.
Sourcepub fn length(&self) -> IntegerMinutes<u32>
pub fn length(&self) -> IntegerMinutes<u32>
Return the length of this time period as a number of seconds.
This function should only be used when encoding the time period for cryptographic purposes.
Sourcepub fn epoch_offset_in_sec(&self) -> u32
pub fn epoch_offset_in_sec(&self) -> u32
Return our offset from the epoch, in seconds.
Note that this is not the start of the TP.
See TimePeriod::from_parts
.
Trait Implementations§
Source§impl Clone for TimePeriod
impl Clone for TimePeriod
Source§fn clone(&self) -> TimePeriod
fn clone(&self) -> TimePeriod
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TimePeriod
impl Debug for TimePeriod
Source§impl Display for TimePeriod
impl Display for TimePeriod
Source§impl PartialEq for TimePeriod
impl PartialEq for TimePeriod
Source§impl PartialOrd for TimePeriod
Two TimePeriod
s are ordered with respect to one another if they have the
same interval length and offset.
impl PartialOrd for TimePeriod
Two TimePeriod
s are ordered with respect to one another if they have the
same interval length and offset.
impl Copy for TimePeriod
impl Eq for TimePeriod
impl StructuralPartialEq for TimePeriod
Auto Trait Implementations§
impl Freeze for TimePeriod
impl RefUnwindSafe for TimePeriod
impl Send for TimePeriod
impl Sync for TimePeriod
impl Unpin for TimePeriod
impl UnwindSafe for TimePeriod
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§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