Skip to main content

ferogram_e2e/
transport.rs

1/*
2 * Copyright (c) 2026 Ankit Chaubey <ankitchaubey.dev@gmail.com>
3 * https://github.com/ankit-chaubey
4 *
5 * Project: ferogram
6 * Website: https://ferogram.dev
7 *
8 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
11 * This file may not be copied, modified, or distributed except according
12 * to those terms.
13 */
14
15//! Transport abstraction between the E2E layer and a Telegram client.
16//!
17//! `ferogram-e2e` does not depend on the `ferogram` client crate. It only needs
18//! to send RPCs, so any client can drive it by implementing [`E2eTransport`].
19//! `ferogram` implements it for `ferogram::Client` when its `e2e` feature is on.
20
21use std::future::Future;
22
23use ferogram_tl_types::RemoteCall;
24
25use crate::error::E2eError;
26
27/// Minimal RPC surface the secret chat layer needs from a Telegram client.
28///
29/// Implementations must be cheap to clone (typically a handle around an `Arc`).
30/// Failures are reported as [`E2eError::Transport`].
31pub trait E2eTransport: Clone + Send + Sync + 'static {
32    /// Invoke `req` on the client's home DC.
33    fn invoke<R>(&self, req: &R) -> impl Future<Output = Result<R::Return, E2eError>> + Send
34    where
35        R: RemoteCall + Send + Sync;
36
37    /// Invoke `req` on the datacenter `dc_id`.
38    ///
39    /// Secret chat files live on the DC named in `EncryptedFile::dc_id`, which
40    /// is not necessarily the home DC.
41    fn invoke_on_dc<R>(
42        &self,
43        dc_id: i32,
44        req: &R,
45    ) -> impl Future<Output = Result<R::Return, E2eError>> + Send
46    where
47        R: RemoteCall + Send + Sync;
48}