Skip to main content

PtsState

Struct PtsState 

Source
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: i32

Main pts counter (messages, non-channel updates).

§qts: i32

Secondary counter for secret-chat updates.

§date: i32

Date of the last received update (Unix timestamp).

§seq: i32

Combined-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: bool

Guard 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

Source

pub fn from_server_state(s: &State) -> Self

Source

pub fn touch(&mut self)

Record that an update was received now (resets the deadline timer).

Source

pub fn deadline_exceeded(&self) -> bool

Returns true if no update has been received for > 15 minutes.

Source

pub fn check_pts(&self, new_pts: i32, pts_count: i32) -> PtsCheckResult

Check whether new_pts is in order given pts_count new updates.

Source

pub fn check_qts(&self, new_qts: i32, qts_count: i32) -> PtsCheckResult

Check a qts value (secret chat updates).

Source

pub fn check_seq(&self, _new_seq: i32, seq_start: i32) -> PtsCheckResult

Check top-level seq for UpdatesCombined containers.

Source

pub fn check_channel_pts( &self, channel_id: i64, new_pts: i32, pts_count: i32, ) -> PtsCheckResult

Check a per-channel pts value.

Source

pub fn advance(&mut self, new_pts: i32)

Advance the global pts.

Source

pub fn advance_qts(&mut self, new_qts: i32)

Advance the qts.

Source

pub fn advance_seq(&mut self, new_seq: i32)

Advance seq.

Source

pub fn advance_channel(&mut self, channel_id: i64, new_pts: i32)

Advance a per-channel pts.

Trait Implementations§

Source§

impl Clone for PtsState

Source§

fn clone(&self) -> PtsState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PtsState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PtsState

Source§

fn default() -> PtsState

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more