import struct from zlib import crc32 from .connection import Connection from ...errors import InvalidChecksumError class ConnectionTcpFull(Connection): """ Default Telegram mode. Sends 12 additional bytes and needs to calculate the CRC value of the packet itself. """ def __init__(self, ip, port, *, loop, proxy=None): super().__init__(ip, port, loop=loop, proxy=proxy) self._send_counter = 0 async def connect(self, timeout=None, ssl=None): await super().connect(timeout=timeout, ssl=ssl) self._send_counter = 0 # Important or Telegram won't reply def _send(self, data): # https://core.telegram.org/mtproto#tcp-transport # total length, sequence number, packet and checksum (CRC32) length = len(data) + 12 data = struct.pack('