# SOCKS5 proxy The SOCKS5 module in `src/socks5.rs` implements RFC 1928 (SOCKS5 protocol) and RFC 1929 (username/password authentication). ## Purpose Handle the SOCKS5 handshake on the connector side, parse CONNECT requests, and resolve target addresses so that local applications can forward traffic through the tunnel. ## Supported features - CONNECT command only (no BIND or UDP) - No-auth and username/password authentication methods - IPv4 and domain name targets (no IPv6) - Target DNS resolution on the connector side ## Key abstractions | Type | File | Description | | ---- | ---- | ----------- | | `Socks5Target` | `src/socks5.rs` | Enum: `Ipv4(addr, port)` or `Domain { domain, port }` | | `Socks5State` | `src/socks5.rs` | State machine: ExpectGreeting → ExpectAuth → ExpectRequest → RequestReceived → Established → Closed | | `Socks5Error` | `src/socks5.rs` | Error enum for malformed input, unsupported methods, and parse failures | | `parse_greeting` | `src/socks5.rs` | Parse client greeting and choose auth method | | `parse_auth_request` | `src/socks5.rs` | Parse username/password auth request | | `parse_connect_request` | `src/socks5.rs` | Parse CONNECT request and extract target | | `resolve_target` | `src/socks5.rs` | Async DNS resolution of a `Socks5Target` to a `SocketAddr` | ## Integration The connector's `run_socks5_proxy` in `src/tunnel.rs` calls `socks5_handshake` (an async function in `src/tunnel.rs` that uses `src/socks5.rs` constants and helpers) for each incoming SOCKS5 connection. After handshake, it opens a stream via `StreamMux::open_stream` and forwards data bidirectionally. ## Key source files | File | Purpose | | ---- | ------- | | `src/socks5.rs` | SOCKS5 protocol constants, parsing, target resolution | | `src/tunnel.rs` | Async SOCKS5 handshake and proxy integration |