Skip to main content

proxychains_masq/proxy/
mod.rs

1pub mod http;
2pub mod https;
3pub mod raw;
4pub mod socks4;
5pub mod socks5;
6
7use std::{fmt, net::IpAddr};
8
9use tokio::io::{AsyncRead, AsyncWrite};
10
11/// A type-erased async stream that supports both reading and writing.
12///
13/// Used throughout the chain engine so that heterogeneous stream types —
14/// plain [`tokio::net::TcpStream`], TLS-wrapped streams, etc. — can all flow
15/// through the same proxy chaining code without monomorphization.
16pub trait AsyncStream: AsyncRead + AsyncWrite + Send + Unpin {}
17impl<T: AsyncRead + AsyncWrite + Send + Unpin> AsyncStream for T {}
18
19/// An owned, heap-allocated [`AsyncStream`].
20pub type BoxStream = Box<dyn AsyncStream>;
21
22/// The target of a proxy connection: either a resolved IP address or a hostname.
23#[derive(Debug, Clone)]
24pub enum Target {
25    Ip(IpAddr, u16),
26    Host(String, u16),
27}
28
29impl Target {
30    /// Return the destination port.
31    pub fn port(&self) -> u16 {
32        match self {
33            Target::Ip(_, p) | Target::Host(_, p) => *p,
34        }
35    }
36}
37
38impl fmt::Display for Target {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            Target::Ip(ip, port) => write!(f, "{ip}:{port}"),
42            Target::Host(host, port) => write!(f, "{host}:{port}"),
43        }
44    }
45}