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.