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