Skip to main content

ConnectionWriter

Struct ConnectionWriter 

Source
pub struct ConnectionWriter {
    pub enc: EncryptedSession,
    pub frame_kind: FrameKind,
    pub perm_auth_key: Option<[u8; 256]>,
    pub pending_ack: Vec<i64>,
    pub sent_bodies: HashMap<i64, Vec<u8>>,
    pub container_map: HashMap<i64, i64>,
    pub new_session_resend_queue: Vec<(i64, i64, Vec<u8>)>,
    pub salts: Vec<FutureSalt>,
    pub start_salt_time: Option<(i32, Instant)>,
}
Expand description

Owns the EncryptedSession (for packing) and the pending-RPC map.

Fields§

§enc: EncryptedSession§frame_kind: FrameKind§perm_auth_key: Option<[u8; 256]>

PFS: permanent auth key to save in session. None when PFS is off.

§pending_ack: Vec<i64>

msg_ids of received content messages waiting to be acked. Drained into a MsgsAck on every outgoing frame (bundled into container when sending an RPC, or sent standalone after route_frame).

§sent_bodies: HashMap<i64, Vec<u8>>

raw TL body bytes of every sent request, keyed by msg_id. On bad_msg_notification the matching body is re-encrypted with a fresh msg_id and re-sent transparently.

§container_map: HashMap<i64, i64>

maps container_msg_id -> inner request msg_id. When bad_msg_notification / bad_server_salt arrives for a container rather than the individual inner message, we look here to find the inner request to retry.

§new_session_resend_queue: Vec<(i64, i64, Vec<u8>)>

Stale-msg resends queued under the writer lock and drained after release to avoid holding the lock across TCP I/O.

§salts: Vec<FutureSalt>

-style future salt pool. Sorted by valid_since ascending so the newest salt is LAST (.valid_since), which puts the highest valid_since at the end in ascending-key order).

§start_salt_time: Option<(i32, Instant)>

Server-time anchor received with the last GetFutureSalts response. (server_now, local_instant) lets us approximate server time at any moment so we can check whether a salt’s valid_since window has opened.

Implementations§

Source§

impl ConnectionWriter

Source

pub fn auth_key_bytes(&self) -> [u8; 256]

Source

pub fn first_salt(&self) -> i64

Source

pub fn time_offset(&self) -> i32

Source

pub fn advance_salt_if_needed(&mut self) -> bool

Proactively advance the active salt and prune expired ones.

Called at the top of every RPC send. Salts are sorted ascending by valid_since (oldest=index 0, newest=last).

Prunes expired salts, then advances enc.salt to the freshest usable one.

Returns true when the pool has shrunk to a single entry: caller should fire a proactive GetFutureSalts via try_request_salts().

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> 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, 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