ferogram_connect/proxy.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
15use tokio::net::TcpStream;
16
17use crate::error::ConnectError;
18use crate::transport_kind::TransportKind;
19
20/// Decoded MTProxy configuration.
21#[derive(Clone, Debug)]
22pub struct MtProxyConfig {
23 /// Proxy server hostname or IP.
24 pub host: String,
25 /// Proxy server port.
26 pub port: u16,
27 /// Raw secret bytes.
28 pub secret: Vec<u8>,
29 /// Transport variant; pass this as `config.transport`.
30 pub transport: TransportKind,
31}
32
33impl MtProxyConfig {
34 /// Open a TCP connection to the MTProxy host:port.
35 pub async fn connect(&self) -> Result<TcpStream, ConnectError> {
36 let addr = format!("{}:{}", self.host, self.port);
37 tracing::debug!("[ferogram::connect] MTProxy: opening TCP connection to {addr}");
38 TcpStream::connect(&addr).await.map_err(ConnectError::Io)
39 }
40
41 /// Socket address string `"host:port"`.
42 pub fn addr(&self) -> String {
43 format!("{}:{}", self.host, self.port)
44 }
45}