ferogram-mtsender 0.6.5

MTProto sender pool and retry policy for ferogram
Documentation

ferogram-mtsender

MTProto sender pool and retry policy for ferogram.

Crates.io Telegram Channel Telegram Chat docs.rs License

Manages DC connections and drives the retry loop for RPC calls. ferogram sits on top of this; most users never touch it directly.

ferogram re-exports the retry types. For installation instructions see the ferogram README.

What it does

  • DcPool: one DcConnection per DC, created on demand
  • DcConnection: owns the sender loop for a single DC
  • Retry policy trait with built-in AutoSleep, NoRetries, and CircuitBreaker
  • FLOOD_WAIT and SLOWMODE_WAIT auto-sleep with jitter
  • Exponential backoff for transient I/O errors

Retry policies

AutoSleep

Sleeps on FLOOD_WAIT and retries once on I/O errors. Default policy used by ferogram.

use ferogram_mtsender::AutoSleep;
use std::time::Duration;

let policy = AutoSleep {
    threshold: Duration::from_secs(60),
    io_errors_as_flood_of: Some(Duration::from_secs(1)),
};

NoRetries

Propagates every error immediately.

use ferogram_mtsender::NoRetries;
let policy = NoRetries;

CircuitBreaker

Trips after a set number of consecutive failures and stays open for a cooldown window.

use ferogram_mtsender::CircuitBreaker;
use std::time::Duration;

let policy = CircuitBreaker::new(5, Duration::from_secs(30));

Custom policy

use ferogram_mtsender::{RetryPolicy, RetryContext};
use std::ops::ControlFlow;
use std::time::Duration;

struct MyPolicy;

impl RetryPolicy for MyPolicy {
    fn should_retry(&self, ctx: &RetryContext) -> ControlFlow<(), Duration> {
        if ctx.fail_count.get() < 3 {
            ControlFlow::Continue(Duration::from_secs(1))
        } else {
            ControlFlow::Break(())
        }
    }
}

Feature flags

Flag What it enables
metrics RPC/connection instrumentation (counters, histograms, gauges) via the metrics crate. Off by default; a zero-cost no-op shim is used otherwise.

Stack position

ferogram
└ ferogram-mtsender  <-- here
  └ ferogram-connect

License

This project is licensed under either the MIT License or Apache License 2.0, at your option. See LICENSE-MIT and LICENSE-APACHE for details.

Author: Ankit Chaubey (@ankit-chaubey)