1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/// Module contains implementations
/// of the proxification protocol Socks4
/// and utilities related to the protocol
/// 
/// # Example
/// 
/// ```
/// use async_proxy::clients::socks4::no_ident::Socks4NoIdent;
/// use async_proxy::general::ConnectionTimeouts;
/// use async_proxy::proxy::ProxyConstructor;
/// use tokio::net::TcpStream;
/// use std::net::{SocketAddr, SocketAddrV4};
/// use std::time::Duration;
/// use std::process::exit;
///
/// #[tokio::main]
/// async fn main() {
///     // The address of the proxy server that
///     // will be used to connect through.
///     // (We used a random proxy from `https://hidemy.name/en/proxy-list/`)
///     let proxy_addr: SocketAddr = "104.248.63.15:30588".parse().unwrap();
///
///     // The address of the destination service
///     // that we will be connecting to through proxy.
///     // (We used a tcp echo server from `http://tcpbin.org/`)
///     let dest_addr: SocketAddrV4 = "52.20.16.20:30000".parse().unwrap();
///
///     // Setting up timeouts
///     let timeouts = ConnectionTimeouts::new(
///         // Connecting timeout
///         Duration::from_secs(8),
///         // Write timeout
///         Duration::from_secs(8),
///         // Read timeout
///         Duration::from_secs(8)
///     );
///
///     // Creating the socks4 constructor,
///     // using which we will establish a connection
///     // through proxy
///     let socks4_proxy = Socks4NoIdent::new(dest_addr, timeouts);
///
///     // Connecting to the stream and getting the readable and
///     // writable stream, or terminating the script if it is
///     // unable to connect
///     let stream = TcpStream::connect(proxy_addr)
///                            .await
///                            .expect("Unable to connect to the proxy server");
///
///     // Connecting to the service through proxy
///     let stream = match socks4_proxy.connect(stream).await {
///         Ok(stream) => {
///             // Successfully connected to the service
///             stream
///         },
///         Err(e) => {
///             // -- handling the error -- //
///             exit(1);
///         }
///     };
/// }
/// ```
pub mod socks4;

/// Module contains implementations
/// of the proxification protocol Socks5
/// and utilities related to the protocol
/// 
/// # Example
/// 
/// ```
/// use async_proxy::clients::socks5::{
///     Destination, no_auth::TcpNoAuth
/// };
/// use async_proxy::general::ConnectionTimeouts;
/// use async_proxy::proxy::ProxyConstructor;
/// use tokio::net::TcpStream;
/// use std::net::{
///     SocketAddr, Ipv4Addr
/// };
/// use std::time::Duration;
/// use std::process::exit;
/// 
/// #[tokio::main]
/// async fn main() {
///     // The address of the proxy server that
///     // will be used to connect through.
///     // (We used a random proxy from `https://hidemy.name/en/proxy-list/`)
///     let proxy_addr: SocketAddr = "72.11.148.222:56533".parse().unwrap();
/// 
///     // Setting up timeouts
///     let timeouts = ConnectionTimeouts::new(
///         // Connecting timeout
///         Duration::from_secs(8),
///         // Write timeout
///         Duration::from_secs(8),
///         // Read timeout
///         Duration::from_secs(8)
///     );
/// 
///     // The address of the destination service
///     // that we will be connecting to through proxy.
///     // (We used a tcp echo server from `http://tcpbin.org/`)
///     let dest_ipaddr: Ipv4Addr = Ipv4Addr::new(52, 20, 16, 20);
/// 
///     // The port of the destination service
///     const DEST_PORT: u16 = 30_000;
/// 
///     // Creating the socks5 constructor,
///     // using which we will establish a connection
///     // through proxy
///     let mut socks5_proxy = TcpNoAuth::new(Destination::Ipv4Addr(dest_ipaddr),
///                                           DEST_PORT, timeouts);
/// 
///     // Connecting to the stream and getting the readable and
///     // writable stream, or terminating the script if it is
///     // unable to connect
///     let stream = TcpStream::connect(proxy_addr)
///                            .await
///                            .expect("Unable to connect to the proxy server");
/// 
///     // Connecting to the service through proxy
///     let stream = match socks5_proxy.connect(stream).await {
///         Ok(stream) => {
///             // Successfully connected to the service
///             stream
///         },
///         Err(e) => {
///             // -- handling error -- //
///             exit(1);
///         }
///     };
/// 
///     // -- using `stream` -- //
/// }
/// ```

pub mod socks5;