Skip to content
aimalyginPublic

About

Mobile-first Rust implementation of VLESS, REALITY, Vision, Trojan, Shadowsocks 2022, VMess AEAD, Hysteria 2, WireGuard, TUN, routing, and DNS for embeddable proxy clients.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

54 stars

Watchers

1 watching

Forks

xray-rust

A Rust client core that reads Xray-style configurations, with Swift and Kotlin SDKs for VPN apps on iOS, tvOS, macOS and Android.

CI Release Maven Central License: MPL 2.0 Platforms Rust

Website · Mobile SDK · Kotlin Multiplatform · Status · Config compatibility · Benchmarks · Support the project

The development compatibility reference is Xray-core v26.11.9. Dated release and benchmark results retain their original references.

Support the project

If you find this project useful, consider supporting its development with a donation:

  • TON (TON network): UQCIpU1qagwDltuqPUZh4EuI2zXvismk6esCCTWUVphj_o4y
  • ETH (Ethereum network): 0x96A9a65E188c439a95267a3dA6920884C530f57f
  • BTC (Bitcoin network): bc1qxxk42z2ty8wx702sk5cammwhchl95y39kf2wdc
  • SOL (Solana network): D4xFX2GwPniSetHZWn2XRTBaSM6m1k1wMtacr6TMVHQD

Thank you for your support!

Why xray-rust

  • Rust core with bounded resources. Flow budgets, bounded queues, timeouts and backpressure bound the TUN path and relays; config, wire-format and FFI lifecycle code has fuzz targets.
  • Xray-compatible configs. VLESS with REALITY, xtls-rprx-vision, XHTTP and Mux, plus VMess AEAD, Trojan, Shadowsocks (2022 and classic AEAD), Hysteria 2 and WireGuard clients. The parser accepts a documented subset and rejects unsupported fields with their JSON path instead of guessing.
  • Built for mobile. A stable C ABI with Swift Package and Android AAR adapters, a reference NEPacketTunnelProvider and VpnService, share-link import, live connection inventory and traffic counters, and diagnostics.
  • Measured against Xray-core. Published, reproducible benchmarks: 4.6 MiB idle memory against 27.4 MiB for Xray-core, and 22.1 against 19.1 Gbps through VLESS + REALITY + Vision (details).
  • Checked against the reference. CI replays Go-oracle wire fixtures, and release candidates plus a weekly job run interoperability tests against a pinned Xray-core (verification).

Note

xray-rust is a client-side core. Security audits are done with Fable 5.1 and GPT-6 Sol Daybreak, not by an independent auditor. "Supported" means implemented and covered by tests, not complete behavioral parity with every Xray-core release; see project status and Xray-core differences.

At a glance

Client outbounds and the transports and security layers each one can use. Every cell covers a documented subset; configuration compatibility lists the accepted values.

Outbound Stream transports TLS REALITY Vision UDP Mux / XUDP
VLESS RAW, WebSocket, HTTPUpgrade, gRPC, XHTTP (H1/H2/H3) ✅ ✅ RAW, gRPC, XHTTP ✅ RAW¹ ✅ ✅²
VMess AEAD RAW, WebSocket, HTTPUpgrade, gRPC, XHTTP ✅ ✅ RAW, gRPC, XHTTP ➖ ✅ ✅²
Trojan RAW, WebSocket, HTTPUpgrade, gRPC, XHTTP ✅ ✅ RAW, gRPC, XHTTP ➖ ✅ ✅²
Shadowsocks 2022, classic AEAD³ RAW, WebSocket, HTTPUpgrade, gRPC, XHTTP ✅ ✅ RAW, gRPC, XHTTP ➖ ✅ ✅²
Hysteria 2 Own QUIC carrier, Salamander, port hopping QUIC ➖ ➖ ✅ ➖
WireGuard Own UDP carrier ➖ ➖ ➖ ✅ ➖
SOCKS5 RAW, WebSocket, HTTPUpgrade, gRPC, XHTTP ✅ ✅ RAW, gRPC, XHTTP ➖ ✅ ❌
HTTP CONNECT RAW, WebSocket, HTTPUpgrade, gRPC, XHTTP ✅ ✅ RAW, gRPC, XHTTP ➖ ❌ ❌
Freedom, blackhole, DNS Direct ➖ ➖ ➖ ✅ ➖

