pub struct PtsState {
pub pts: i32,
pub qts: i32,
pub date: i32,
pub seq: i32,
pub channel_pts: HashMap<i64, i32>,
pub channel_diff_calls: HashMap<i64, u32>,
pub last_update_at: Option<Instant>,
pub getting_diff_for: HashSet<i64>,
pub getting_global_diff: bool,
pub getting_global_diff_since: Option<Instant>,
}Expand description
Full MTProto sequence-number state, including per-channel counters.
All fields are pub so that connect() can restore them from the
persisted session without going through an artificial constructor.
Fields§
§pts: i32Main pts counter (messages, non-channel updates).
qts: i32Secondary counter for secret-chat updates.
date: i32Date of the last received update (Unix timestamp).
seq: i32Combined-container sequence number.
channel_pts: HashMap<i64, i32>Per-channel pts counters. channel_id → pts.
channel_diff_calls: HashMap<i64, u32>How many times getChannelDifference has been called per channel. tDesktop starts at limit=100, then raises to 1000 after the first successful response. We track call count to implement the same ramp-up.
last_update_at: Option<Instant>Timestamp of last received update for deadline-based gap detection.
getting_diff_for: HashSet<i64>Channels currently awaiting a getChannelDifference response. If a channel is in this set, no new gap-fill task is spawned for it.
getting_global_diff: boolGuard against concurrent global getDifference calls. Without this, two simultaneous gap detections both spawn get_difference(), which double-processes updates and corrupts pts state.
getting_global_diff_since: Option<Instant>When getting_global_diff was set to true. Used by the stuck-diff watchdog in check_update_deadline: if the flag has been set for >30 s the RPC is assumed hung and the guard is reset so the next gap_tick can retry.
Implementations§
Source§impl PtsState
impl PtsState
pub fn from_server_state(s: &State) -> Self
Sourcepub fn deadline_exceeded(&self) -> bool
pub fn deadline_exceeded(&self) -> bool
Returns true if no update has been received for > 15 minutes.
Sourcepub fn check_pts(&self, new_pts: i32, pts_count: i32) -> PtsCheckResult
pub fn check_pts(&self, new_pts: i32, pts_count: i32) -> PtsCheckResult
Check whether new_pts is in order given pts_count new updates.
Sourcepub fn check_qts(&self, new_qts: i32, qts_count: i32) -> PtsCheckResult
pub fn check_qts(&self, new_qts: i32, qts_count: i32) -> PtsCheckResult
Check a qts value (secret chat updates).
Sourcepub fn check_seq(&self, _new_seq: i32, seq_start: i32) -> PtsCheckResult
pub fn check_seq(&self, _new_seq: i32, seq_start: i32) -> PtsCheckResult
Check top-level seq for UpdatesCombined containers.
Sourcepub fn check_channel_pts(
&self,
channel_id: i64,
new_pts: i32,
pts_count: i32,
) -> PtsCheckResult
pub fn check_channel_pts( &self, channel_id: i64, new_pts: i32, pts_count: i32, ) -> PtsCheckResult
Check a per-channel pts value.
Sourcepub fn advance_qts(&mut self, new_qts: i32)
pub fn advance_qts(&mut self, new_qts: i32)
Advance the qts.
Sourcepub fn advance_seq(&mut self, new_seq: i32)
pub fn advance_seq(&mut self, new_seq: i32)
Advance seq.
Sourcepub fn advance_channel(&mut self, channel_id: i64, new_pts: i32)
pub fn advance_channel(&mut self, channel_id: i64, new_pts: i32)
Advance a per-channel pts.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PtsState
impl RefUnwindSafe for PtsState
impl Send for PtsState
impl Sync for PtsState
impl Unpin for PtsState
impl UnsafeUnpin for PtsState
impl UnwindSafe for PtsState
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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