Skip to content
Edit this page

Architecture and Crates

Wind decomposes a proxy runtime into focused Rust crates (Edition 2024, MSRV 1.85). Data-plane traits are decoupled from concrete protocols, allowing applications such as the standalone wind binary, TUIC, and Breeze to assemble runtimes declaratively via App and Plugin.

Layered Architecture

+----------------------------------------------------------------------+
|             Application Assembly (wind CLI / tuic / breeze)          |
+----------------------------------------------------------------------+
|  Protocols      wind-socks      wind-tuic          wind-naive        |
+----------------------------------------------------------------------+
|  Services    wind-base   wind-quic   wind-acl   wind-dns  wind-acme  |
|                         wind-geodata  wind-rule                      |
+----------------------------------------------------------------------+
|  Core Traits                      wind-core                          |
+----------------------------------------------------------------------+

A typical flow traverses three stages:

  1. Inbound (AbstractInbound) accepts a client connection, performs protocol handshake and authentication (optionally via InboundHooks), and builds a FlowContext carrying target address, network type, source address, and user identity.
  2. Dispatcher (Dispatcher<R>) routes the flow:
  3. If the inbound is pinned to an outbound (with_outbound), it forwards directly without consulting the router.
  4. Otherwise it invokes the statically dispatched Router to obtain RouteAction::Forward(tag) or RouteAction::Reject(reason). Security-enforcing routers such as wind-acl also pin the validated resolved IP via route_with_target.
  5. For UDP flows, Dispatcher waits for the first UdpPacket, routes using its target, replays the first packet, and invokes prepare_udp_target on every subsequent datagram.
  6. Outbound (Outbound) dials the target or upstream relay and transfers bytes via copy_bidirectional or UdpStream.

Workspace Crates

The workspace contains 13 member crates. The top-level wind binary is licensed under AGPL-3.0-or-later; library crates are licensed under MIT OR Apache-2.0 (wind-naive also carries an MPL-2.0 notice):

Crate Default features Key responsibilities Verification
wind [] Standalone CLI binary and runtime plugin: YAML/TOML config, socks/http/mixed/tunnel inbounds, socks/tuic/naive/load-balance outbounds —
wind-core ["quic"] Core abstractions: App/Plugin, Dispatcher/Router, AbstractInbound/Outbound, FlowContext, TargetAddr, ActiveConnections, InboundHooks, StatsCollector, copy_bidirectional, Resolver Verus
wind-base None Protocol-agnostic primitives: DirectOutbound, LazyOutbound, LoadBalanceOutbound, TunnelTcpInbound/TunnelUdpInbound Verus
wind-quic ["quiche"] Backend-neutral QUIC handles (QuicConnection/QuicSendStream/QuicRecvStream) unifying quinn and tokio-quiche, plus CertStore, ECH, and h3_adapter —
wind-tuic ["server", "client", "quinn", "quiche", "aws-lc-rs", "masquerade"] TUIC v5 server and client generic over wind-quic, with dual backends, UDP fragmentation/reassembly, and HTTP/3 masquerading Verus + Vest
wind-socks None SOCKS4/4a/5 and HTTP/1.1 inbounds (including Mixed first-byte sniffing, auth, and UDP ASSOCIATE) plus SOCKS5 TCP/UDP outbound Verus + Vest
wind-naive [] NaïveProxy outbound over cronet-rs (HTTP/2 & QUIC CONNECT + padding), UoT v2 UDP, and SocketPolicy Verus + Vest
wind-acl None nftables-inspired ACL IR (Ruleset/Chain/NamedSet/VerdictMap), Verus-verified optimizer, apernet & metacubex parsers, AclEngine, loopback/private guards Verus
wind-rule None Leaf crate with zero internal Wind dependencies: MetaCubeX/Clash rule parser and MatchContext evaluator —
wind-geodata None Compiles geosite.dat / geoip.dat into 16-byte-header rkyv zero-copy memmap2 snapshots validated on load Verus
wind-dns None hickory-resolver custom DNS (UDP/TCP/DoT/DoH) with StackPrefer filtering —
wind-acme ["aws-lc-rs", "resolver"] ACME HTTP-01 provisioning and renewal (resolver in-memory for rustls/Quinn; http01 file-backed for Quiche) plus ECDSA P-256 self-signed cert generation —
wind-test ["aws-lc-rs"] Cross-crate integration harnesses and benchmarks (arc_bench, acl_routing, tcp_relay) —

The root Cargo.toml pins quiche, tokio-quiche, and datagram-socket via [patch.crates-io] to a single revision of rust-proxy/quiche, while quinn tracks the bbrv3 branch paired with quinn-congestions.

wind-core Core Abstractions

Application Lifecycle (App / Plugin)

App<R: Router> composes the process around a shared AppContext (TaskTracker + CancellationToken):

  • Composable plugins: add_plugin, add_outbound, set_router, add_inbound_with, add_inbound_with_outbound, and own_running_inbound (for transport-dependency listeners started before the main build completes).
  • Authentication and hooks:
  • TuicAuthenticator::lookup(&Uuid) supplies (UserId, password_bytes) for constant-time token verification in core;
  • UserPassAuthenticator::authenticate(user, pass) serves HTTP Basic and SOCKS5 auth (StaticUserPass performs non-short-circuiting constant-time comparison on both fields);
  • ConnectionHooks provides on_connect, on_authenticated (returning ConnectDecision::Accept or Reject(reason)), and on_disconnect, automatically fanned out when multiple hooks are registered.
  • Traffic accounting and active connections:
  • StatsCollector combines DashMap<UserId, UserStatsData> with portable_atomic::AtomicU64 (32-bit safe). reset_all() atomically drains counters and prunes zero entries; restore() rolls batches back losslessly if TrafficSink::submit fails.
  • Sampling interval (set_sample_interval) and flush interval (set_flush_interval, default 60s) are independently configurable.
  • ActiveConnections maintains O(1) per-user counts (count_for). kick_user cancels all tokens for a user while keeping entries until each connection finishes deregistering (fail-closed quota accounting).
  • Graceful shutdown: On Ctrl-C, SIGTERM, or token cancellation, App::run runs a bounded final traffic flush (up to 3 retries, 100ms apart), cancels the root token, closes TaskTracker, and drains tasks up to shutdown_timeout (default 10s).

Stream Traits and Bidirectional Relay

  • TCP: AbstractTcpStream requires AsyncRead + AsyncWrite + Send + Unpin (intentionally omitting Sync for compatibility with quiche's PollSender).
  • UDP: UdpStream pairs mpsc channels carrying UdpPacket { source, target, payload }.
  • Bidirectional copy with half-close: copy_bidirectional(a, b, half_close_timeout) uses 64 KiB per-direction buffers so backpressure in one direction never stalls the reverse direction. Observing EOF on either reader drains its paired writer, calls poll_shutdown to propagate FIN, and arms the half-close idle timer (Duration::ZERO disables it; progress in either direction renews the deadline).