mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Completely overhaul connections and transports
Reduce abstraction leaks. Now the transport can hold any state, rather than just the tag. It's also responsible to initialize on the first connection, and they can be cleanly reset. asyncio connections are no longer used, in favour of raw sockets, which should avoid some annoyances. For the time being, more obscure transport modes have been removed, as well as proxy support, until further cleaning is done.
This commit is contained in:
29
telethon/_network/transports/intermediate.py
Normal file
29
telethon/_network/transports/intermediate.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from .transport import Transport
|
||||
import struct
|
||||
|
||||
|
||||
class Intermediate(Transport):
|
||||
def __init__(self):
|
||||
self._init = False
|
||||
|
||||
def recreate_fresh(self):
|
||||
return type(self)()
|
||||
|
||||
def pack(self, input: bytes) -> bytes:
|
||||
if self._init:
|
||||
header = b''
|
||||
else:
|
||||
header = b'\xee\xee\xee\xee'
|
||||
self._init = True
|
||||
|
||||
return header + struct.pack('<i', len(data)) + data
|
||||
|
||||
def unpack(self, input: bytes) -> (int, bytes):
|
||||
if len(input) < 4:
|
||||
raise EOFError()
|
||||
|
||||
length = struct.unpack('<i', input[:4])[0] + 4
|
||||
if len(input) < length:
|
||||
raise EOFError()
|
||||
|
||||
return length, input[4:length]
|
Reference in New Issue
Block a user