pub struct Connection {
pub stream: TcpStream,
pub enc: EncryptedSession,
pub frame_kind: FrameKind,
pub perm_auth_key: Option<[u8; 256]>,
}Fields§
§stream: TcpStream§enc: EncryptedSession§frame_kind: FrameKind§perm_auth_key: Option<[u8; 256]>When PFS is active, the permanent auth key (stored in session).
enc holds the temp key; this field holds the perm key so
auth_key_bytes() returns the right value to persist.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn open_stream_pub(
addr: &str,
dc_id: i16,
transport: &TransportKind,
socks5: Option<&Socks5Config>,
mtproxy: Option<&MtProxyConfig>,
) -> Result<(TcpStream, FrameKind), ConnectError>
pub async fn open_stream_pub( addr: &str, dc_id: i16, transport: &TransportKind, socks5: Option<&Socks5Config>, mtproxy: Option<&MtProxyConfig>, ) -> Result<(TcpStream, FrameKind), ConnectError>
Open a TCP stream and apply transport framing, returning the stream and FrameKind.
Used by ferogram-mtsender for the connect-with-key path where DH is not needed
(the auth key is already known). Socket options and transport init are handled here.
Sourcepub async fn connect_raw(
addr: &str,
socks5: Option<&Socks5Config>,
mtproxy: Option<&MtProxyConfig>,
transport: &TransportKind,
dc_id: i16,
) -> Result<Self, ConnectError>
pub async fn connect_raw( addr: &str, socks5: Option<&Socks5Config>, mtproxy: Option<&MtProxyConfig>, transport: &TransportKind, dc_id: i16, ) -> Result<Self, ConnectError>
Open a fresh connection and run the full unauthenticated DH key
exchange to produce a brand new permanent auth key. Use
Self::connect_with_key instead once an auth key already exists
for the DC, since redoing DH on every reconnect is wasted work.
Sourcepub async fn connect_with_key(
addr: &str,
auth_key: [u8; 256],
first_salt: i64,
time_offset: i32,
socks5: Option<&Socks5Config>,
mtproxy: Option<&MtProxyConfig>,
transport: &TransportKind,
dc_id: i16,
pfs: bool,
) -> Result<Self, ConnectError>
pub async fn connect_with_key( addr: &str, auth_key: [u8; 256], first_salt: i64, time_offset: i32, socks5: Option<&Socks5Config>, mtproxy: Option<&MtProxyConfig>, transport: &TransportKind, dc_id: i16, pfs: bool, ) -> Result<Self, ConnectError>
Open a connection using an auth_key already negotiated for this DC,
skipping the DH handshake entirely. If pfs is set, also binds a
temporary key for this session via auth.bindTempAuthKey, falling
back to the permanent key if the bind fails.
Sourcepub fn auth_key_bytes(&self) -> [u8; 256]
pub fn auth_key_bytes(&self) -> [u8; 256]
The permanent auth key, for persisting to the session. Under PFS this
is perm_auth_key, not the short-lived temp key the connection is
actually encrypted with.
Sourcepub async fn connect_to_dc(
addr: &str,
dc_id: i16,
transport: &TransportKind,
socks5: Option<&Socks5Config>,
mtproxy: Option<&MtProxyConfig>,
) -> Result<(TcpStream, FrameKind, EncryptedSession), ConnectError>
pub async fn connect_to_dc( addr: &str, dc_id: i16, transport: &TransportKind, socks5: Option<&Socks5Config>, mtproxy: Option<&MtProxyConfig>, ) -> Result<(TcpStream, FrameKind, EncryptedSession), ConnectError>
Open a TCP connection, negotiate transport framing, and complete the MTProto DH handshake.
Returns (stream, frame_kind, session) as owned values. The caller is responsible for
setting up reader/writer tasks. This is the single authoritative connection path;
ferogram-mtsender delegates here instead of reimplementing the DH sequence.
Auto Trait Implementations§
impl !Freeze for Connection
impl !RefUnwindSafe for Connection
impl !UnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
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