import struct import random import os from .connection import Connection class ConnectionTcpIntermediate(Connection): """ Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`. Always sends 4 extra bytes for the packet length. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._codec = IntermediatePacket() def _init_conn(self): self._writer.write(self._codec.tag) def _send(self, data): self._writer.write(self._codec.encode_packet(data)) async def _recv(self): return await self.codec.read_packet(self._reader) class IntermediatePacket: tag = b'\xee\xee\xee\xee' mtproto_proxy_tag = tag def encode_packet(self, data): return struct.pack(' 0: return packet_with_padding[:-pad_size] return packet_with_padding