How aeroxy/tunnix works
1. What this repo is
- tunnix is a single Rust binary that runs in two major modes: server and client.
- Its core job is to carry SOCKS5, HTTP proxy, remote shell, and file-transfer traffic through an HTTP/SSE tunnel, encrypted end-to-end.
2. Top-level architecture
- The client sits next to local apps and exposes a local proxy port.
- The server sits on the remote host and exposes HTTP endpoints.
- Traffic flows: local app → client listener → encrypted tunnel over HTTP/SSE → server router → target TCP service.
3. Client ingress boundary
- proxy.rs accepts incoming TCP connections on the local port and peeks the first byte to auto-detect protocol.
- socks5.rs handles SOCKS5 CONNECT sessions.
- http_proxy.rs handles HTTP proxying, including HTTP CONNECT and plain HTTP forwarding.
- This means the client is the protocol adapter between local apps and the tunnel.
4. Connection handling and multiplexing
- relay.rs is the bidirectional pipe between a local connection and a tunnel session.
- It tracks connection IDs and lets many local connections share one tunnel transport.
- The tunnel is session-based rather than one TCP socket per target connection.
5. Tunnel transport
- tunnel.rs implements the client side of the HTTP/SSE transport.
- The transport uses POST /send/{session} for encrypted binary payloads and GET /stream/{session} as an SSE event stream.
- This design avoids WebSockets and works in environments that allow plain HTTP but block direct TCP.
6. Server-side HTTP boundary
- server.rs is the remote HTTP server, built on hyper.
- It strips optional path prefixes, routes session traffic, and exposes HTTP endpoints such as health checks.
- It is the network-facing boundary on the remote host; everything past it is internal tunnel/session handling.
7. Cryptography and shared wire format
- crypto.rs provides the end-to-end protection layer.
- The repo uses Argon2id to derive keys from the shared password and ChaCha20-Poly1305 for authenticated encryption.
- protocol.rs likely defines the framing/messages that both sides use inside the encrypted channel.
8. Optional remote execution path
- exec.rs implements remote-exec, which is an opt-in shell/command execution channel over the same tunnel.
- On the server side it requires explicit authorization via --allow-exec.
- The PTY-based design matters architecturally: it is interactive, terminal-aware, and Unix-only.
9. Optional file transfer path
- transfer.rs and archive.rs implement push/pull.
- Files and directories are packed into tar archives, compressed with zstd, then sent through the encrypted tunnel.
- This is a separate application-layer stream from proxy traffic, but it reuses the same auth and transport infrastructure.
10. Configuration and hot reload
- config.rs loads CLI flags, config files, defaults, and environment-based password input.
- reload.rs watches config changes and reloads selected fields without restart.
- Hot-reloadable settings include password, headers, path prefix, and some response text; listener addresses and logging level require restart.
11. Important integration boundaries
- The client boundary is “local app protocol termination” for SOCKS5 and HTTP proxy.
- The server boundary is “HTTP ingress” and “remote TCP egress” to target services.
- A reverse proxy or platform URL may sit in front of the server; path_prefix and custom headers exist specifically to survive those deployment constraints.
12. Tests and operational packaging
- tests/transfer_roundtrip.rs validates the archive/transfer path.
- tests/reconnect_on_url_change.rs covers tunnel resilience when the server URL changes.
- The repo also includes a Homebrew formula and Cargo-based build/release tooling, indicating it is packaged as a deployable CLI binary rather than a library.
Main entry points: server.rs Server · main.rs Main · proxy.rs Local proxy · tunnel.rs Tunnel
Components 18
Client side
Local protocol adapters and tunnel relay
- Local proxy · Accepts local TCP connections and auto-detects protocol
src/proxy.rs - SOCKS5 · Handles SOCKS5 CONNECT sessions
src/socks5.rs - HTTP proxy · Handles HTTP proxying and CONNECT forwarding
src/http_proxy.rs - Relay · Bridges local sockets to shared tunnel sessions
src/relay.rs - Local apps · Applications using SOCKS5 or HTTP proxy locally
Tunnel core
Shared encrypted session and wire format
Server side
HTTP ingress and remote execution/transfer handlers
- Server · HTTP boundary that routes sessions and endpoints
src/server.rs - Remote exec · Runs interactive shell sessions when explicitly allowed
src/exec.rs - Transfer · Implements push and pull over the tunnel
src/transfer.rs - Archive · Packs files and directories for transfer
src/archive.rs - TCP target · Destination services reached from the server side
- Health · Operational HTTP check exposed by the server
Config and ops
Runtime configuration, reload, and packaging
Connections 22
- Main → Config: loads · Startup configuration and runtime options
- Main → Local proxy: client mode · Starts local listener and tunnel client
- Main → Server: server mode · Starts remote HTTP ingress
- Main → Reload: enables · Optional hot reload of selected settings
- Local proxy → SOCKS5: routes · Dispatches SOCKS5 sessions
- Local proxy → HTTP proxy: routes · Dispatches HTTP proxy sessions
- Local proxy → Relay: hands off · Passes accepted connections into the shared relay
- Local apps → Local proxy: connects to · Local applications speak proxy protocols
- Relay → Tunnel: opens session · Multiplexes many local connections over one tunnel transport
- Tunnel → Protocol: frames · Encodes session messages into the shared wire format
- Tunnel → Crypto: encrypts · Protects all tunnel payloads end to end
- Server → Crypto: decrypts · Uses shared password-derived keys for ingress traffic
- Server → Protocol: parses · Understands the tunneled message framing
- Server → TCP target: forwards to · Connects remote sessions to target TCP services
- Server → Remote exec: routes · Hands exec sessions to the interactive PTY path
- Server → Transfer: routes · Hands file transfer sessions to the transfer path
- Transfer → Archive: packs · Archives and compresses payloads before sending
- Reload → Config: updates · Applies hot-reloadable configuration fields
- Config → Server: configures · Supplies headers, prefix, and server behavior
- Config → Tunnel: configures · Supplies password and transport settings
- Formula → Main: packages · Distribution packaging for the CLI binary
- Health → Server: served by · Operational endpoint on the HTTP boundary