✅ supported subset · ❌ not supported · ➖ not applicable. ¹ Direct mode over RAW with TLS or REALITY; on other transports Vision requires VLESS encryption, as in Xray. ² Over XHTTP, and for VLESS with xtls-rprx-vision, Mux carries UDP children only, as the pinned Xray-core server accepts only those there. ³ aes-128-gcm, aes-256-gcm, chacha20-poly1305 and xchacha20-poly1305, with Xray's aliases; no stream ciphers or none.

Inbounds: SOCKS5 (no-auth or RFC 1929 password, CONNECT and UDP ASSOCIATE), HTTP CONNECT, a TUN packet API or file descriptor with a userspace TCP/UDP stack, and Linux TPROXY. Routing and DNS: Xray field rules with geosite/geoip, balancers with observatory health checks, DoT/DoH/DoQ, fake IP and hot-swappable routing policy. Security extras: uTLS-shaped ClientHellos, VLESS encryption (ML-KEM-768/X25519), ClientHello fragmentation, UDP noise, and UDP port hopping for Hysteria 2 and XHTTP over HTTP/3.

Not supported yet

Mirrors the notable unsupported areas in project status:

  • Shadowsocks stream ciphers and none, legacy VMess authentication, and server-side proxy protocols;
  • generic HTTP/2, QUIC and KCP transports, and stream transports beyond raw, WebSocket, HTTPUpgrade, gRPC and XHTTP;
  • the reverse proxy's portal (server) side, observatory command/API services, regex leastLoad costs, and outbound chaining outside the documented transport-layer TCP subset;
  • HTTP inbound transparent proxy mode;
  • full Xray DNS, policy/statistics, sniffing, and routing semantics.
Detailed scope and important limits
Area Implemented Important limits
Local inbounds SOCKS5 no-auth or RFC 1929 password CONNECT and UDP ASSOCIATE, HTTP CONNECT and plain HTTP forwarding with optional Basic accounts, TUN Password-protected SOCKS UDP requires a declared client endpoint; no HTTP transparent proxy mode or server-side Xray protocols
Outbounds Freedom/direct, Xray-compatible blackhole and loopback, VLESS, Hysteria 2, WireGuard, Trojan, Shadowsocks 2022 and classic AEAD (aes-128-gcm, aes-256-gcm, chacha20-poly1305, xchacha20-poly1305), VMess AEAD, SOCKS5 CONNECT and UDP ASSOCIATE with optional RFC 1929 credentials, HTTP/1.1 and HTTP/2 CONNECT with optional Basic credentials and custom headers, DNS, health-aware selector groups including bounded leastLoad, and validated transport-layer TCP chaining No Shadowsocks stream ciphers or none, legacy VMess authentication, SOCKS outbound Mux, HTTP outbound UDP, server-side proxy protocols, or chaining outside the documented TCP subset
Security and flow TLS and REALITY with uTLS-shaped ClientHellos, xtls-rprx-vision, VLESS UDP and XUDP paths, and bounded Mux.Cool/XUDP pooling for VLESS, Trojan, Shadowsocks (2022 and AEAD) and VMess Only the documented config subset; REALITY rejects the 14 fingerprints that carry no X25519 key share and warns on those without the X25519MLKEM768 share v26.10.21 servers require, while plain TLS accepts all 61
Routing and DNS Field rules with domain/IP/network/port matchers, geosite/geoip, atomic rule/geodata snapshot replacement, Xray routing.balancers plus bounded observatory URL health checks and leastLoad, cycle-free TCP outbound graph edges, Xray-style DNS server selection including routed tls:// DoT, routed/local HTTP/2 DoH, and provider-local quic+local:// DoQ, routed multi-address resolution, TTL-aware positive/negative cache with bounded stale-while-revalidate, dns.hosts, bounded fake IP, and DNS-outbound Direct/Drop/Return/Hijack policy Full config and outbound/balancer topology replacement still requires a new core; no UDP/protocol-layer outbound chaining, per-server cache policy, or full Xray DNS/routing parity
Mobile Swift Package/Xcode sample for iOS, tvOS, and macOS; Android library and VpnService adapter Signing, entitlements, VPN consent, foreground policy, and release packaging remain host-app responsibilities
Management Development ABI 1.17 plus Swift/Kotlin expose protocol capability discovery, shared profile import, on-demand outbound probes and cancellation of probes in flight alongside routing-policy replacement/snapshots, typed SOCKS TCP/UDP, HTTP TCP, and TUN TCP/UDP connection inventory, addressable close, per-outbound accounting with live bytes of active flows, and equivalent typed TUN diagnostic queues Policy updates affect new flows only; inventory is live and accounting is process-lifetime cumulative, with live bytes of active flows reported separately; no persistent connection history

