Expand description
§socks5-impl
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
§Features
address: standaloneAddressandAddressTypetypes re-exported at the crate root.user-key: standaloneUserKeytype re-exported at the crate root.proxy-parameters: standaloneProxyParametersandProxyTypetypes; enablesaddressanduser-key.protocol: full SOCKS5 protocol API underprotocol; enablesaddress,user-key, andproxy-parameters.client: SOCKS5 client support.server: SOCKS5 server support.serde: serialization support.tokio: asynchronous I/O support.
To depend on a standalone type feature, disable default features:
socks5-impl = { version = "0.9.9", default-features = false, features = ["address"] }#[cfg(feature = "user-key")]
fn main() {
use socks5_impl::UserKey;
let key = UserKey::new("user", "password");
assert_eq!(key.username, "user");
}
#[cfg(not(feature = "user-key"))]
fn main() {}#[cfg(feature = "proxy-parameters")]
fn main() {
use socks5_impl::{ProxyParameters, ProxyType};
let parameters = "socks5://127.0.0.1:1080".parse::<ProxyParameters>().unwrap();
assert_eq!(parameters.proxy_type, ProxyType::Socks5);
}
#[cfg(not(feature = "proxy-parameters"))]
fn main() {}- Fully asynchronized.
- Supports all SOCKS5 commands: CONNECT, BIND, ASSOCIATE.
- Customizable authentication: no authentication, username/password, GSSAPI.
§Usage
The entry point of this crate is socks5_impl::server::Server.
Check examples for usage examples.
§Example
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,
Address,
protocol::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() {}§License
GNU General Public License v3.0
Modules§
Structs§
- Proxy
Parameters - UserKey
- Required for username/password authentication.
Enums§
- Address
- SOCKS5 Address Format
- Address
Type - Error
- The library’s error type.
- Proxy
Type
Traits§
Type Aliases§
- Result
- The library’s
Resulttype alias.