VLESS
Source files: 42 · checked against Etemenanki 46c12e4 · katana v6.1.0
Etemenanki/protocols/src/vless/mod.rsEtemenanki/protocols/src/vless/addons.rsEtemenanki/protocols/src/vless/protocol.rsEtemenanki/protocols/src/vless/validator.rsEtemenanki/protocols/src/vless/config.rsEtemenanki/protocols/src/vless/core.rsEtemenanki/protocols/src/vless/codec.rsEtemenanki/protocols/src/helpers/address.rsEtemenanki/protocols/src/core/mod.rsEtemenanki/protocols/src/mux/mod.rsEtemenanki/protocols/src/mux/demux.rsEtemenanki/protocols/src/mux/frame.rsEtemenanki/protocols/src/sniff/mod.rsEtemenanki/concepts/src/core.rsEtemenanki/concepts/src/client.rsEtemenanki/concepts/src/runtime.rsEtemenanki/concepts/src/buffer.rsEtemenanki/app/src/config.rsEtemenanki/app/src/lower.rsEtemenanki/supervisor/src/build/inbound.rsEtemenanki/supervisor/src/build/outbound.rsEtemenanki/supervisor/src/build/validate.rsEtemenanki/supervisor/src/serve.rsEtemenanki/supervisor/src/entity/session.rsEtemenanki/supervisor/src/topology/inbound/mod.rsEtemenanki/supervisor/src/topology/outbound/mod.rsEtemenanki/supervisor/src/topology/spec_plan/inbound.rsEtemenanki/supervisor/src/topology/spec_plan/outbound.rsEtemenanki/protocols/tests/unit/vless/addons.rsEtemenanki/protocols/tests/unit/vless/protocol.rsEtemenanki/protocols/tests/unit/vless/validator.rsEtemenanki/protocols/tests/unit/vless/core.rsEtemenanki/protocols/tests/unit/vless/codec.rsEtemenanki/protocols/tests/unit/mux/demux.rsEtemenanki/protocols/tests/pipeline/vless.rsEtemenanki/app/tests/integration/e2e_xray.rsEtemenanki/app/tests/integration/e2e_xray_mux.rsEtemenanki/app/tests/integration/e2e_xray_reality.rsEtemenanki/app/tests/integration/e2e_sniff.rsEtemenanki/app/tests/unit/lower.rskatana/src/lower/inbound.rskatana/src/api/newv2board.rs
VLESS is the thinnest protocol in etemenanki-protocols: a request header that names a user, a command and a target, a two-byte response, and then the flow’s bytes verbatim. It has no cryptography of its own, so the transport underneath (TLS, WebSocket over TLS, gRPC over TLS, or REALITY) provides confidentiality. The module lives in protocols/src/vless/: the wire primitives and the request addons that carry the XTLS flow, the server as a sans-I/O core (VlessCore), the client as two sans-I/O codecs (VlessStream, VlessDatagram), and the XTLS Vision adapter in vision/, which has a page of its own.
This page is for contributors who change that module. It gives the exact wire layout, walks through the VlessCore state machine event by event, explains why the user table is keyed by a processed UUID, and lists the tests that pin each behaviour. The generic machinery the core plugs into (ProxyCoreDecode, effects, the per-connection runtime) is described in the concepts pages linked at the end.
Responsibilities
Section titled “Responsibilities”| The module does | It leaves to others |
|---|---|
| Parse and validate the request header from a growing byte slice: version, addons, command, port-first address. | Reading from the socket, buffering, timers and dialing: the per-connection runtime in concepts/src/runtime.rs. |
Decode the request addons into a VlessFlow, and refuse a Vision request that reaches the core. |
Vision framing and the raw switch: VisionStream in protocols/src/vless/vision/, which the supervisor puts under the core and the codec. |
Authenticate the 16-byte user id against a Validator<T> and attach the configured UUID and payload to the flow. |
Deciding where the flow goes: the application’s connector and router. |
| Relay a TCP flow verbatim, answering once the outbound is connected. | Confidentiality and server authentication: the TLS, WebSocket, gRPC and REALITY transports. |
| Relay a UDP association to the single target named in the header, with 2-byte length framing both ways. | mux.cool framing itself: Demux in protocols/src/mux/demux.rs, shared with Trojan and VMess. |
Hand a mux carrier (command 0x03) to Demux. |
Sniffing rules: the collector in protocols/src/sniff/. |
| Encode the request and decode the response on the client side, and carry a Vision outbound’s UDP as XUDP. | Config parsing and construction: the front ends lower their config into a spec (app/src/lower.rs, katana src/lower/inbound.rs), and the supervisor builds the Validator and the codecs (supervisor/src/build/inbound.rs, supervisor/src/build/outbound.rs). |
The reverse command is out of scope. The XTLS flow is decoded from the request addons (Request addons), and the only flow known is XTLS Vision (xtls-rprx-vision). VlessCore serves plain VLESS only: Vision is served by VisionStream, an adapter the supervisor wraps around a REALITY stream before the core or the codec sees it, and the server side of that adapter strips the flow from the header. A Vision request that still reaches the core means no adapter was in place, and the core refuses it once the user id is known (vless flow (xtls vision) is not served by this core, Unsupported); an unknown id is refused as unknown first, whatever flow it asks for. That refusal is a backstop, not the rule that keeps Vision off other transports; validation is (Flow in the spec).
The flow is set per inbound, not per user. etemenanki-app reads it as flow in UuidUsersSettings and VlessOutboundSettings (app/src/config.rs) and decodes it in app/src/lower.rs → parse_vless_flow: unset or "" is VlessFlow::None, xtls-rprx-vision is VlessFlow::Vision, anything else fails with <ctx>: unknown vless flow "…". IdUser is deny_unknown_fields, so a flow inside a user entry fails with invalid settings: unknown field `flow`, expected `id` or `email` . katana takes the flow from the panel’s node config, helium-node-api’s, whose flow is absent or xtls-rprx-vision and holds Vision to security reality (flow xtls-rprx-vision needs security reality); src/lower/inbound.rs → lower_stream_protocol maps it to the same two values. A UniProxy panel’s flow is read in src/api/newv2board.rs → v2ray: a node with any other flow is refused as node requests kernel-unsupported feature: VLESS flow "…", and a flow on a node that does not serve VLESS as node requests kernel-unsupported feature: an XTLS flow off VLESS.
VLESS has no open mode. IdUser has an email next to its id: the key is optional to the schema, so that a missing one gets an error naming the inbound and the entry, but app/src/lower.rs requires it (inbound <tag>: users[<n>] has no email; a user of this inbound is named by its email). The supervisor’s validate_inbound refuses a VLESS inbound whose spec names no user set, with the protocol has no open mode and needs a user set.
etemenanki-app reads a VLESS inbound’s settings as UuidUsersSettings and a VMess inbound’s as VmessInboundSettings (app/src/lower.rs → lower_inbound). clock_check exists only in the VMess struct and flow only in the VLESS one, so each is refused as an unknown field on the other protocol: inbound <tag>: invalid settings: unknown field `clock_check`, expected `users` or `flow` on VLESS (a_vmess_inbound_can_turn_the_clock_check_off in app/tests/unit/lower.rs), unknown field `flow`, expected `users` or `clock_check` on VMess.
Module layout
Section titled “Module layout”| File | Contents |
|---|---|
protocols/src/vless/mod.rs |
Re-exports VlessCore, VlessStream, VlessDatagram, VlessServerConfig, Command, RequestHeader, Validator, VlessFlow. |
protocols/src/vless/addons.rs |
VlessFlow, XTLS_RPRX_VISION, and the addons protobuf: parse_addons, encode_addons. |
protocols/src/vless/protocol.rs |
Constants, Command, RequestHeader, slice parsers (parse_request_header, parse_response_header, parse_length_packet) and encoders. |
protocols/src/vless/validator.rs |
Validator<T>: the user table keyed by processed UUID. |
protocols/src/vless/config.rs |
VlessServerConfig<T>: the user list, and validator() to build the table. |
protocols/src/vless/core.rs |
VlessCore<T>: the server state machine, an implementation of ProxyCoreDecode. |
protocols/src/vless/codec.rs |
VlessStream (ProxyCoreEncode) and VlessDatagram (ProxyCoreEncodeDatagram). |
protocols/src/vless/vision/ |
The XTLS Vision adapter: padding, the inner-TLS filter, the framers and the VisionStream poll shell. See XTLS Vision. |
Wire format
Section titled “Wire format”All multi-byte integers are big-endian. The layout follows Xray’s proxy/vless/encoding.
Request header
Section titled “Request header”| Offset | Field | Size | Meaning |
|---|---|---|---|
| 0 | version | 1 | Must be 0x00 (VERSION). |
| 1 | uuid | 16 | The user id, raw bytes as on the wire. |
| 17 | addons length | 1 | n, the length of the protobuf addons that follow; 0 for plain VLESS. |
| 18 | addons | n | The flow, as described under Request addons. |
| 18 + n | command | 1 | 0x01 TCP (CMD_TCP), 0x02 UDP (CMD_UDP), 0x03 mux (CMD_MUX). Anything else is refused. |
| 19 + n | address | 5 to 259 | Port first, then the typed address (next table): 7 bytes for IPv4, 19 for IPv6, 4 + n for an n-byte domain. Absent for CMD_MUX: the header ends at offset 19 + n. |
Without addons the longest header is REQUEST_HEADER_MAX = 1 + 16 + 1 + 1 + AddressCodec::MAX_LEN = 278 bytes, where AddressCodec::MAX_LEN = 1 + 1 + 255 + 2 = 259. The Vision addons add 18 bytes.
Address
Section titled “Address”VLESS uses the VMess-style codec, ADDR = AddressCodec::VMESS (protocols/src/helpers/address.rs): the port comes first, and the type bytes differ from SOCKS.
| Field | Size | Meaning |
|---|---|---|
| port | 2 | Destination port. |
| type | 1 | 0x01 IPv4, 0x02 domain, 0x03 IPv6. Any other value fails with unknown address type: N. |
| address | 4, 1 + n, or 16 | IPv4 octets; a length byte and n domain bytes; or IPv6 octets. |
A domain is decoded by parse_domain_bytes. A domain that starts with a digit or [ and parses as an IP literal (brackets stripped) is folded back into Remote::IpAddr. Anything else must be non-empty UTF-8 made only of ASCII letters, digits, -, . and _; otherwise the parse fails with empty domain name, non-utf8 domain or invalid domain name: … (all InvalidData). The folding matters for sniffing, which only runs for IP destinations.
Request addons
Section titled “Request addons”The addons are a protobuf message, a port of Xray’s proxy/vless/encoding/addons.proto:
message Addons { string Flow = 1; bytes Seed = 2;}addons::parse_addons reads it strictly, so a stray or future flow never passes as plain VLESS:
| Input | Result |
|---|---|
No bytes, or a Flow field that is empty |
VlessFlow::None |
Flow = xtls-rprx-vision |
VlessFlow::Vision |
| Any other flow string | unsupported vless flow "…" |
A Flow that is not UTF-8 |
vless flow is not valid utf-8 |
A Seed field |
Parsed and skipped: Vision’s padding seed is fixed, not negotiated |
| Any other field, or field 1 or 2 with another wire type | Refused: unknown vless addons field tag 0x…, or one of the length errors below when the bytes after the tag do not hold a length-delimited value |
| A varint longer than 10 bytes or without its last byte | vless addons varint is unterminated or too long |
| A field longer than what is left | vless addons field runs past the end |
Every refusal is InvalidData. encode_addons(VlessFlow::Vision) writes the 18 bytes 0x0a 0x10 and xtls-rprx-vision; VlessFlow::None writes nothing, so the addons length byte is 0. The client codecs write the outbound’s flow: VlessStream in every TCP header, VlessDatagram only in the Vision form, whose header carries the mux command (Mux request). ENCODED_MAX (18) is the most encode_addons writes.
Response header
Section titled “Response header”| Offset | Field | Size | Meaning |
|---|---|---|---|
| 0 | version | 1 | 0x00. |
| 1 | addons length | 1 | Length of addons that follow. |
| 2 | addons | n | Skipped by the client. |
The server always sends RESPONSE_HEADER = [VERSION, 0], with or without Vision. The client parser, parse_response_header, accepts and skips non-empty response addons but refuses any version other than 0. Request addons are decoded; response addons are skipped.
UDP framing
Section titled “UDP framing”After a CMD_UDP request, both directions carry length-prefixed packets with no per-packet address:
| Field | Size | Meaning |
|---|---|---|
| length | 2 | Payload length, 0 to 65535. |
| payload | length | One datagram. |
Every uplink packet goes to the target in the request header; every downlink packet is reported by the client as coming from that target. A mux carrier is the way to reach several UDP peers over one connection (XUDP, see mux.cool and XUDP). The client codec frames UDP this way only without a flow; under Vision it sends XUDP instead.
Mux request
Section titled “Mux request”A CMD_MUX request is 19 bytes plus its addons: version, uuid, addons length, addons and command, with no address. parse_request_header synthesises the destination with mux_destination() (protocols/src/mux/mod.rs): the domain MUX_ADDRESS = "v1.mux.cool", port 0, network TCP. It is never dialed; it is what a log line or a route rule sees for the carrier. The mux.cool frames start right after the command byte, at offset 19 without addons. An Xray client with the Vision flow sends its UDP as such a carrier (XUDP), with the flow in the addons, and VlessDatagram::with_flow does the same with VlessFlow::Vision: its header is 37 bytes, the 18 addon bytes included.
Key types
Section titled “Key types”Wire primitives
Section titled “Wire primitives”pub const REQUEST_HEADER_MAX: usize = 1 + 16 + 1 + 1 + AddressCodec::MAX_LEN; // empty addonspub const RESPONSE_HEADER: [u8; 2] = [VERSION, 0];pub const VERSION: u8 = 0;pub const CMD_TCP: u8 = 1;pub const CMD_UDP: u8 = 2;pub const CMD_MUX: u8 = 3;pub const ADDR: AddressCodec = AddressCodec::VMESS;
pub enum Command { Tcp, Udp, Mux,}
impl Command { pub fn network(self) -> DialNetwork;}
pub struct RequestHeader { pub uuid: [u8; 16], pub command: Command, pub destination: Destination, pub flow: VlessFlow,}
pub fn encode_request_header( uuid: &[u8; 16], command: Command, destination: &Destination, flow: VlessFlow,) -> BytesMut;pub fn parse_request_header(buf: &[u8]) -> io::Result<Option<(RequestHeader, usize)>>;pub fn parse_response_header(buf: &[u8]) -> io::Result<Option<usize>>;pub fn parse_length_packet(buf: &[u8]) -> Option<(Range<usize>, usize)>;pub fn encode_length_packet(payload: &[u8]) -> Bytes;#[derive(Default)]pub enum VlessFlow { #[default] None, Vision,}
pub const XTLS_RPRX_VISION: &str = "xtls-rprx-vision";pub(crate) const ENCODED_MAX: usize = 2 + XTLS_RPRX_VISION.len(); // 18
pub fn parse_addons(bytes: &[u8]) -> io::Result<VlessFlow>;pub fn encode_addons(flow: VlessFlow) -> Vec<u8>;Command::network maps Tcp and Mux to DialNetwork::Tcp (a mux carrier is itself a stream; its sub-flows carry their own networks) and Udp to DialNetwork::Udp. RequestHeader::uuid is the id exactly as it appeared on the wire; the configured UUID comes from the validator. RequestHeader::flow is the decoded flow: the parser reports Vision and leaves it to the caller to serve or refuse it.
The three parse_* functions are the forms the core, the codecs and the tests use. They take the front of a buffer that may still be growing and return Ok(None) while it is too short, so the caller consumes nothing and waits for more bytes. Short input is detected through need_more (protocols/src/helpers/parse.rs), which turns an UnexpectedEof from the bounds-checked take/take_array helpers into None; every other error propagates. parse_request_header refuses an unknown version or command and addons that do not decode; an addons length that runs past the buffer is short input, not an error. The async readers and writers the module used to keep beside them were removed in protocols 3.0.0; see Protocol crate foundations.
Validator and server config
Section titled “Validator and server config”fn process_uuid(mut id: [u8; 16]) -> [u8; 16];
pub struct Validator<T> { users: HashMap<[u8; 16], (Uuid, Arc<T>)>,}
impl<T> Validator<T> { pub fn new() -> Self; pub fn add(&mut self, id: Uuid, data: Arc<T>); pub fn get(&self, id: &[u8; 16]) -> Option<(Uuid, Arc<T>)>; pub fn len(&self) -> usize; pub fn is_empty(&self) -> bool;}pub struct VlessServerConfig<T> { pub users: Vec<(Uuid, Arc<T>)>,}
impl<T> VlessServerConfig<T> { pub fn validator(&self) -> Validator<T>;}T is the per-user payload that travels with every flow as NetworkUser::user_data. Every front end serves VLESS through etemenanki-supervisor, which uses T = Principal; the tests use (). supervisor/src/build/inbound.rs → user_table builds the table as VlessServerConfig { users: uuids(..) }.validator() from the users the inbound admits, each UUID paired with its user’s Arc<Principal>, and the supervisor keeps it in StreamProtocol::Vless { users: ArcSwap<vless::Validator<Principal>>, vision: bool } (supervisor/src/topology/inbound/mod.rs); vision is set when the spec’s flow is Vision (Flow in the spec). Clone and Default are written by hand so they do not require T: Clone: the payload is always behind an Arc.
A change to the inbound’s users builds a new table off the hot path and stores it into that cell. supervisor/src/serve.rs → serve_connection hands drive the closure || VlessCore::new(users.load_full(), sniff, source) and the connection’s Report; drive calls it once, so each connection’s core gets the table current when its runtime is built. The table is an Arc the core shares read-only, so a lookup takes no lock. source is the socket’s peer, or the client a PROXY protocol v2 header names when the inbound reads one, or, for a socket a relay on the same host handed over, the client the header sent with it names, or, over WebSocket on an inbound with real_ip, the client a proxy in the trusted networks names in the upgrade’s header. How a user change reaches sessions already open is on Users, principals and sessions.
The processed UUID
Section titled “The processed UUID”process_uuid zeroes bytes 6 and 7 of a UUID. Validator::add stores each user under the processed form of its configured UUID, and Validator::get processes the request id before the lookup:
fn process_uuid(mut id: [u8; 16]) -> [u8; 16] { id[6] = 0; id[7] = 0; id}This is a port of ProcessUUID in Xray’s proxy/vless/validator.go, whose MemoryValidator keys users the same way. Doing the same keeps authentication identical to an Xray server: a client id that Xray matches to a user is matched here too. Byte 6 holds the UUID version nibble, so the key does not depend on the version bits. The consequences for contributors:
getreturns the configuredUuidand its payload, not the request bytes. The core puts thatUuidintoUserAuthorization::Uuidand the payload intoNetworkUser::user_data, so routing and logging see the configured id. The payload is the configured user’sPrincipal: the session binds to it on its first flow (supervisor/src/entity/session.rs→Session::admit), and the supervisor bills the session’s bytes to that user, even when the client’s bytes 6 and 7 differ. Accounting is on Per-user usage accounting.- Both sides must apply
process_uuid. Keying the map by the raw UUID, or looking up raw request bytes, silently breaks clients whose bytes 6 and 7 differ.
Validator::add inserts into a HashMap keyed by the processed UUID.
VlessCore
Section titled “VlessCore”pub struct VlessCore<T> { validator: Arc<Validator<T>>, sniff: bool, source: Option<IpAddr>, timing: Timing, prefix: SniffPrefix, state: State<T>,}
impl<T> VlessCore<T> { pub const BUF_SIZE: usize = 16 * 1024;
pub fn new(validator: Arc<Validator<T>>, sniff: bool, source: Option<IpAddr>) -> Self; pub fn is_established(&self) -> bool;}
impl<T: Send + Sync + 'static> ProxyCoreDecode for VlessCore<T> { type Key = FlowKey; type Target = Flow<T>; type Error = io::Error; type TransportAddr = ();
const STAGING_RESERVE: usize = 272 + downlink_overhead(Self::BUF_SIZE); const MAX_DATAGRAM: usize = 8192;
fn handle( &mut self, event: Event<'_, Self>, fx: &mut Effects<'_, Self>, ) -> Result<usize, io::Error>;
fn held(&self) -> &[u8];}The private state enum is the whole state machine:
enum State<T> { Handshake, Sniff(Flow<T>), Tcp { relay: Passthrough<FlowKey>, replied: bool, }, Udp { flow: Flow<T>, opened: bool, }, Mux(Demux<T>), Done,}The core composes the shared pieces from protocols/src/core/mod.rs rather than reimplementing them:
| Piece | Role in VlessCore |
|---|---|
Timing |
The single deadline per phase: HANDSHAKE_TIMEOUT, SNIFF_TIMEOUT or RELAY_IDLE_TIMEOUT. touch runs at the top of every byte event (Transport, Outbound, Datagram). is_established() delegates to it and is true in Phase::Relay and Phase::Closing. |
SniffPrefix |
The first payload bytes of a TCP flow with an IP destination, held until the flow opens. |
Passthrough<FlowKey> |
Half-close bookkeeping for the one TCP outbound, keyed FlowKey::Direct. |
Demux<T> |
The mux.cool demultiplexer for a CMD_MUX carrier; its sub-flows are keyed FlowKey::Sub(SubKey). |
held() returns the demux’s held buffer in State::Mux and the sniff prefix otherwise, so Effect::ForwardHeld ranges resolve against whichever buffer is live.
Buffer sizing
Section titled “Buffer sizing”| Constant | Value | Why |
|---|---|---|
VlessCore::BUF_SIZE |
16 KiB | The cap on the runtime’s read and staging buffers, which start small or empty and grow toward it (concepts/src/buffer.rs). A UDP frame carries up to MAX_DATAGRAM bytes behind its 2-byte length, and a mux downlink read of up to BUF_SIZE needs room for its Keep headers. |
STAGING_RESERVE |
272 + downlink_overhead(16384) = 808 |
What one event may stage beyond echoing its own payload: the response header, a UDP frame’s length prefix, or the mux Keep headers one outbound read splits into. |
downlink_overhead(read_size) |
read_size.div_ceil(MAX_DATA_LEN) * FRAME_OVERHEAD_MAX = 2 × 268 |
One Keep header per MAX_DATA_LEN (8 KiB) piece; FRAME_OVERHEAD_MAX = 2 + 4 + 1 + AddressCodec::MAX_LEN + 2 = 268 (protocols/src/mux/frame.rs). |
MAX_DATAGRAM |
8192 | Raised from the trait default of 4096. The runtime polls a datagram outbound only when staging has STAGING_RESERVE + MAX_DATAGRAM free, which fits in 16 KiB, and reads each packet into at most this many bytes; like a kernel recv, a longer downlink packet is truncated. |
The runtime’s contract (concepts/src/core.rs → ProxyCoreDecode::STAGING_RESERVE) is that every event except Deadline arrives only with that much staging room free, plus the payload length for outbound byte events. That is why the core can treat a failed fx.stage or staging.reserve as a bug and return staging_full() (staging room below the core's declared reserve).
Client codecs
Section titled “Client codecs”const RESERVE: usize = REQUEST_HEADER_MAX + addons::ENCODED_MAX;const DATAGRAM_RESERVE: usize = /* the larger of RESERVE and FRAME_OVERHEAD_MAX */;const XUDP_SESSION: u16 = 0;
pub struct VlessStream { header: BytesMut, replied: bool,}
impl VlessStream { pub fn new(uuid: &[u8; 16], dest: &Destination, flow: VlessFlow) -> Self;}
pub struct VlessDatagram { header: BytesMut, target: Destination, replied: bool, framing: Framing,}
enum Framing { Length, // len(2, BE) | payload, to and from the header's target Xudp { opened: bool }, // opened once the New frame is staged}
impl VlessDatagram { pub fn new(uuid: &[u8; 16], target: &Destination) -> Self; // with_flow(.., VlessFlow::None) pub fn with_flow(uuid: &[u8; 16], target: &Destination, flow: VlessFlow) -> Self;}Both implement ProxyCoreEncodeHandshake with type Target = Destination (the upstream VLESS server the runtime dials) and type Error = io::Error. VlessStream’s STAGING_RESERVE is RESERVE, REQUEST_HEADER_MAX + addons::ENCODED_MAX = 278 + 18 = 296: the longest header the codecs emit, a 255-byte domain with the Vision addons. VlessDatagram’s is DATAGRAM_RESERVE, the larger of RESERVE and one packet’s XUDP frame overhead (FRAME_OVERHEAD_MAX, 268), so also 296. VlessStream adds ProxyCoreEncode; VlessDatagram adds ProxyCoreEncodeDatagram:
fn start(&mut self, out: &mut Staging<'_>) -> Result<Handshake, Self::Error>;fn reply(&mut self, wire: &mut [u8], out: &mut Staging<'_>) -> Result<Reply, Self::Error>;fn finish(&mut self, out: &mut Staging<'_>) -> Result<(), Self::Error>;
fn seal(&mut self, plain: &[u8], out: &mut Staging<'_>) -> Result<usize, Self::Error>;fn open(&mut self, wire: &mut [u8]) -> Result<Opened, Self::Error>;
fn seal_to( &mut self, plain: &[u8], to: &Destination, out: &mut Staging<'_>,) -> Result<Option<()>, Self::Error>;fn open_from(&mut self, wire: &mut [u8]) -> Result<OpenedFrom, Self::Error>;The supervisor picks the codec per flow in supervisor/src/build/outbound.rs → build_outbound, Vless arm: a flow whose destination.network is DialNetwork::Udp gets VlessDatagram::with_flow(&uuid, &f.destination, vless_flow), every other flow gets VlessStream::new(&uuid, &f.destination, vless_flow); both announce the outbound’s flow in their addons. With Vision, transport_connector also asks the REALITY transport to wrap each dialed stream in the client side of VisionStream, for the same user id. Both codecs run inside Outbound::Vless(ProxyClient<VLESS_BUF, VlessStream, VlessDatagram>) with VLESS_BUF = 16 * 1024 (supervisor/src/topology/outbound/mod.rs). Each flow opens its own upstream connection. The client side sends CMD_MUX only for a UDP flow under Vision, and then carries that one flow’s packets as one XUDP session; it never multiplexes several flows over one connection.
Flow in the spec
Section titled “Flow in the spec”The flow is part of the supervisor’s spec on both sides (supervisor/src/topology/spec_plan/inbound.rs, outbound.rs); VlessFlow is re-exported as etemenanki_supervisor::topology::spec_plan::VlessFlow:
pub enum InboundProtocolSpec { // … Vless { transport: InboundTransportSpec, flow: VlessFlow, },}
pub enum OutboundProtocolSpec { // … Vless { upstream: ProxyUpstream, id: Uuid, flow: VlessFlow, },}supervisor/src/build/validate.rs holds the rules, fail-closed on both sides:
| Rule | Inbound | Outbound |
|---|---|---|
A REALITY shape only under VLESS: reality is for vless only |
inbound_transport, for every protocol InboundProtocolSpec::transport names |
validate_outbound |
A Vision flow only over the REALITY shape: vless vision (xtls-rprx-vision) rides only over reality |
inbound_transport |
validate_outbound |
A user set: the protocol has no open mode and needs a user set |
validate_inbound |
– |
The build then puts the adapter in place where the REALITY stream’s concrete type is still known:
- Inbound.
build/inbound.rs→build_handlersetsStreamProtocol::Vless { vision }from the flow.serve.rs→serve_tcpturns each accepted REALITY stream into a Vision one withTransportStream::into_vision_serverbefore it spawnsserve_connection, soVlessCorereads plain VLESS over it. A flow change is a settings change: the handler is swapped, and connections already open keep the one they were accepted with. - Outbound.
build/outbound.rs→transport_connectorbuildsTransportKind::reality(client).vision(uuid)for a Vision outbound, so every stream it dials comes back asTransportStream::Vision.
The adapter, its framing and the raw switch are on XTLS Vision; the REALITY transport under it is on REALITY transport.
Server state machine
Section titled “Server state machine”stateDiagram-v2 [*] --> Handshake Handshake --> Tcp: CMD_TCP, sniff off or domain target Handshake --> Sniff: CMD_TCP, sniff on and IP target Handshake --> Udp: CMD_UDP, reply staged Handshake --> Mux: CMD_MUX, reply staged Handshake --> Done: TransportEof Sniff --> Tcp: verdict, deadline or TransportEof Tcp --> Tcp: Connected stages the reply once Udp --> Done: TransportEof or outbound gone Mux --> Done: TransportEof Done --> [*]
Tcp itself ends through Passthrough: the connection finishes once both halves have closed, when the outbound is gone, or when Timing reports the relay idle. A validation error in Handshake does not move to Done; handle returns Err and the runtime tears the connection down.
Validation order
Section titled “Validation order”parse_request_header checks each field as soon as its byte is present, so malformed input fails before the whole header has arrived, and the user lookup runs only on a complete, well-formed header.
flowchart TB
v{"byte 0 == 0?"} -- no --> e1["InvalidData: invalid vless request version: N"]
v -- yes --> u["bytes 1..17: uuid"]
u --> a["byte 17: addons length n, then parse_addons over n bytes"]
a -- "does not decode" --> e2["InvalidData: unsupported vless flow, or an addons error"]
a -- "a VlessFlow" --> c{"byte 18 + n in 1, 2, 3?"}
c -- no --> e3["InvalidData: invalid vless command: N"]
c -- "3 (mux)" --> m["mux_destination(), 19 + n bytes used"]
c -- "1 or 2" --> ad["port-first address from byte 19 + n"]
ad --> look["Validator::get(uuid)"]
m --> look
look -- None --> e4["PermissionDenied: invalid vless request user id"]
look -- "Some(uuid, data)" --> f{"flow is None?"}
f -- "no, in VlessCore" --> e5["Unsupported: vless flow (xtls vision) is not served by this core"]
f -- yes --> ok["Flow::new(destination, user, source)"]
parse_request_header returns a Vision flow as a value; the flow check is VlessCore::handle’s, after the user lookup. An unknown id is therefore refused as PermissionDenied, which the IP ban counts, whatever flow it asks for, and only a known user’s Vision request gets Unsupported. Behind a Vision inbound the core never sees the flow: the adapter’s read framer has already parsed the header, refused one without the Vision flow (vless vision: the request did not carry the vision flow), and handed the core a copy of it without the addons.
Any of these errors is returned from handle. The core has staged nothing at that point, so the client gets no response bytes before the connection closes. While the header is incomplete, on_transport returns Ok(0) and the runtime keeps the bytes in its read buffer; the first such event arms HANDSHAKE_TIMEOUT through Timing::touch.
When the response goes out
Section titled “When the response goes out”| Command | Response header staged | Why |
|---|---|---|
CMD_TCP |
On the first Event::Connected, guarded by replied. |
A failed dial closes the connection without ever answering, so the client sees the stream end before any response header. |
CMD_UDP |
Right after authentication, in the same handle call. |
The outbound socket opens lazily on the first packet; there is no connect to wait for. |
CMD_MUX |
Right after authentication, before any sub-flow exists. | Each sub-flow has its own outbound and its own success or failure, reported in mux frames. |
A VLESS client does not wait for the response before sending payload (the client codec’s start returns Handshake::Done), so the first payload bytes usually arrive together with, or right after, the header. This is what makes sniffing possible before the dial.
TCP flow
Section titled “TCP flow”sequenceDiagram participant C as VlessStream (client runtime) participant S as VlessCore (server runtime) participant O as Outbound C->>S: request header + first payload Note over S: parse, Validator::get, Flow::new Note over S: SetDeadline(RELAY_IDLE_TIMEOUT) S->>O: Effect::Open (FlowKey::Direct) S->>O: Effect::Forward payload (waits for the connect) O-->>S: Event::Connected S-->>C: stage RESPONSE_HEADER [0, 0] O-->>S: Event::Outbound bytes S-->>C: stage verbatim Note over C: open() consumes 2 bytes as an empty frame, then plaintext C->>S: TransportEof S->>O: Effect::Shutdown (half-close) O-->>S: Event::OutboundEof S-->>C: Effect::ShutdownTransport, then Effect::Finish
After the header, on_transport in State::Tcp forwards the whole slice with Passthrough::on_transport (Effect::Forward over 0..data.len()), and Event::Outbound stages the whole slice with Passthrough::on_outbound. Both clear the sniff prefix first: by then the ForwardHeld that referenced it has been applied, which the runtime’s pin rule guarantees (no byte event is delivered while a held-range effect is pending).
Event::ConnectFailed and Event::OutboundError call Passthrough::on_outbound_gone, which pushes ShutdownTransport and Finish. Staged bytes still drain.
Sniffing
Section titled “Sniffing”With sniff on and an IP destination (worth_sniffing in protocols/src/sniff/mod.rs), a TCP request enters State::Sniff(flow) and Phase::Sniff, which arms SNIFF_TIMEOUT (300 ms). Each transport event pushes bytes into SniffPrefix up to SNIFF_LIMIT (4 KiB) and consumes exactly what was taken. The flow opens (open_sniffed) when:
- the collector returns a verdict other than
Verdict::More:Found(a sniffer recognised the bytes) orExhausted(4 KiB collected without a match). A payload that no sniffer recognises keeps the flow waiting until one of these or the deadline; - the deadline fires (
Expired::Sniff); - the client half-closes (
TransportEof), in which case the half-close is applied right after the open.
open_sniffed copies SniffPrefix::result() into flow.sniffed and calls open_tcp. That enters Phase::Relay, which arms RELAY_IDLE_TIMEOUT, and only then pushes Effect::Open, then Effect::ForwardHeld over 0..held if anything was collected. A flow opened without sniffing takes the same path. The deadline comes first for the reason given at protocols/src/core/mod.rs → Timing::enter: a forward queued after an open waits out the connect, and so would a deadline queued after it, so the previous phase’s deadline would stay armed through the connect. After sniffing, that is the 300 ms window, which could end the flow as idle mid-connect. A domain destination skips sniffing and opens at once. UDP associations and mux carriers are never sniffed by the VLESS core; Demux applies the sniff flag to its own sub-flows.
UDP association
Section titled “UDP association”sequenceDiagram participant C as VlessDatagram (client runtime) participant S as VlessCore participant O as UDP outbound C->>S: header (CMD_UDP, target T) S-->>C: stage RESPONSE_HEADER C->>S: len + packet 1, len + packet 2 S->>O: Effect::Open (first complete frame only) S->>O: Effect::SendTo T (packet 1) S->>O: Effect::SendTo T (packet 2) O-->>S: Event::Datagram (its from is not encoded) S-->>C: stage len + payload Note over C: open_from() labels every reply as coming from T C->>S: TransportEof S->>O: Effect::Close, ShutdownTransport, Finish
In State::Udp, on_transport loops over complete frames with parse_length_packet. For each one it pushes Effect::SendTo { key: FlowKey::Direct, to: flow.destination.clone(), range }, with the range pointing at the payload inside the event slice, so packets are forwarded without copying. The to is always the header target. Effect::Open is pushed lazily before the first SendTo, and opened records it. A trailing partial frame is not consumed and waits in the read buffer.
In the other direction, Event::Datagram reserves len + 2 bytes in staging, writes the big-endian length and copies the payload. The packet’s from is not encoded; the wire has no field for it. A payload longer than u16::MAX would fail with vless: packet exceeds a u16, but the runtime never delivers one: it reads each packet into at most MAX_DATAGRAM bytes.
finish_udp (on TransportEof) pushes Effect::Close only when the outbound was opened, then ShutdownTransport and Finish. ConnectFailed and OutboundError end the association the same way, without Close. Event::SendFailed drops that one packet with a debug log line (vless: packet to … dropped: …) and keeps the association.
Mux carrier
Section titled “Mux carrier”For CMD_MUX, the core stages the response, moves to State::Mux(Demux::new(flow, self.sniff)) and enters Phase::Relay. From then on:
Event::Transportcallsdemux.feed(data, 0, fx). VLESS is an unencrypted carrier, soDemuxleaves a trailing partial frame in the runtime’s read buffer rather than copying it. The core then stagestake_out()when it is not empty. EveryDemuxcall clearsoutbefore it writes, so afterfeedit holds only theEndframes with which the uplink declined sessions: aNewbeyondMAX_SESSIONSor for an id already in use, orKeepdata for a session the demux does not know.Event::Outbound,Event::Datagram,Event::OutboundEof,Event::ConnectFailedandEvent::OutboundErrorfor aFlowKey::Subkey go toon_sub, which callsDemux::on_outbound,on_datagramoron_outbound_goneand stagesdemux.out()in place, without taking it. Because the next call clearsoutfirst, the next uplink does not stage those downlink frames again: each goes to the client once.Event::TransportEofcallsdemux.on_transport_eof, then pushesShutdownTransportandFinish.
The carrier’s own flow carries the user and source into every sub-flow. The frame format, MAX_SESSIONS (256 sub-flows per carrier) and XUDP are described on the mux page.
Event handling by state
Section titled “Event handling by state”| Event | Handshake |
Sniff |
Tcp |
Udp |
Mux |
|---|---|---|---|---|---|
Transport |
Parse; Ok(0) while short |
Collect prefix | Forward verbatim |
Frames to SendTo |
Demux::feed |
Outbound |
Ignored | Ignored | Stage verbatim | Ignored | on_sub (sub keys) |
Datagram |
Ignored | Ignored | Ignored | Stage length-prefixed | on_sub (sub keys) |
Connected |
– | – | Stage reply once | – | – |
ConnectFailed, OutboundError |
– | – | on_outbound_gone |
ShutdownTransport, Finish |
on_sub gone |
OutboundEof |
– | – | on_outbound_eof |
– | on_sub gone |
TransportEof |
Finish |
Open, then half-close | on_transport_eof |
finish_udp |
Demux EOF, Finish |
Deadline |
Err(TimedOut) |
Open with what was held | Finish (idle) |
Finish (idle) |
Finish (idle) |
SendFailed |
Logged, packet dropped | same | same | same | same |
TransportDatagram and TransportSendFailed return Ok(0): VLESS runs over byte-stream transports only (type TransportAddr = ()).
Client codecs
Section titled “Client codecs”VlessStream
Section titled “VlessStream”sequenceDiagram participant P as plaintext side participant R as ProxyClientRuntime participant U as upstream server R->>U: dial R->>R: start(): stage request header, Handshake::Done P->>R: poll_write(plain) R->>U: header + seal(plain) verbatim U-->>R: 0x00 0x00 + data R->>R: open(): Frame consumed 2, plain 0..0 R->>R: open(): Frame over the whole slice R-->>P: poll_read(data)
newencodes the header once withencode_request_header(uuid, Command::Tcp, dest, flow); the flow only changes the addons, and the Vision framing it implies is the adapter’s below the codec.startputs it into staging, clears it and returnsHandshake::Done, so plaintext can follow in the same write.replyis never called for a codec whosestartreturnsDone; it returns the errorvless: the response header is read with the first frameif it is.openparses the response header first. Until it is complete it returnsOpened::NeedMore; then it returns an empty frame (plain: 0..0) that consumes the header and any response addons. After that, every non-empty slice is one frame of plaintext.sealcopies the plaintext verbatim;finishstages nothing, because the wire’s own EOF carries the half-close.- A failed
Staging::putreturnsvless: staging room below the declared reserve.
VlessDatagram
Section titled “VlessDatagram”newiswith_flow(uuid, target, VlessFlow::None).with_flowpicks the framing from the flow: without one, aCommand::Udpheader fortargetand length framing (Framing::Length); withVlessFlow::Vision, aCommand::Muxheader formux_destination()with the Vision addons, and XUDP framing (Framing::Xudp). It keeps a clone oftargeteither way.- With length framing,
seal_toignores itstoargument: the association is bound to the header target, and the wire has no per-packet address. It returnsOk(None), staging nothing, when the payload is longer thanu16::MAXor does not fit in the room offered. - With XUDP,
seal_tosends each packet to its ownto, as a mux.cool frame of sessionXUDP_SESSION(0): the first aNewframe towardtowith the packet and no global id (encode_new_udp_into), every later one aKeepnamingto(encode_keep_into).openedturns true once theNewframe is staged. A packet longer thanMAX_DATA_LEN(8192 bytes), the most a mux reader takes, is dropped:seal_toreturnsOk(Some(()))and stages nothing, as Xray’s XUDP writer drops a packet it cannot frame. A frame that does not fit the room offered givesOk(None). - The client runtime turns
Ok(None)intoInvalidInput(codec refused a packet that fits its reserve). A packet larger than the client’s buffer fails earlier inProxyClientRuntime::make_roomwithframe larger than the client runtime's buffer. open_fromconsumes the response header as an empty frame with no source (None), which the runtime skips. With length framing, every later complete length-prefixed frame is returned withSome(self.target.clone())as its source. With XUDP, the privateopen_xudpparses one mux frame withparse_frame: aKeepwith data is a packet from the frame’s address, or fromtargetwhen the frame names none; aKeepwithout data and aKeepAliveare empty frames with no source; anEndisOpened::End, the end of the flow; aNewfrom the server fails withvless xudp: the server opened a session(InvalidData).
Invariants
Section titled “Invariants”| Invariant | Mechanism | Pinned by |
|---|---|---|
The version byte must be 0, in requests and responses. |
parse_request_header and parse_response_header check byte 0 before anything else. |
rejects_bad_version, response_header_rejects_version, response_header_and_length_packets_are_parsed_from_slices (protocols/tests/unit/vless/protocol.rs); stream_codec_consumes_the_response_header_as_an_empty_frame (codec.rs) |
| The addons decode strictly: the only flow is Vision, and an unknown flow or field, a wrong wire type or malformed bytes are refused, never read as plain VLESS. | parse_addons returns InvalidData for anything but an empty block, an empty or Vision Flow and a Seed. |
an_empty_payload_is_plain_vless, the_vision_flow_round_trips, an_empty_flow_field_is_none, a_seed_field_is_parsed_and_ignored, an_unknown_flow_is_refused, an_unknown_field_is_refused, malformed_protobuf_is_refused_not_panicked (protocols/tests/unit/vless/addons.rs); rejects_an_unknown_or_malformed_flow_header, request_header_is_parsed_from_a_slice_once_whole |
| The command and address follow the addons, wherever they end. | Offsets are computed from the addons length. | parses_a_vision_flow_header_with_shifted_offsets |
| The core serves plain VLESS only. | VlessCore::handle returns Unsupported for a known user’s header whose flow is not None; validation keeps Vision on REALITY, where the adapter strips the flow. |
a_known_uuid_asking_for_vision_is_unsupported_here (core.rs) |
Only commands 1, 2, 3 are accepted. |
The match cmd in parse_request_header returns InvalidData for any other byte. |
rejects_unknown_command (commands 0, 4 and 0xFF) |
A mux request has no address, and the bytes after the command byte are left for Demux. |
Command::Mux returns mux_destination() with 19 bytes plus the addons consumed. |
mux_command_synthesises_its_destination, mux_request_header_roundtrips, request_header_is_parsed_from_a_slice_once_whole |
| An incomplete header consumes nothing. | need_more maps short input to Ok(None); the core returns Ok(0). |
request_header_is_parsed_from_a_slice_once_whole (cuts at 0, 1, 17, 18, 19, 22 and one byte short); tcp_request_opens_and_replies_only_once_connected (first 10 bytes) |
| Users are matched on the processed UUID and reported by their configured UUID. | process_uuid on both add and get; get returns the stored Uuid. |
validator_matches_ignoring_bytes_6_and_7 (validator.rs) |
| An unknown user gets no response, and is refused for its id whatever flow it asks for. | Validator::get runs before the flow check; on None the core returns PermissionDenied before staging anything. |
unknown_uuid_is_refused, an_unknown_uuid_asking_for_vision_is_refused_as_unknown (core.rs) |
| The TCP response goes out once, and only after the outbound connects. | Event::Connected stages RESPONSE_HEADER under the replied flag. |
tcp_request_opens_and_replies_only_once_connected |
| A failed connect closes without a response. | ConnectFailed in State::Tcp calls Passthrough::on_outbound_gone, and nothing was staged before. |
a_refused_connect_closes_without_a_reply |
| A sniffed flow opens with the recovered domain and forwards the held prefix first. | open_sniffed sets flow.sniffed; open_tcp arms the relay deadline, then pushes Open and ForwardHeld. |
sniffing_holds_the_prefix_then_opens_with_the_domain |
| A UDP association is answered at once, opens its outbound on the first packet, sends only to the header target, and leaves a partial frame unconsumed. | State::Udp with the opened flag; SendTo always uses flow.destination. |
udp_association_replies_at_once_and_frames_both_ways |
| A mux carrier is answered at once and its sub-flows are demultiplexed. | Command::Mux stages the reply and hands off to Demux. |
vless_answers_mux_at_once_and_demultiplexes (protocols/tests/unit/mux/demux.rs) |
| Each mux downlink frame is staged once. | Every Demux call that writes out clears it first, so after feed it holds only that uplink’s declines, never the frames on_sub staged earlier. |
a_downlink_frame_is_not_sent_again_by_the_next_uplink, vless_answers_mux_at_once_and_demultiplexes (protocols/tests/unit/mux/demux.rs) |
| Without a flow, the client datagram codec frames every packet to the fixed target and reports every reply as coming from it. | seal_to ignores to; open_from returns self.target. |
datagram_codec_frames_to_the_fixed_target (codec.rs) |
Under Vision, the client datagram codec speaks XUDP: a mux header with the flow and no address, session 0 opened toward the first peer by a New without a global id, a Keep naming each later peer, a packet over MAX_DATA_LEN dropped without an error, replies attributed to the peer their frame names, KeepAlive skipped, End reported. |
Framing::Xudp in seal_to and open_xudp. |
a_vision_datagram_codec_speaks_xudp (codec.rs) |
| The client reserve covers the longest header the codecs emit, the Vision addons included. | RESERVE = REQUEST_HEADER_MAX + addons::ENCODED_MAX, and DATAGRAM_RESERVE is at least RESERVE. |
the_longest_vision_header_fits_the_declared_reserve (codec.rs), the_encoded_bound_is_the_vision_addons (addons.rs) |
| The core never stages more than its reserve beyond an event’s payload. | STAGING_RESERVE covers the reply, a length prefix, or downlink_overhead(BUF_SIZE) of mux headers; a shortfall is staging_full(). |
Exercised end to end by new_server_vs_new_client_tcp and new_server_vs_new_client_udp (protocols/tests/pipeline/vless.rs) |
Failure paths and cancellation
Section titled “Failure paths and cancellation”| Situation | What happens |
|---|---|
| Bad version, addons, command or address | handle returns Err (InvalidData); the runtime ends with RuntimeError::Core, and supervisor/src/serve.rs → serve_connection logs vless connection from <source> ended: proxy core: <error> at debug. No response is sent. Behind a Vision inbound the adapter’s read framer meets these first, and the line says transport: instead of proxy core:. |
| A known user’s Vision request at the plain core | Unsupported (vless flow (xtls vision) is not served by this core), same path. |
| Unknown user | PermissionDenied (invalid vless request user id), same path, whatever flow the header asks for. PermissionDenied is the kind every core uses for a refused credential, so drive also reports it to the supervisor’s guard with Report::failed (supervisor/src/guard.rs). |
| Client stops mid-header | The first event armed HANDSHAKE_TIMEOUT (10 s); Deadline returns client did not complete its request in time (TimedOut). A client that never sends a byte produces no event: supervisor/src/serve.rs → drive watches that case with the same timeout, per runtime step, until is_established() turns true, and fails with inbound handshake timed out after 10s. |
| Client closes before or during the header | TransportEof in Handshake finishes without error. |
| TCP dial fails | on_outbound_gone: ShutdownTransport, Finish; no response. |
| UDP outbound fails | ShutdownTransport, Finish, without Close. |
| One UDP send fails | The packet is dropped with a debug line; the association stays up. |
| Idle relay | After RELAY_IDLE_TIMEOUT (300 s) with no byte event, Timing::expired pushes Finish. |
| Uplink frame larger than the read buffer at its cap | The runtime reports RuntimeError::FrameTooLarge (protocol frame exceeds the read buffer) and the connection ends. With BUF_SIZE = 16 KiB, an uplink UDP frame on a plain VLESS association can carry at most 16 382 payload bytes, although its length field allows 65 535. |
| Cancellation | Dropping the runtime future closes the transport and every outbound with it; the core owns no tasks, channels or locks, so nothing outlives the connection. |
Limits
Section titled “Limits”| Name | Value | Where |
|---|---|---|
VlessCore::BUF_SIZE |
16 KiB | protocols/src/vless/core.rs |
STAGING_RESERVE (server) |
808 bytes | protocols/src/vless/core.rs |
MAX_DATAGRAM |
8192 bytes | protocols/src/vless/core.rs |
REQUEST_HEADER_MAX |
278 bytes, without addons | protocols/src/vless/protocol.rs |
Client STAGING_RESERVE (RESERVE, DATAGRAM_RESERVE) |
296 bytes: the longest header with the Vision addons | protocols/src/vless/codec.rs |
| Addons length | 255 bytes (one length byte); Vision’s addons are 18 (ENCODED_MAX) |
protocols/src/vless/protocol.rs, addons.rs |
| XUDP packet from the Vision client codec | at most MAX_DATA_LEN = 8192 bytes; a longer one is dropped |
protocols/src/vless/codec.rs |
| UDP length prefix | u16, at most 65535 bytes on the wire; 16 382 uplink and MAX_DATAGRAM downlink in practice |
protocols/src/vless/protocol.rs |
HANDSHAKE_TIMEOUT |
10 s | protocols/src/core/mod.rs |
RELAY_IDLE_TIMEOUT |
300 s | protocols/src/core/mod.rs |
SNIFF_TIMEOUT |
300 ms | protocols/src/sniff/mod.rs |
SNIFF_LIMIT |
4 KiB | protocols/src/sniff/mod.rs |
MAX_SESSIONS (mux sub-flows per carrier) |
256 | protocols/src/mux/demux.rs |
VLESS_BUF (the cap on the supervisor’s client runtime buffers) |
16 KiB | supervisor/src/topology/outbound/mod.rs |
The unit tests are compiled into the library through #[path] attributes and run with cargo test -p etemenanki-protocols --lib vless. The protocol tests are all synchronous slice tests. Core tests drive VlessCore through CoreHarness (protocols/src/core/harness.rs), which records effects and staged bytes without any I/O.
| Test | File | What it pins |
|---|---|---|
request_header_roundtrip_tcp_ipv4, request_header_roundtrip_udp_domain, request_header_roundtrip_ipv6 |
protocols/tests/unit/vless/protocol.rs |
The byte layout (offsets 0, 1..17, 17, 18) and a round trip for each address type. |
rejects_bad_version, rejects_an_unknown_or_malformed_flow_header, rejects_unknown_command |
same | Version, addons and command refusal, all InvalidData (commands 0, 4 and 0xFF); an addons length past the buffer is short input. |
parses_a_vision_flow_header_with_shifted_offsets |
same | A Vision header: the flow decoded, and the command and address read after the 18-byte addons. |
an_empty_payload_is_plain_vless, the_vision_flow_round_trips, an_empty_flow_field_is_none, a_seed_field_is_parsed_and_ignored, an_unknown_flow_is_refused, an_unknown_field_is_refused, malformed_protobuf_is_refused_not_panicked, the_encoded_bound_is_the_vision_addons |
protocols/tests/unit/vless/addons.rs |
The addons protobuf both ways, every refusal without a panic, and ENCODED_MAX as the length of the Vision addons. |
mux_command_synthesises_its_destination, mux_request_header_roundtrips |
same | A 19-byte mux header that leaves the next frame untouched. |
response_header_roundtrip, response_header_skips_addons, response_header_rejects_version |
same | The response header and addon skipping. |
length_packet_roundtrip, multiple_length_packets |
same | UDP framing. |
request_header_is_parsed_from_a_slice_once_whole, response_header_and_length_packets_are_parsed_from_slices |
same | The slice parsers return None at every cut point, report the bytes consumed, stop a mux header at 19 bytes, and refuse addons that do not decode and a wrong response version. |
validator_matches_ignoring_bytes_6_and_7 |
protocols/tests/unit/vless/validator.rs |
Processed-UUID lookup that returns the configured id. |
tcp_request_opens_and_replies_only_once_connected, a_refused_connect_closes_without_a_reply, unknown_uuid_is_refused |
protocols/tests/unit/vless/core.rs |
TCP handshake, deadline arming, reply timing and the failure paths. |
an_unknown_uuid_asking_for_vision_is_refused_as_unknown, a_known_uuid_asking_for_vision_is_unsupported_here |
same | The lookup before the flow check: PermissionDenied for an unknown id with the Vision flow, Unsupported for a known one. |
sniffing_holds_the_prefix_then_opens_with_the_domain |
same | Sniff phase, held prefix and deadlines: the relay deadline, then Open with the domain, then ForwardHeld. |
udp_association_replies_at_once_and_frames_both_ways |
same | UDP reply timing, lazy open, target pinning, partial frames and teardown. |
stream_codec_consumes_the_response_header_as_an_empty_frame, datagram_codec_frames_to_the_fixed_target |
protocols/tests/unit/vless/codec.rs |
Both client codecs without a flow. |
the_longest_vision_header_fits_the_declared_reserve |
same | A Vision header to a 255-byte domain is longer than REQUEST_HEADER_MAX, exactly STAGING_RESERVE, and start stages it into a buffer of that size; both codecs declare the same reserve. |
a_vision_datagram_codec_speaks_xudp |
same | The Vision datagram codec: the mux header with the flow, a New toward the first peer, a Keep to another, a 9000-byte packet dropped, and a Keep reply, a KeepAlive and an End opened. |
vless_answers_mux_at_once_and_demultiplexes |
protocols/tests/unit/mux/demux.rs |
The mux carrier through VlessCore, and that the next uplink sends a packet to another peer without staging the earlier reply again. |
a_downlink_frame_is_not_sent_again_by_the_next_uplink |
same | A reply read from out() in place, as VlessCore stages it, is not queued again by the next feed. |
new_server_vs_new_client_tcp, new_server_vs_new_client_udp |
protocols/tests/pipeline/vless.rs |
The real runtimes over loopback: a 70 000-byte echo with half-close, and UDP packets of 8 and 1500 bytes. Run with cargo test -p etemenanki-protocols --test pipeline vless. |
app_client_* and app_server_* over WebSocket, gRPC and TLS |
app/tests/integration/e2e_xray.rs |
Interop with a real Xray binary in both directions, with VLESS as the tunnel protocol. |
vless_mux_tcp_single_stream, vless_mux_tcp_concurrent_streams_stay_separate, vless_mux_over_ws_tls, vless_xudp_datagram_roundtrip, xudp_attributes_replies_to_the_right_peer |
app/tests/integration/e2e_xray_mux.rs |
An Xray client with mux enabled against the VLESS server. |
xray_reality_client_reaches_our_server, our_reality_client_reaches_an_xray_server, xray_vision_client_reaches_our_server, our_vision_client_reaches_an_xray_server, vision_splices_inner_tls_xray_client_to_our_server, vision_splices_inner_tls_our_client_to_xray_server, our_vision_client_carries_udp_to_our_server, our_vision_client_carries_udp_to_an_xray_server, xray_vision_client_carries_udp_to_our_server and the negatives |
app/tests/integration/e2e_xray_reality.rs |
VLESS over REALITY with xray-core v26.10.17 in both directions, without and with Vision, and UDP through Vision as XUDP; the Vision tests are on XTLS Vision. |
an_http_host_routes_an_ip_addressed_flow and the other sniffing tests |
app/tests/integration/e2e_sniff.rs |
Sniffing through a VLESS inbound, end to end. |
The Xray interop tests build Xray with go build from the reference tree in the workspace and skip themselves on a machine without Go (printing SKIP: `go` not available; skipping xray interop test) or when that build fails (SKIP: failed to build xray-core).