Connection Modes
The only part about network that you should worry about are the different connection modes, which are the following:
- class telethon.network.connection.tcpfull.ConnectionTcpFull(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)
Bases:
Connection
Default Telegram mode. Sends 12 additional bytes and needs to calculate the CRC value of the packet itself.
- __annotations__ = {}
- packet_codec
alias of
FullPacketCodec
- class telethon.network.connection.tcpfull.FullPacketCodec(connection)
Bases:
PacketCodec
- __annotations__ = {}
- encode_packet(data)
Encodes single packet and returns encoded bytes.
- async read_packet(reader)
Reads single packet from
reader
object that should havereadexactly(n)
method.
- tag = None
- class telethon.network.connection.tcpabridged.AbridgedPacketCodec(connection)
Bases:
PacketCodec
- __annotations__ = {}
- encode_packet(data)
Encodes single packet and returns encoded bytes.
- obfuscate_tag = b'\xef\xef\xef\xef'
- async read_packet(reader)
Reads single packet from
reader
object that should havereadexactly(n)
method.
- tag = b'\xef'
- class telethon.network.connection.tcpabridged.ConnectionTcpAbridged(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)
Bases:
Connection
This is the mode with the lowest overhead, as it will only require 1 byte if the packet length is less than 508 bytes (127 << 2, which is very common).
- __annotations__ = {}
- packet_codec
alias of
AbridgedPacketCodec
- class telethon.network.connection.tcpintermediate.ConnectionTcpIntermediate(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)
Bases:
Connection
Intermediate mode between
ConnectionTcpFull
andConnectionTcpAbridged
. Always sends 4 extra bytes for the packet length.- __annotations__ = {}
- packet_codec
alias of
IntermediatePacketCodec
- class telethon.network.connection.tcpintermediate.IntermediatePacketCodec(connection)
Bases:
PacketCodec
- __annotations__ = {}
- encode_packet(data)
Encodes single packet and returns encoded bytes.
- obfuscate_tag = b'\xee\xee\xee\xee'
- async read_packet(reader)
Reads single packet from
reader
object that should havereadexactly(n)
method.
- tag = b'\xee\xee\xee\xee'
- class telethon.network.connection.tcpintermediate.RandomizedIntermediatePacketCodec(connection)
Bases:
IntermediatePacketCodec
Data packets are aligned to 4bytes. This codec adds random bytes of size from 0 to 3 bytes, which are ignored by decoder.
- __annotations__ = {}
- encode_packet(data)
Encodes single packet and returns encoded bytes.
- obfuscate_tag = b'\xdd\xdd\xdd\xdd'
- async read_packet(reader)
Reads single packet from
reader
object that should havereadexactly(n)
method.
- tag = None
- class telethon.network.connection.tcpobfuscated.ConnectionTcpObfuscated(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)
Bases:
ObfuscatedConnection
Mode that Telegram defines as “obfuscated2”. Encodes the packet just like
ConnectionTcpAbridged
, but encrypts every message with a randomly generated key using the AES-CTR mode so the packets are harder to discern.- __annotations__ = {}
- obfuscated_io
alias of
ObfuscatedIO
- packet_codec
alias of
AbridgedPacketCodec
- class telethon.network.connection.tcpobfuscated.ObfuscatedIO(connection)
Bases:
object
- __weakref__
list of weak references to the object (if defined)
- header = None
- static init_header(packet_codec)
- async readexactly(n)
- write(data)
- class telethon.network.connection.http.ConnectionHttp(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)
Bases:
Connection
- __annotations__ = {}
- async connect(timeout=None, ssl=None)
Establishes a connection with the server.
- packet_codec
alias of
HttpPacketCodec
- class telethon.network.connection.http.HttpPacketCodec(connection)
Bases:
PacketCodec
- __annotations__ = {}
- encode_packet(data)
Encodes single packet and returns encoded bytes.
- obfuscate_tag = None
- async read_packet(reader)
Reads single packet from
reader
object that should havereadexactly(n)
method.
- tag = None