miniproto.connection.sender.MTProtoSender
miniproto.connection.sender.MTProtoSender
Section titled “miniproto.connection.sender.MTProtoSender”MTProtoSender(endpoint: ConnectionEndpoint, transport_config: TransportConfig, state: MTProtoState, *, connector: StreamConnector | None = None, reconnect_attempts: int = 3, ping_disconnect_delay: int = 75, ping_interval: float = DEFAULT_PING_INTERVAL, ack_flush_threshold: int = DEFAULT_ACK_FLUSH_THRESHOLD, ack_max_delay: float = DEFAULT_ACK_MAX_DELAY, max_pending_rpcs: int | None = None, incoming_queue_size: int = DEFAULT_INCOMING_QUEUE_SIZE, on_salt_change: Callable[[int], None] | None = None, reconnect_cooldown: float = DEFAULT_RECONNECT_COOLDOWN) -> NoneManage a concurrent encrypted MTProto session over a reconnecting transport.
One sender serializes message-ID/sequence assignment and transport writes
while supporting concurrent :meth:request callers. It owns its receive and
keepalive tasks after :meth:connect; callers must eventually
:meth:disconnect. On a routine transport loss it retries only explicitly
retry_safe requests and reports an ambiguous result for unsafe requests.
Configure a disconnected sender and its bounded background machinery.
Parameters:
- endpoint (
ConnectionEndpoint) – Remote MTProto TCP destination. - transport_config (
TransportConfig) – Transport framing, deadline, and reconnect bounds. - state (
MTProtoState) – Mutable authorization/session state used to encrypt, validate, sequence, acknowledge, and persist MTProto messages. - connector (
StreamConnector | None) – Optional stream factory passed to every transport open. - reconnect_attempts (
int) – Maximum connection attempts per recovery cycle; defaults to 3. - ping_disconnect_delay (
int) – Telegram disconnect timeout armed by pings; defaults to 75 seconds. - ping_interval (
float) – Requested ping cadence, clamped to at least 0.05 s and no more than half the read deadline; defaults to 45 s. - ack_flush_threshold (
int) – Pending acknowledgements that trigger an eager flush; clamped to at least 1 and defaults to 16. - ack_max_delay (
float) – Maximum age before the keepalive task flushes queued acknowledgements; clamped to at least 0.05 s and defaults to 10. - max_pending_rpcs (
int | None) – Optional hard concurrent :meth:requestlimit. - incoming_queue_size (
int) – Bounded unsolicited-message queue capacity; clamped to at least 1 and defaults to 256. Oldest items are dropped when it is full. - on_salt_change (
Callable[[int], None] | None) – Optional synchronous callback invoked after the sender accepts a server salt update; callback errors are logged. - reconnect_cooldown (
float) – Minimum paced delay after a young connection dies; clamped to zero or greater and defaults to one second.
Notes
Construction starts no tasks or network I/O. Methods share internal connect/send locks; use this instance from one event loop.