Expand description
MTProto sender pool and retry policy for ferogram.
This crate is part of ferogram, an async Rust MTProto client built by Ankit Chaubey.
- Channel: t.me/Ferogram
- Chat: t.me/FerogramChat
Most users do not need this crate directly. The ferogram crate wraps
everything. Use ferogram-mtsender only if you are building a custom
dispatch layer or need direct access to the DC connection pool.
§What’s in here
MtpSender: Single-task MTProto sender. All TCP I/O (read, write, ping) runs inside one Tokio task that owns the unsplitTcpStream. Callers enqueue request bodies viaMtpSender::enqueueand receive results through a oneshot channel. This design eliminates mutex contention between reader and writer halves and ensures ACKs are flushed on every outgoing frame.DcPool: Per-DC connection pool capped at three slots. Requests are round-robined across liveConnSlots. The pool opens new connections on demand and replaces slots that have faulted.DcConnection: One encrypted connection to a single DC. Handles pendingmsgs_ackaccumulation and issuesping_delay_disconnectto keep the socket alive inside Telegram’s 75-second idle window.RetryPolicy/RetryLoop: Trait and executor for retry behaviour on RPC failures.AutoSleepsleeps throughFLOOD_WAITerrors;NoRetriesreturns the error immediately. Implement the trait to add exponential back-off or a circuit breaker.CircuitBreaker: Stops issuing requests to a DC that has failed repeatedly, giving the pool time to reconnect before hammering the server.spawn_sender_task/SenderHandle: Spawns the background I/O loop and returns a handle for enqueuing RPCs, subscribing toFrameEvents (updates), and issuingReconnectRequests.InvocationError/RpcError: Typed errors for failed RPC calls, including flood waits, server errors, and transport failures.
§Example: send an RPC via the pool
use ferogram_mtsender::{DcPool, InvocationError};
use ferogram_connect::TransportKind;
use ferogram_session::DcEntry;
use ferogram_tl_types::functions::help::GetConfig;
let dc_entries: Vec<DcEntry> = vec![]; // populate from your session
let mut pool = DcPool::new(2, &dc_entries, None, TransportKind::Full);
let raw = pool.invoke_on_dc(2, &dc_entries, &GetConfig {}).await?;
println!("raw response bytes: {}", raw.len());Re-exports§
pub use mtp_sender::MtpSender;pub use sender_task::FrameEvent;pub use sender_task::ReconnectRequest;pub use sender_task::RpcEnqueue;pub use sender_task::SenderHandle;pub use sender_task::spawn_sender_task;
Modules§
- mtp_
sender - Single-task MTProto sender.
- sender_
task - The sender task: a single
tokio::spawn-ed loop that ownsMtpSenderand is the only entity that touches the TCP socket.
Structs§
- Auto
Sleep - Automatically sleep on
FLOOD_WAITand retry once on transient I/O errors. - Circuit
Breaker - A
RetryPolicythat stops retrying afterthresholdconsecutive failures and stays silent for acooldownwindow before resetting. - Conn
Slot - One slot in the per-DC connection pool.
- DcConnection
- DcPool
- Pool of per-DC authenticated connections. Each DC holds up to MAX_CONNS_PER_DC slots. The pool lock is dropped before any network I/O so concurrent callers don’t serialize on it.
- NoRetries
- Never retry: propagate every error immediately.
- Retry
Context - Context passed to
RetryPolicy::should_retryon each failure. - Retry
Loop - Drives the retry loop for a single RPC call.
- RpcError
- An error returned by Telegram’s servers in response to an RPC call.
Enums§
- Invocation
Error - The error type returned from any
Clientmethod that talks to Telegram.
Traits§
- Retry
Policy - Controls how the client reacts when an RPC call fails.