Fundamental abstractions and async read / write functions for SOCKS5 protocol and Relatively low-level asynchronized SOCKS5 server implementation based on tokio.
This repo hosts at socks5-impl
- Fully asynchronized
- Supports all SOCKS5 commands
- CONNECT
- BIND
- ASSOCIATE
- Customizable authentication
- No authentication
- Username / password
- GSSAPI
The entry point of this crate is socks5_impl::server::Server.
Check examples for usage examples.
This example uses the server feature. When that feature is disabled, the doctest still compiles with an empty fallback main.
#[cfg(feature = "server")]
use std::{net::SocketAddr, sync::Arc};
#[cfg(feature = "server")]
use socks5_impl::{
Result,
protocol::{Address, Reply},
server::{auth, ClientConnection, IncomingConnection, Server},
};
#[cfg(feature = "server")]
#[tokio::main]
async fn main() -> Result<()> {
let listen_addr: SocketAddr = "127.0.0.1:5000".parse()?;
let auth = Arc::new(auth::NoAuth);
let server = Server::bind(listen_addr, auth).await?;
loop {
let (conn, _) = server.accept().await?;
tokio::spawn(async move {
if let Err(err) = handle(conn).await {
eprintln!("{err}");
}
});
}
}
#[cfg(feature = "server")]
async fn handle(conn: IncomingConnection) -> Result<()> {
let conn = conn.authenticate().await?;
match conn.wait_request().await? {
ClientConnection::Connect(connect, addr) => {
let mut conn = connect.reply(Reply::Succeeded, Address::unspecified()).await?;
let _ = addr;
conn.shutdown().await?;
}
ClientConnection::Bind(bind, _) => {
let mut conn = bind.reply(Reply::CommandNotSupported, Address::unspecified()).await?;
conn.shutdown().await?;
}
ClientConnection::UdpAssociate(associate, _) => {
let mut conn = associate.reply(Reply::CommandNotSupported, Address::unspecified()).await?;
conn.shutdown().await?;
}
}
Ok(())
}
#[cfg(not(feature = "server"))]
fn main() {}GNU General Public License v3.0