12 releases

0.3.6 Sep 12, 2024
0.3.5 Sep 9, 2024
0.3.4 Aug 18, 2024
0.2.2 Jun 19, 2024
0.1.0 May 16, 2024

#1647 in Asynchronous

Download history 16/week @ 2024-06-23 3/week @ 2024-06-30 6/week @ 2024-07-07 13/week @ 2024-07-28 163/week @ 2024-08-11 413/week @ 2024-08-18 10/week @ 2024-08-25 1/week @ 2024-09-01 256/week @ 2024-09-08 119/week @ 2024-09-15 24/week @ 2024-09-22 18/week @ 2024-09-29 4/week @ 2024-10-06

181 downloads per month
Used in socky

MIT license

21KB
411 lines

Proxied

Async SOCKS4/5 and HTTP(s) client connectors for Rust

Features

  • HTTP/HTTPS proxy
  • SOCKS4/5 proxy
  • Basic authorization for each type of proxy
  • Fully async
  • Proxy address as DNS Name
  • Round-robin dispatch in case of multiple addresses

Getting started

Add the following to your Cargo.toml file:

[dependencies]
proxied = "0.3"

Example

use proxied::{Proxy, TCPConnection, NetworkTarget};

#[tokio::main]
async fn main() {
    let proxy = Proxy::from_str("socks5://127.0.0.1:1080").unwrap();
    let connection = proxy.connect(NetworkTarget::Domain {domain: "tcpbin.com", port: 4242}).await.unwrap();

    // Send data to the echo server
    let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9];
    connection.write(data).await.unwrap(); 

    // Read the data back
    let mut buf = vec![0; data.len()];
    connection.read_exact(&mut buf).await.unwrap();

}

lib.rs:

Proxied

Asynchronous proxy TCP connector

Includes:

  • No unsafe code
  • SOCKS4/5 and HTTP(s) proxies support
  • Single structure for both types of proxies
  • TCPStream-like connection (see TCPConnection)
  • Password authentication

How-to

Main entrypoint is Proxy structure. It contains connection data about proxy like protocol, address port and credentials. Additionally it supports IP refreshment link, although user is expected to manually request it.

To create a TCP connection, call Proxy::connect_tcp. After it is created, it can be used just like regural TCP stream, as it implements AsyncRead and AsyncWrite.

Dependencies

~4–12MB
~132K SLoC