The 0.8 implementation and acceptance record distinguishes passing host/CI checks from remaining physical-device gates, and the changelog lists what main adds after the latest release.

Platforms

Platform Integration Artifact
iOS 15+ Swift Package, SwiftUI sample host, Packet Tunnel provider Static XCFramework device and universal simulator slices
tvOS 17+ Swift Package, SwiftUI sample host, Packet Tunnel provider Static XCFramework device and universal simulator slices
macOS 13+ Swift Package, app/menu-bar sample, Packet Tunnel provider Universal arm64 + x86_64 static XCFramework slice
Android API 24+ Kotlin wrapper, JNI bridge, VpnService adapter Four-ABI AAR with 16 KiB-aligned native libraries

These are reference integrations: production apps provide their own signing, entitlements or manifest policy, VPN consent and distribution. The lower-level Apple products also run on macOS 11 and 12; see platform status.

Architecture

flowchart TB
    subgraph Host["Host application"]
        App["iOS / tvOS / macOS app<br/>Android app"]
        SDK["SDK<br/>Swift: XrayMobileAdapter, XrayAppleTunnel<br/>Kotlin: XrayCore, XrayVpnService"]
        App --> SDK
    end

    SDK -->|"JSON config, packets or TUN fd,<br/>socket protection"| FFI["xray-ffi<br/>C ABI + Tokio runtime"]
    CLI["xray-cli<br/>xray-rust run"]
    FFI --> Config["xray-config<br/>Xray JSON subset, geodata"]
    CLI --> Config
    Config --> Core
    FFI -->|"lifecycle, packets"| Core
    CLI --> Core

    subgraph Core["xray-core-rs"]
        Inbounds["Inbounds<br/>SOCKS5 · HTTP · TUN (smoltcp)"]
        Routing["xray-routing<br/>rules, balancers"]
        DNS["DNS<br/>DoT · DoH · DoQ · fake IP"]
        Outbounds["Outbounds · xray-proxy<br/>VLESS · VMess · Trojan · Shadowsocks<br/>Hysteria 2 · WireGuard"]
        Transports["xray-transport<br/>TCP · TLS/uTLS · REALITY<br/>WS · gRPC · XHTTP · QUIC"]
        Inbounds --> Routing
        Routing --> DNS
        Routing --> Outbounds
        Outbounds --> Transports
    end

    Transports --> Net(("Network"))
Loading

The host owns the VPN interface, consent and profile storage; the core parses the profile once per handle, routes each flow and dials the selected outbound. When the Android core is created with a VpnService, every outbound socket passes through VpnService.protect(fd) before use. See architecture for crate boundaries and data paths, and the C ABI contract for lifecycle and threading.

Benchmarks

Synthetic same-host comparison from the 2026-10-30 three-engine group: xray-rust 123b9d8d against Xray-core v26.10.21 and stable sing-box v1.14.4 on an Apple M6 with 32 GB RAM and macOS 27.0. Values are medians of five release runs.

