From 64fe9163d25ff8a176268e8fa87027224046461b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 15 May 2018 19:17:22 +0200 Subject: [PATCH] Refactor tcp_abridged --- .../connection/transport/tcp/tcp_abridged.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp_abridged.py b/pyrogram/connection/transport/tcp/tcp_abridged.py index ad682fed..472f4799 100644 --- a/pyrogram/connection/transport/tcp/tcp_abridged.py +++ b/pyrogram/connection/transport/tcp/tcp_abridged.py @@ -26,28 +26,23 @@ log = logging.getLogger(__name__) class TCPAbridged(TCP): def __init__(self, proxy: dict): super().__init__(proxy) - self.is_first_packet = None def connect(self, address: tuple): super().connect(address) - self.is_first_packet = True + super().sendall(b"\xef") + log.info("Connected{}!".format(" with proxy" if self.proxy_enabled else "")) def sendall(self, data: bytes, *args): length = len(data) // 4 - data = ( - bytes([length]) + data - if length <= 126 - else b"\x7f" + int.to_bytes(length, 3, "little") + data + super().sendall( + (bytes([length]) + if length <= 126 + else b"\x7f" + length.to_bytes(3, "little")) + + data ) - if self.is_first_packet: - data = b"\xef" + data - self.is_first_packet = False - - super().sendall(data) - def recvall(self, length: int = 0) -> bytes or None: length = super().recvall(1)