async_proxy/lib.rs
1//! # async-proxy
2//!
3//! The crate `async-proxy` provides a fast and flexible,
4//! as well as asyncronous implementation of proxy clients
5//! and proxy-related utilities.
6//!
7//! # Example
8//!
9//! ```
10//! use async_proxy::clients::socks4::no_ident::Socks4NoIdent;
11//! use async_proxy::general::ConnectionTimeouts;
12//! use async_proxy::proxy::ProxyConstructor;
13//! use tokio::net::TcpStream;
14//! use std::net::{SocketAddr, SocketAddrV4};
15//! use std::time::Duration;
16//! use std::process::exit;
17//!
18//! #[tokio::main]
19//! async fn main() {
20//! // The address of the proxy server that
21//! // will be used to connect through.
22//! // (We used a random proxy from `https://hidemy.name/en/proxy-list/`)
23//! let proxy_addr: SocketAddr = "104.248.63.15:30588".parse().unwrap();
24//!
25//! // The address of the destination service
26//! // that we will be connecting to through proxy.
27//! // (We used a tcp echo server from `http://tcpbin.org/`)
28//! let dest_addr: SocketAddrV4 = "52.20.16.20:30000".parse().unwrap();
29//!
30//! // Setting up timeouts
31//! let timeouts = ConnectionTimeouts::new(
32//! // Connecting timeout
33//! Duration::from_secs(8),
34//! // Write timeout
35//! Duration::from_secs(8),
36//! // Read timeout
37//! Duration::from_secs(8)
38//! );
39//!
40//! // Creating the socks4 constructor,
41//! // using which we will establish a connection
42//! // through proxy
43//! let socks4_proxy = Socks4NoIdent::new(dest_addr, timeouts);
44//!
45//! // Connecting to the stream and getting the readable and
46//! // writable stream, or terminating the script if it is
47//! // unable to connect
48//! let stream = TcpStream::connect(proxy_addr)
49//! .await
50//! .expect("Unable to connect to the proxy server");
51//!
52//! // Connecting to the service through proxy
53//! let stream = match socks4_proxy.connect(stream).await {
54//! Ok(stream) => {
55//! // Successfully connected to the service
56//! stream
57//! },
58//! Err(e) => {
59//! // -- handling the error -- //
60//! exit(1);
61//! }
62//! };
63//! }
64//! ```
65//!
66
67
68/// Module responsible for functionality
69/// related to proxy clients interfaces
70/// (eg. common definitions and traits)
71pub mod proxy;
72
73/// Module responsible for client implementations
74/// of known and most-used proxifications
75/// protocols, such as Socks4/5, HTTP(s)
76/// proxies
77pub mod clients;
78
79/// Module contains types and definitions
80/// that are widely and generally used
81/// over the library
82pub mod general;