Scenario (lower is better unless noted) xray-rust Xray-core sing-box
Idle memory, MiB 4.6 27.4 30.8
1,000 idle SOCKS flows, MiB 22.7 78.6 omitted
Memory with real geodata, MiB 9.9 33.4 unsupported
VLESS + REALITY + Vision bulk, Gbps (higher is better) 22.1 19.1 omitted
VLESS + REALITY + Vision CPU, ms/GiB 480 500 omitted
UDP round trip, µs 23 41 29
Plain TCP bulk through SOCKS, Gbps (higher is better) 90.4 73.3 100.0
Reconnect burst setup, µs 1,333 987 1,313
Peak resident set size, lower is better. Idle: xray-rust 4.6 MiB, Xray-core 27.4, sing-box 30.8. 100 idle flows: xray-rust 7.0, Xray-core 34.6, sing-box 37.6. 1000 idle flows: xray-rust 22.7, Xray-core 78.6, sing-box omitted. Bulk TCP throughput through a VLESS + REALITY + Vision tunnel, higher is better: xray-rust 22.1 Gbps and Xray-core 19.1; stable sing-box omitted at the recorded client compatibility boundary. Peak memory with real geodata loaded, lower is better: xray-rust 9.9 MiB and Xray-core 33.4 MiB.

What these numbers do not show:

  • They are localhost process microbenchmarks, not WAN, packet loss, mobile energy or TUN measurements.
  • Stable sing-box is omitted from REALITY: its client removes the X25519MLKEM768 key share that v26.9.8 and later servers require. Its 1,000-flow runs did not complete on this host.
  • Setup is slower than Xray-core's: xray-rust replies to SOCKS CONNECT after routing and dialing, Xray-core before them (see the measurement asymmetry note in benchmark methodology).
  • At 123b9d8d, 32 parallel XHTTP H3 uploads peaked at 163.3 MiB against 49.9 for Xray-core; a later shared send budget brought that to 87.7 MiB (send-budget report).
  • In the 0.8 protocol comparison (1050 full-client trials) memory is lower throughout, but Shadowsocks 2022 and VMess bulk throughput and CPU targets remain unmet; see the 0.8 performance record.

Latency, CPU, setup and stream-transport tables are in the dated result group; the method is in benchmark methodology. For 0.7 regression checks and Hysteria2/WireGuard comparisons, see the 0.7 performance record. The 2026-08-31 RC4 group, the earlier Xray-core v26.5.9 and the xray-rust DNS charts remain available as historical evidence.

Performance-branch and XHTTP H3 memory reports (2026-10-30/31)

The 2026-10-30 performance-branch report compares main at 9b06d374 with the branch at 123b9d8d on one Apple M6, against the same Xray v26.10.21 server and driver: 200 scenarios, five runs per version, 2,000 accepted trials. WebSocket uploads use 53–59% less CPU per byte, one-flow gRPC downloads run 2.2× faster, XHTTP H3 uploads run 34–71% faster at 23–46% less CPU, and XHTTP H1 uploads through TUN peak at up to 62% less memory. Faster gRPC and XHTTP H3 flows also hold more data, up to 9.6 → 31.9 MiB for eight XHTTP H3 uploads through TUN, and XHTTP H1 uploads through TUN cost 9.5% more CPU. The report explains each cost and keeps every repeat and rejected attempt; 131/156 bulk cases change throughput by at most 5%. This is a Rust before/after comparison; the earlier v26.10.21 migration comparison remains with its erratum. A later change on the branch shares one send budget between XHTTP H3 uploads: 32 parallel uploads now peak at 87.7 instead of 162.1 MiB RSS and 32 duplex transfers at 78.2 instead of 140.6, at the same throughput (send-budget report). On Linux, where quinn reserved 2.9 MiB of receive buffer for every XHTTP H3 connection, 32 parallel downloads now peak at 114.6 instead of 154.3 MiB at the same throughput (receive-buffer report). A vendored h3 no longer buffers downloads outside QUIC flow control: 32 downloads now peak at 95.8 instead of 112.5 MiB, and the longer they run the more that saves (download-memory report). Concurrent downloads now share a receive budget that holds only readers that fall behind: 32 downloads peak at 50.0 instead of 96.7 MiB and 32 duplex transfers at 63.6 instead of 110.6, while one-, eight-flow and long-path downloads keep their speed (receive-budget report). On macOS, where readers keep up, none of these three changes moves the XHTTP H3 numbers beyond run-to-run spread (macOS re-check, receive-budget collector run).

