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
impl ConnectionWriter
pub fn auth_key_bytes(&self) -> [u8; 256]
pub fn first_salt(&self) -> i64
pub fn time_offset(&self) -> i32
Sourcepub fn advance_salt_if_needed(&mut self) -> bool
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§
impl Freeze for ConnectionWriter
impl !RefUnwindSafe for ConnectionWriter
impl Send for ConnectionWriter
impl Sync for ConnectionWriter
impl Unpin for ConnectionWriter
impl UnsafeUnpin for ConnectionWriter
impl !UnwindSafe for ConnectionWriter
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