mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Let all connection modes implement the new Connection
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import struct
|
||||
|
||||
from .tcpfull import ConnectionTcpFull
|
||||
from .connection import Connection
|
||||
|
||||
|
||||
class ConnectionTcpIntermediate(ConnectionTcpFull):
|
||||
class ConnectionTcpIntermediate(Connection):
|
||||
"""
|
||||
Intermediate mode between `ConnectionTcpFull` and `ConnectionTcpAbridged`.
|
||||
Always sends 4 extra bytes for the packet length.
|
||||
"""
|
||||
async def connect(self, ip, port):
|
||||
result = await super().connect(ip, port)
|
||||
await self.conn.write(b'\xee\xee\xee\xee')
|
||||
return result
|
||||
async def connect(self):
|
||||
await super().connect()
|
||||
await self.send(b'\xee\xee\xee\xee')
|
||||
|
||||
async def recv(self):
|
||||
return await self.read(struct.unpack('<i', await self.read(4))[0])
|
||||
def _send(self, data):
|
||||
self._writer.write(struct.pack('<i', len(data)) + data)
|
||||
|
||||
async def send(self, message):
|
||||
await self.write(struct.pack('<i', len(message)) + message)
|
||||
async def _recv(self):
|
||||
return await self._reader.readexactly(
|
||||
struct.unpack('<i', await self._reader.readexactly(4))[0])
|
||||
|
Reference in New Issue
Block a user