Performance branch against main: median paired changes in throughput, CPU per GiB and peak footprint across all 156 bulk scenarios

Quick start

CLI

Build the xray-rust binary, export a starting profile, validate it and run it:

cargo build --locked -p xray-cli          # produces target/debug/xray-rust
target/debug/xray-rust config example vless-tls > client.json
target/debug/xray-rust config check --config client.json --json
target/debug/xray-rust run -config client.json

config check parses the profile without starting the core or touching the network, and reports problems with their JSON path. The exported examples (socks-direct, vless-tls, hysteria2, wireguard, xhttp-download, dns-routing, …) use synthetic endpoints and credentials: supply your own before running. See configuration tooling.

For a credential-free smoke run, the loopback example starts a SOCKS5 listener at 127.0.0.1:1080, routes directly through the host network, and runs until Ctrl-C; on unix, SIGTERM (from systemctl stop, docker stop or launchd) stops it as gracefully, as in Xray-core:

cargo run --locked -p xray-cli -- run \
  -config examples/freedom.json

For VLESS, copy a synthetic fixture from tests/fixtures/configs/ outside the repository and replace every placeholder. Never commit a live UUID, key, short ID, endpoint, or subscription URL.

Kotlin Multiplatform (Android and iOS)

Use xray-rust-kmp to import proxy links, start and stop the VPN tunnel, and observe its state from shared Kotlin code. The Android engine uses the mobile SDK's VpnService. On iOS, the app controls a Swift Packet Tunnel extension. Build tag v0.10.1 from source as a Gradle composite build. The KMP setup guide includes the Gradle configuration and iOS Swift package requirements.

Android

Prebuilt SDK packages are published from xray-rust-mobile; each mobile release pins a reviewed core commit and ships checksums and a release manifest. Stable versions are on Maven Central, no GitHub credentials needed; each release also carries the standalone AAR:

dependencies {
    implementation("io.github.aimalygin:xray-rust-mobile:0.10.1")
}

Subclass the reference VpnService and register it in your manifest:

class AppVpnService : XrayVpnService() {
    fun connect(configJson: String) {
        startXrayTunnel(
            configJson = configJson,
            tunRuntimeProfile = XrayTunRuntimeProfile.Mobile,
        )
    }

    override fun onXrayTunnelStartFailed(error: Throwable) {
        // Report a sanitized failure to the host app.
    }
}

The host app still owns VpnService.prepare, the foreground notification and service type. See the mobile SDK guide and Android integration.

Apple

Add the Swift Package:

dependencies: [
    .package(
        url: "https://github.com/aimalygin/xray-rust-mobile.git",
        exact: "0.10.1"
    ),
]

It provides the low-level XrayMobileAdapter, shared profile and storage APIs in XrayAppleShared, and the ready-to-subclass XrayAppleTunnel packet-tunnel provider. A Packet Tunnel extension can use it directly:

import XrayAppleTunnel

final class PacketTunnelProvider: XrayPacketTunnelProvider {}

Starting a real tunnel needs signing and the Packet Tunnel Network Extension entitlement. See the mobile SDK guide and Apple integration.

Build the mobile SDKs and samples from source

Prerequisites:

  • Rust via rustup; rust-toolchain.toml selects the exact toolchain used by the workspace.
  • A C toolchain for native dependencies.
  • Go only for deterministic oracle tools and optional Xray-core interoperability tests.
  • Xcode for Apple artifacts, or JDK 17+, Android SDK 35, CMake 3.22.1, and NDK 26.3.11579264 for Android artifacts.

