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: telethon.network.connection.connection.Connection

Default Telegram mode. Sends 12 additional bytes and needs to calculate the CRC value of the packet itself.

packet_codec

alias of FullPacketCodec

class telethon.network.connection.tcpfull.FullPacketCodec(connection)

Bases: telethon.network.connection.connection.PacketCodec

encode_packet(data)

Encodes single packet and returns encoded bytes.

read_packet(reader)

Reads single packet from reader object that should have readexactly(n) method.

tag = None
class telethon.network.connection.tcpabridged.AbridgedPacketCodec(connection)

Bases: telethon.network.connection.connection.PacketCodec

encode_packet(data)

Encodes single packet and returns encoded bytes.

obfuscate_tag = b'\xef\xef\xef\xef'
read_packet(reader)

Reads single packet from reader object that should have readexactly(n) method.

tag = b'\xef'
class telethon.network.connection.tcpabridged.ConnectionTcpAbridged(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)

Bases: telethon.network.connection.connection.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).

packet_codec

alias of AbridgedPacketCodec

class telethon.network.connection.tcpintermediate.ConnectionTcpIntermediate(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)

Bases: telethon.network.connection.connection.Connection

Intermediate mode between ConnectionTcpFull and ConnectionTcpAbridged. Always sends 4 extra bytes for the packet length.

packet_codec

alias of IntermediatePacketCodec

class telethon.network.connection.tcpintermediate.IntermediatePacketCodec(connection)

Bases: telethon.network.connection.connection.PacketCodec

encode_packet(data)

Encodes single packet and returns encoded bytes.

obfuscate_tag = b'\xee\xee\xee\xee'
read_packet(reader)

Reads single packet from reader object that should have readexactly(n) method.

tag = b'\xee\xee\xee\xee'
class telethon.network.connection.tcpintermediate.RandomizedIntermediatePacketCodec(connection)

Bases: telethon.network.connection.tcpintermediate.IntermediatePacketCodec

Data packets are aligned to 4bytes. This codec adds random bytes of size from 0 to 3 bytes, which are ignored by decoder.

encode_packet(data)

Encodes single packet and returns encoded bytes.

obfuscate_tag = b'\xdd\xdd\xdd\xdd'
read_packet(reader)

Reads single packet from reader object that should have readexactly(n) method.

tag = None
class telethon.network.connection.tcpobfuscated.ConnectionTcpObfuscated(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)

Bases: telethon.network.connection.connection.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.

obfuscated_io

alias of ObfuscatedIO

packet_codec

alias of telethon.network.connection.tcpabridged.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)
readexactly(n)
write(data)
class telethon.network.connection.http.ConnectionHttp(ip, port, dc_id, *, loggers, proxy=None, local_addr=None)

Bases: telethon.network.connection.connection.Connection

connect(timeout=None, ssl=None)

Establishes a connection with the server.

packet_codec

alias of HttpPacketCodec

class telethon.network.connection.http.HttpPacketCodec(connection)

Bases: telethon.network.connection.connection.PacketCodec

encode_packet(data)

Encodes single packet and returns encoded bytes.

obfuscate_tag = None
read_packet(reader)

Reads single packet from reader object that should have readexactly(n) method.

tag = None