pub struct TrackerState {
pub current_event: TrackerEvent,
pub last_announce_time: Option<Instant>,
pub min_interval_secs: u64,
pub interval_secs: u64,
pub announce_count: u64,
/* private fields */
}Expand description
State machine for tracking announce events and intervals.
Manages the current event state, timing of announces, and ensures proper event sequencing according to BitTorrent specification.
Fields§
§current_event: TrackerEventCurrent event to send on next announce
last_announce_time: Option<Instant>Timestamp of last successful announce
min_interval_secs: u64Minimum interval between announces (from tracker response)
interval_secs: u64Normal interval between announces (from tracker response)
announce_count: u64Total number of announces sent
Implementations§
Source§impl TrackerState
impl TrackerState
Sourcepub fn should_announce(&self) -> bool
pub fn should_announce(&self) -> bool
Check if it’s time to send another announce based on interval constraints
Returns true if enough time has elapsed since the last announce according to min_interval_secs
Sourcepub fn secs_until_next_announce(&self) -> u64
pub fn secs_until_next_announce(&self) -> u64
Get the recommended wait time until next announce
Sourcepub fn record_announce(&mut self, event: TrackerEvent)
pub fn record_announce(&mut self, event: TrackerEvent)
Mark that an announce has been sent and advance the event state
This updates internal timing and transitions the event state:
- After Started -> None (for regular announces)
- After Completed -> None
- After Stopped -> stays Stopped (terminal state)
Sourcepub fn update_intervals(
&mut self,
interval: Option<u64>,
min_interval: Option<u64>,
)
pub fn update_intervals( &mut self, interval: Option<u64>, min_interval: Option<u64>, )
Update interval values from tracker response
Trackers return interval (recommended) and optionally min interval
which constrain how often we may re-announce.
Sourcepub fn mark_completed(&mut self)
pub fn mark_completed(&mut self)
Transition to completed state - call when all pieces are downloaded
Sourcepub fn mark_stopped(&mut self)
pub fn mark_stopped(&mut self)
Transition to stopped state - call on shutdown/cancel
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Check if the tracker is in terminal (stopped) state
Trait Implementations§
Source§impl Debug for TrackerState
impl Debug for TrackerState
Auto Trait Implementations§
impl Freeze for TrackerState
impl RefUnwindSafe for TrackerState
impl Send for TrackerState
impl Sync for TrackerState
impl Unpin for TrackerState
impl UnsafeUnpin for TrackerState
impl UnwindSafe for TrackerState
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
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>
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