diff --git a/client/src/telethon/_impl/mtproto/transport/abcs.py b/client/src/telethon/_impl/mtproto/transport/abcs.py index d1b01956..b3a16f58 100644 --- a/client/src/telethon/_impl/mtproto/transport/abcs.py +++ b/client/src/telethon/_impl/mtproto/transport/abcs.py @@ -15,6 +15,10 @@ class Transport(ABC): def unpack(self, input: bytes | bytearray | memoryview, output: bytearray) -> int: pass + @abstractmethod + def reset(self): + pass + class MissingBytesError(ValueError): def __init__(self, *, expected: int, got: int) -> None: diff --git a/client/src/telethon/_impl/mtproto/transport/abridged.py b/client/src/telethon/_impl/mtproto/transport/abridged.py index 1f8cf482..65b92a14 100644 --- a/client/src/telethon/_impl/mtproto/transport/abridged.py +++ b/client/src/telethon/_impl/mtproto/transport/abridged.py @@ -1,3 +1,4 @@ +import logging import struct from .abcs import BadStatusError, MissingBytesError, OutFn, Transport @@ -60,3 +61,7 @@ class Abridged(Transport): output += memoryview(input)[header_len : header_len + length] return header_len + length + + def reset(self): + logging.info("Resetting sending of header in abridged transport") + self._init = False diff --git a/client/src/telethon/_impl/mtproto/transport/full.py b/client/src/telethon/_impl/mtproto/transport/full.py index 59cc1e2c..f04d751c 100644 --- a/client/src/telethon/_impl/mtproto/transport/full.py +++ b/client/src/telethon/_impl/mtproto/transport/full.py @@ -1,3 +1,4 @@ +import logging import struct from zlib import crc32 @@ -61,3 +62,8 @@ class Full(Transport): self._recv_seq += 1 output += memoryview(input)[8 : length - 4] return length + + def reset(self): + logging.info("Resetting recv and send seqs in full transport") + self._send_seq = 0 + self._recv_seq = 0 diff --git a/client/src/telethon/_impl/mtproto/transport/intermediate.py b/client/src/telethon/_impl/mtproto/transport/intermediate.py index 2f5b434e..e75adff6 100644 --- a/client/src/telethon/_impl/mtproto/transport/intermediate.py +++ b/client/src/telethon/_impl/mtproto/transport/intermediate.py @@ -1,3 +1,4 @@ +import logging import struct from .abcs import BadStatusError, MissingBytesError, OutFn, Transport @@ -52,3 +53,7 @@ class Intermediate(Transport): output += memoryview(input)[4 : 4 + length] return length + 4 + + def reset(self): + logging.info("Resetting sending of header in intermediate transport") + self._init = False