Apple:

scripts/check-mobile-toolchains.sh --apple
scripts/build-apple-xcframework.sh
scripts/fetch-geodata.sh
open platform/apple/XrayClient/XrayClient.xcodeproj

The Xcode project consumes target/mobile/apple/XrayRust.xcframework through the local Swift Package. Choose the XrayClient, XrayClientTv, or XrayClientMac scheme. The committed project builds unsigned under placeholder org.example identifiers; to sign it, copy platform/apple/XrayClient/Config/Local.xcconfig.example to Local.xcconfig in the same directory and set your bundle prefix and Team ID there. That file is git-ignored, so your identity stays out of the repository and Xcode leaves nothing to commit. Register App IDs matching your prefix first — the tunnel targets request the packet-tunnel-provider entitlement. The geodata download is needed by the checked-in Xcode resource build phases; profiles that do not use geodata can omit those files in a custom host project. See Apple integration.

Android:

scripts/check-mobile-toolchains.sh --android
scripts/build-android-adapter.sh

This produces platform/android/xraymobile/build/outputs/aar/xraymobile-debug.aar. See Android integration.

Project layout

crates/
├── xray-cli               xray-rust command: run, config check/example/contract
├── xray-config            Xray JSON subset and geodata parser with path-aware diagnostics
├── xray-core-rs           lifecycle, inbounds, routing, outbound selection, DNS, TUN runtime
├── xray-ffi               stable C ABI with an embedded Tokio runtime
├── xray-proxy             client protocol wire formats: SOCKS/HTTP, VLESS, VMess, Trojan, Shadowsocks, Hysteria 2, WireGuard, Mux
├── xray-transport         TCP, TLS, REALITY, DNS, dialing and shaped ClientHellos
├── xray-routing           routing matchers and policy evaluation
├── xray-tun               bounded packet queues and TUN abstractions
├── xray-utls              uTLS ClientHello profile data
├── xray-vless-encryption  VLESS encryption client
├── xray-wireguard         WireGuard client with a userspace TCP/UDP interface
├── xray-runtime           shutdown coordination
└── xray-bench             benchmark harness against Xray-core and sing-box
platform/
├── android                Kotlin wrapper, JNI bridge, VpnService and device-test apps
└── apple                  Swift Package, Packet Tunnel provider and Xcode sample app
tools/                     Go oracles and reference builds for wire fixtures
tests/                     shared fixtures and compatibility data
fuzz/                      cargo-fuzz targets
scripts/                   build, interop, benchmark and release checks
docs/                      status, compatibility, architecture, evidence
vendor/                    forks of upstream crates the workspace builds on
website/                   project website source

Documentation

Contributing and testing

Read CONTRIBUTING.md first. Run the same Rust checks used by CI:

cargo fmt --all -- --check
cargo clippy --workspace --all-targets --all-features --locked -- \
  -D warnings -W clippy::perf -W clippy::suspicious
cargo test --workspace --exclude xray-rust-fuzz --all-targets --locked

For a self-contained data-path test that needs no external server:

cargo test --locked -p xray-core-rs \
  --test runtime_data_path_tests \
  socks_client_reaches_echo_target_through_freedom_outbound

The default suite is hermetic. Beyond it, verification documents the Go-oracle fixture replay (scripts/verify-oracle-fixtures.sh), local interoperability against a pinned Xray-core checkout (scripts/check-*-interop.sh), fuzzing and live-node tests; mobile testing covers the SDKs and physical devices. Report vulnerabilities privately as described in SECURITY.md.

License

The project source is licensed under the Mozilla Public License 2.0. Downloaded geodata and other third-party components remain under their respective licenses; see THIRD_PARTY_NOTICES.md.

About

Mobile-first Rust implementation of VLESS, REALITY, Vision, Trojan, Shadowsocks 2022, VMess AEAD, Hysteria 2, WireGuard, TUN, routing, and DNS for embeddable proxy clients.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

54 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages