Skip to content

XTLS Vision

Source files: 20 · checked against Etemenanki 46c12e4
  • Etemenanki/protocols/src/vless/vision/mod.rs
  • Etemenanki/protocols/src/vless/vision/padding.rs
  • Etemenanki/protocols/src/vless/vision/filter.rs
  • Etemenanki/protocols/src/vless/vision/framer.rs
  • Etemenanki/protocols/src/vless/vision/stream.rs
  • Etemenanki/protocols/src/vless/codec.rs
  • Etemenanki/protocols/src/transports/stream.rs
  • Etemenanki/protocols/src/transports/connect.rs
  • Etemenanki/protocols/src/transports/reality.rs
  • Etemenanki/reality/src/stream.rs
  • Etemenanki/supervisor/src/serve.rs
  • Etemenanki/supervisor/src/build/inbound.rs
  • Etemenanki/supervisor/src/build/outbound.rs
  • Etemenanki/supervisor/src/build/validate.rs
  • Etemenanki/supervisor/src/topology/inbound/mod.rs
  • Etemenanki/protocols/tests/unit/vless/vision/padding.rs
  • Etemenanki/protocols/tests/unit/vless/vision/filter.rs
  • Etemenanki/protocols/tests/unit/vless/vision/framer.rs
  • Etemenanki/protocols/tests/unit/vless/vision/stream.rs
  • Etemenanki/app/tests/integration/e2e_xray_reality.rs

XTLS Vision (xtls-rprx-vision) is a VLESS flow that changes how the body of a VLESS connection travels. It pads the first frames so that the lengths of the VLESS header and of an inner TLS handshake do not show, and, when the tunnel carries a TLS 1.3 session of its own, lets both ends leave the outer TLS and copy the raw TCP socket, so the inner TLS is not encrypted twice. protocols/src/vless/vision/ is a port of the padding, unpadding and inner-TLS filter of Xray’s proxy/proxy.go, with a stream adapter of its own on top. It runs only over REALITY.

This page is for contributors who change that module or the places that put it in front of a VLESS core or codec. The VLESS wire format, the request addons that carry the flow and VlessCore are on the VLESS page; the REALITY record layer the adapter sits on is on REALITY transport and in the etemenanki-reality pages.

The module does It leaves to others
Frame the VLESS body into padded Vision blocks, with the user id on the first block of each direction. Parsing and authenticating the VLESS header: VlessCore, which reads it unframed through the adapter.
Recover the body from the peer’s blocks across any read boundary, and report the terminal command. Announcing the flow in the request addons: VlessStream::new with VlessFlow::Vision.
Strip the flow from the request header on the server, so the plain VlessCore serves the body. Refusing Vision off REALITY: the supervisor’s validation (supervisor/src/build/validate.rs).
Watch the first buffers of both directions for an inner TLS handshake, and end the framing: with COMMAND_DIRECT at the first write of whole application-data records after a TLS 1.3 ServerHello, with COMMAND_END otherwise. The TLS 1.3 record layer and its into_raw_parts: etemenanki-reality, through protocols/src/transports/reality.rs.
Send its own writes to the bare socket once its COMMAND_DIRECT is out, and take the socket out of the record layer when the peer’s COMMAND_DIRECT arrives, draining every byte the record layer already holds. Deciding which connections get the adapter: supervisor/src/serve.rs and supervisor/src/build/outbound.rs.
File Contents
mod.rs The commands COMMAND_CONTINUE, COMMAND_END, COMMAND_DIRECT; DEFAULT_SEED, MAX_BUFFER, FIRST_FRAME_OVERHEAD, HEADER_LEN; re-exports.
padding.rs pad, which builds one block; Unpad and Unpadded, which take blocks apart.
filter.rs TlsFilter, the inner-TLS inspector.
framer.rs Role, ReadFramer and ReadOut, WriteFramer: the sans-I/O halves of the adapter. The private pad_body, is_complete_record and reshape port Xray’s VisionWriter.WriteMultiBuffer, IsCompleteRecord and ReshapeMultiBuffer.
stream.rs VisionStream, the poll shell over a REALITY stream, with its private Splice and WriteHalf states. Compiled only with the reality feature, like the REALITY transport.

The first four files are sans-I/O and build without the feature; the tests drive them with byte slices.

Vision frames only the body. On each side the VLESS header stays as it is: the client’s request header on the uplink, the server’s two-byte response header on the downlink. Everything after it is a sequence of blocks:

Field Size Meaning
user id 16 Only on the first block of each direction: the VLESS user id, which the client knows and the server learns from the request header.
command 1 0 COMMAND_CONTINUE: more blocks follow. 1 COMMAND_END: the framing ends, the rest of the stream is plain under the outer TLS. 2 COMMAND_DIRECT: the framing ends and the sender has switched to the raw socket.
content length 2 Big-endian.
padding length 2 Big-endian.
content content length Body bytes.
padding padding length Zeros.

pad(content, command, uuid, long_padding, seed) builds one block. With the seed DEFAULT_SEED = [900, 500, 900, 256], Xray’s:

  • Long padding, when the caller asks for it and the content is shorter than 900 bytes: a random length in 0..500, plus 900, minus the content length. Content and padding together then take 900 to 1399 bytes, whatever the size of a small write.
  • Short padding otherwise: a random length in 0..256.

The padding is then capped so that the whole block fits MAX_BUFFER (8192 bytes, Xray’s buf.Size) with the 21-byte first-block overhead. The write framer cuts each write into blocks as Xray’s ReshapeMultiBuffer does (reshape): first into buffers of MAX_BUFFER bytes, then each buffer of MAX_CONTENT = MAX_BUFFER - FIRST_FRAME_OVERHEAD = 8171 bytes or more in two, at its last application-data record header (17 03 03) when that starts between 21 and 8171 bytes in, else at 4096. No block carries more than 8171 bytes of content.

sequenceDiagram
    participant CC as VlessStream (client codec)
    participant CV as VisionStream client
    participant SV as VisionStream server
    participant SC as VlessCore
    CC->>CV: request header with the Vision addons, then body
    CV->>SV: header unframed, body in blocks, user id on the first
    Note over SV: ReadFramer parses the header, learns the user id, strips the flow
    SV->>SC: header without addons, then the body content
    SC-->>SV: response header, then reply bytes
    SV-->>CV: response header unframed, reply in blocks, user id on the first
    CV-->>CC: response header, then reply content
    Note over CV,SV: After an inner TLS 1.3 ServerHello each writer ends with COMMAND_DIRECT and writes raw, and each reader follows when the peer sends its COMMAND_DIRECT

The core and the codec never see a block. Each side’s ReadFramer hands them the unframed header and the content, and each side’s WriteFramer frames what they write.

protocols/src/vless/vision/padding.rs
pub fn pad(
content: &[u8],
command: u8,
uuid: Option<&[u8; 16]>,
long_padding: bool,
seed: [u32; 4],
) -> Vec<u8>;
pub struct Unpad { /* … */ }
pub struct Unpadded {
pub content: Vec<u8>,
pub command: Option<u8>,
pub leftover: Vec<u8>,
}
impl Unpad {
pub fn new(uuid: [u8; 16]) -> Self;
pub fn push(&mut self, input: &[u8]) -> Unpadded;
}

Unpad is a state machine over a private Phase: Initial, then Command(left) for the five header bytes, Content(left) and Padding(left). Every phase counts down across calls, so a block can arrive split anywhere.

  • In Initial it holds bytes until 16 are in, since the user id may arrive split. If they are the expected id, it starts on the first block. If they are not, it treats the stream as unframed: it reports COMMAND_DIRECT with everything held so far as leftover.
  • After a block whose command is COMMAND_CONTINUE, it starts on the next block. After any other command it is terminated: that call reports the command and the bytes after the block as leftover, and every later call returns its whole input as leftover.
protocols/src/vless/vision/filter.rs
pub struct TlsFilter { /* … */ }
impl TlsFilter {
pub fn new() -> Self;
pub fn inspect(&mut self, b: &[u8]);
pub fn done(&self) -> bool;
pub fn is_tls(&self) -> bool;
pub fn enable_direct(&self) -> bool;
pub(crate) fn is_tls12_or_above(&self) -> bool;
pub(crate) fn packets_left(&self) -> i32;
}

A port of Xray’s XtlsFilterTls. One filter serves both directions of a connection, as Xray’s TrafficState does: the write framer owns it, inspects every write it pads, and is shown the body bytes the reader unframes through WriteFramer::observe. Each inspect looks at one buffer, at most PACKETS_TO_FILTER = 8 of them across both directions:

It sees Effect
A record starting 16 03 03 with handshake type 02 (ServerHello) is_tls; the cipher suite is read past the session id when the record is at least 79 bytes; the record is then searched for the supported_versions extension naming TLS 1.3 (00 2b 00 02 03 04), across later buffers if the record spans them.
supported_versions with TLS 1.3 done; enable_direct unless the suite is TLS_AES_128_CCM_8_SHA256 (0x1305).
The end of the ServerHello record without it done, without enable_direct: TLS 1.2 or older.
A record starting 16 03 with handshake type 01 (ClientHello) is_tls, no verdict.
Eight buffers done, whatever was seen.

is_tls12_or_above reports that a ServerHello went past. packets_left is the budget still unspent, and 0 once a verdict is in, as Xray zeroes its count there. The write framer reads both to end traffic that is not TLS one buffer early.

protocols/src/vless/vision/framer.rs
pub enum Role {
Server,
Client,
}
pub struct ReadOut {
pub out: Vec<u8>,
pub direct: bool,
pub leftover: Vec<u8>,
}
impl ReadFramer {
pub fn server() -> Self;
pub fn client(uuid: [u8; 16]) -> Self;
pub fn uuid(&self) -> Option<[u8; 16]>;
pub fn is_direct(&self) -> bool;
pub(crate) fn take_header_len(&mut self) -> Option<usize>;
pub fn push(&mut self, wire: &[u8]) -> io::Result<ReadOut>;
}
impl WriteFramer {
pub fn server() -> Self;
pub fn client(uuid: [u8; 16]) -> Self;
pub fn set_uuid(&mut self, uuid: [u8; 16]);
pub fn is_plain(&self) -> bool;
pub(crate) fn is_direct(&self) -> bool;
pub(crate) fn observe(&mut self, incoming: &[u8]);
pub fn set_direct(&mut self);
pub fn direct_frame(&mut self) -> Vec<u8>;
pub fn frame(&mut self, content: &[u8]) -> io::Result<Vec<u8>>;
}

ReadFramer turns wire bytes into what the core or codec reads. Its phases are Header, Body, Plain and Direct.

  • Header collects bytes until the header parses. A server parses the request header with parse_request_header, refuses one without the Vision flow (vless vision: the request did not carry the vision flow, InvalidData), learns the user id, and emits the header with the addons length set to 0 and the addons removed. A client passes the response header through unchanged. The bytes after the header in the same read start the body. The framer records how long the header it emitted was, and take_header_len hands that length out once, so the shell can show the filter the body alone.
  • Body feeds an Unpad built for the user id and emits the content. A terminal COMMAND_END moves to Plain and emits the leftover as content: the stream is still under the outer TLS. Any other terminal command, COMMAND_DIRECT in practice, moves to Direct and returns the leftover with direct: true for the shell.
  • Plain emits its input unchanged; Direct returns it as leftover.

WriteFramer turns what the core or codec writes into wire bytes. Its phases are Header, Padding, Plain and Direct.

  • Header passes the header through: a server the two bytes of RESPONSE_HEADER, a client whatever parse_request_header says the request header takes, buffering until it parses.

  • Padding runs pad_body over every write and picks the command of each block as Xray’s VisionWriter does. It shows the whole write to the filter once, notes whether the write is nothing but whole application-data records (is_complete_record: every record starts 17 03 03 with a non-zero length, and the last one ends with the write), and cuts it into chunks with reshape. Then, chunk by chunk:

    Chunk Block
    Starts 17 03 03, at least 6 bytes, in a whole-record write, while the traffic is TLS (is_tls) The framing ends with this write. The last chunk carries the terminal command, earlier ones COMMAND_CONTINUE. The terminal is COMMAND_DIRECT when the filter has enable_direct (it saw a TLS 1.3 ServerHello) and COMMAND_END otherwise.
    Any chunk while no ServerHello has been seen (is_tls12_or_above false) and the budget is down to one buffer or spent (packets_left() <= 1) COMMAND_END, and the rest of the write follows unframed: the framing ends one buffer before the filter gives up, as Xray does for older readers.
    Any other chunk COMMAND_CONTINUE, except the last chunk of a write in which an application-data chunk came earlier: that one carries the terminal command.

    The user id goes on the first block the framer ever sends. Long padding applies while the traffic is TLS and to every application-data chunk; after the first application-data chunk of a write the other chunks get short padding, as does all traffic not seen as TLS. A write that ends with COMMAND_DIRECT moves the framer to Direct, one that ends with COMMAND_END to Plain. Traffic that is TLS 1.2 or later but whose application data never comes as a whole-record write stays framed with COMMAND_CONTINUE.

  • direct_frame builds an empty COMMAND_DIRECT block, with the user id if no block has gone out yet. The shell sends it when the peer’s COMMAND_DIRECT arrives while its own writer is still framing. set_direct then moves to Direct. is_direct is true in Direct however the framer got there, and Plain and Direct pass writes through.

Either peer’s writer therefore ends the framing with COMMAND_DIRECT on its own, as Xray’s writer does. Until etemenanki-protocols 6.2.0 no code path sent COMMAND_DIRECT first: the only one was direct_frame, sent after the peer’s, so two Etemenanki peers stayed framed under the outer TLS.

protocols/src/vless/vision/stream.rs
pub struct VisionStream { /* … */ }
impl VisionStream {
pub fn server(stream: RealityStream) -> Self;
pub fn client(stream: RealityStream, uuid: [u8; 16]) -> Self;
}
impl AsyncRead for VisionStream { /* … */ }
impl AsyncWrite for VisionStream { /* … */ }

RealityStream is protocols/src/transports/reality.rs’s own wrapper, so no etemenanki_reality type appears in the vless code. The shell holds:

Field Role
inner Inner::Tls(Box<RealityStream>) while framed, Inner::Raw(TcpStream) after the switch, Inner::Taken only while into_raw_parts runs.
read, write The two framers.
out_buf Content from the read framer not yet handed to a poll_read.
wire_buf Framed bytes from the write framer not yet written.
raw_in Raw bytes to serve before the socket’s own, after the switch.
scratch READ_CHUNK = 16 KiB, the most decrypted plaintext pulled from the record layer at once.
splice Splice::None, Pending once the peer’s COMMAND_DIRECT has arrived, Done once the socket is out of the record layer and raw both ways.
write_half WriteHalf::Tls while our writes go through the record layer, Switching once our COMMAND_DIRECT is queued, Raw once it and every sealed record are on the wire.
read_eof The REALITY stream ended while framed; later reads return end of stream.
  • poll_read hands back out_buf first. Framed, it reads one chunk of plaintext from the REALITY stream, pushes it through the read framer, passes a newly learned user id to the write framer (set_uuid), shows the filter the chunk’s unframed body without the header (take_header_len, observe), and loops, so a record that held only header or padding does not look like the end of the stream. When the read framer reports direct, the leftover goes to raw_in and splice becomes Pending. After the switch it serves raw_in, then reads the socket. While only our write half is raw, reads still come through the REALITY stream.
  • poll_write first finishes a pending read-side switch and our own write-side switch. With the socket raw it writes to it. With only our write half raw it writes to the socket under the REALITY stream (RealityStream::socket, try_write once poll_write_ready says so), past the record layer. Otherwise it flushes any framed bytes still pending, frames the new write, and sets write_half to Switching when that write ended the framing with COMMAND_DIRECT. It reports the whole write as taken once the framed bytes are in wire_buf, so at most one write’s worth of framed bytes waits for the socket.
  • poll_flush finishes the pending switches, then flushes wire_buf and the REALITY stream. With our write half raw it has nothing to do: a bare TCP socket holds nothing back.
  • poll_shutdown finishes the pending switches, then shuts the REALITY stream down while our writes go through it. Past our direct frame it half-closes the socket itself (shutdown(Write)), with no close_notify, because the peer reads that direction bare.

The record layer can surrender the socket only as a whole: RealityStream::into_raw_parts consumes the stream and gives back the socket, the decrypted content not yet read and the bytes received after the current record. Reading raw while the record layer still holds the socket is not possible, but writing raw is, as long as nothing is sealed after the first raw byte: RealityStream::socket lends the socket underneath. The shell therefore switches in two steps, as Xray switches each direction on its own (VisionWriter, VisionReader).

  1. A write ends the framing with COMMAND_DIRECT (Framers), and poll_write sets write_half to Switching.
  2. The next poll_write, poll_flush or poll_shutdown, or poll_switch, runs poll_write_switch first. It flushes wire_buf, then the REALITY stream, so our direct frame and every sealed record are on the wire, and sets Raw.
  3. From then on our writes go to the bare socket and nothing more is sealed: a record now would land after raw bytes. Reads still come through the record layer until the peer’s COMMAND_DIRECT.
sequenceDiagram
    participant P as Peer
    participant R as poll_read
    participant S as poll_switch
    P->>R: block with COMMAND_DIRECT, then raw bytes
    R->>S: splice = Pending, leftover kept in raw_in
    opt our writer is still framing
        S->>P: framed bytes still pending, then an empty COMMAND_DIRECT block
    end
    Note over S: Every sealed record on the wire
    Note over S: into_raw_parts gives the socket, the unread plaintext and the buffered bytes
    Note over S: raw_in = leftover, then plaintext, then buffered
    S-->>R: splice = Done
    R->>P: raw reads and writes from now on

poll_switch runs from whichever of poll_read, poll_write, poll_flush or poll_shutdown is polled while the switch is pending:

  1. If our write half is still under the record layer, flush wire_buf; then, unless the write framer already ended the framing with COMMAND_END, queue direct_frame, mark the writer Direct and set write_half to Switching.
  2. Finish the write-side switch with poll_write_switch, which flushes the direct frame and the REALITY stream. When the writer had ended with COMMAND_END, flush the REALITY stream here instead: into_raw_parts refuses to run while sealed bytes are unwritten (REALITY: flush the stream before taking it apart). When our write half was already raw, nothing has been sealed since its flush.
  3. Take the stream apart and build raw_in from, in order, the bytes the read framer found after the peer’s COMMAND_DIRECT, the record layer’s decrypted but unread content, and its received but undecrypted bytes.
  4. Mark the socket raw both ways.

The order is right because the REALITY stream decrypts a record only once the previous one has been read, and reads one record at a time: whatever the peer wrote raw after its last record is still in the buffered bytes, never decrypted by mistake.

A peer’s COMMAND_DIRECT means it has already switched its own writes to raw, and it accepts our COMMAND_DIRECT arriving after that. Each side’s filter sees the same ServerHello, one as it writes it and the other as it reads it, so each writer ends with COMMAND_DIRECT at its first write of whole application-data records: against Xray and between two Etemenanki peers alike, each side’s write half goes raw first and its read half follows when the peer’s command arrives. poll_switch queues the empty direct frame at most once: write_half leaves Tls the moment the frame is queued, so a switch polled again while that frame is still being flushed does not send a second one.

The supervisor builds the adapter where the transport stream’s concrete type is still known. Validation has already refused Vision on any transport but REALITY (Flow in the spec).

Side Where What
Inbound supervisor/src/build/inbound.rs → build_handler StreamProtocol::Vless { users, vision }, with vision set when the spec’s flow is VlessFlow::Vision (supervisor/src/topology/inbound/mod.rs).
Inbound supervisor/src/serve.rs → serve_tcp For a Vision inbound, each accepted stream goes through TransportStream::into_vision_server before serve_connection is spawned. It turns TransportStream::Reality into TransportStream::Vision(VisionStream::server(..)) and refuses every other transport (vless vision rides only over reality); a refusal is logged at debug as <tag>: vision setup failed: … and the connection is dropped. The core is the ordinary VlessCore.
Outbound supervisor/src/build/outbound.rs → transport_connector With vision = Some(uuid), builds TransportKind::reality(client).vision(uuid).
Outbound supervisor/src/build/outbound.rs → build_outbound A TCP flow gets VlessStream::new(&uuid, &f.destination, vless_flow), a UDP flow VlessDatagram::with_flow(&uuid, &f.destination, vless_flow); both codecs run over the Vision stream the connector dialed.
Outbound protocols/src/transports/connect.rs → TransportKind::wrap After the REALITY client handshake, yields TransportStream::Vision(VisionStream::client(stream, uuid)). TransportKind::vision changes nothing on a transport that is not REALITY.

TransportStream::Vision (protocols/src/transports/stream.rs) forwards reads and writes to the VisionStream, so the runtimes over it are the same as for any other transport.

A UDP flow through a Vision outbound rides XUDP, as Xray’s VLESS client sends it. With VlessFlow::Vision, VlessDatagram::with_flow writes a CMD_MUX request header that carries the Vision addons, and sends each packet as a mux.cool frame of session 0 that names its peer: a New frame toward the first, Keep frames after it. A packet longer than MAX_DATA_LEN (8 KiB) is dropped. The Vision adapter frames that stream like any other body. Each body write starts with a frame’s metadata length rather than a TLS record header, so the writer ends the framing with COMMAND_END one buffer before the filter gives up. On a Vision inbound the read framer strips the flow from the mux request as from any other, and VlessCore serves the carrier with Demux. The codec is on VLESS, the frames on mux.cool and XUDP.

Invariant Mechanism Pinned by
The header is unframed, and the server’s core sees it without the flow. The read framer’s Header phase; the server re-emits the header with addonsLen = 0. client_uplink_reaches_the_server_unframed_header_and_body, server_downlink_reaches_the_client_unframed_header_and_body
A block can be split anywhere, the user id included. Unpad counts every phase down across calls and holds the id until 16 bytes are in. unpad_works_across_any_chunk_boundary (chunks of 1, 2, 3, 7, 16 and 64 bytes), a_reader_rebuilds_across_tiny_reads
A body that does not begin with the user id is not unpadded. Unpad reports COMMAND_DIRECT with the bytes as leftover. a_wrong_leading_uuid_is_treated_as_raw
Only a terminal command ends the framing. block_done continues on COMMAND_CONTINUE. a_continue_only_stream_yields_no_terminal_command, unpad_recovers_the_content_and_reports_the_command
Blocks are padded long while the traffic is TLS. pad_body passes is_tls as long_padding, and true for the application-data blocks. long_padding_hides_a_short_header, a_frame_carries_its_header_and_content (the pad branches)
Traffic not seen as TLS 1.2 or later ends the framing with COMMAND_END one buffer before the filter gives up. pad_body ends when !is_tls12_or_above() && packets_left() <= 1. non_tls_traffic_ends_the_framing (plain after the seventh write)
After a TLS 1.3 ServerHello, the first write of whole application-data records ends the framing with COMMAND_DIRECT, and what follows passes unframed. is_complete_record and pad_body’s terminal; the Direct phase passes writes through. a_client_sends_direct_with_its_first_application_data_after_tls13
Part of a record, or a write that mixes another record type with application data, does not end the framing. is_complete_record is false for it. a_partial_application_data_record_keeps_the_framing, a_client_sends_direct_with_its_first_application_data_after_tls13 (its change_cipher_spec and Finished write)
Inner TLS older than 1.3 ends with COMMAND_END, and the outer TLS stays. The terminal is COMMAND_DIRECT only with enable_direct. inner_tls12_ends_the_framing_on_application_data
Only TLS 1.3 with a suite other than 0x1305 counts as direct-capable. TlsFilter::inspect. an_inner_tls13_handshake_enables_direct, tls12_does_not_enable_direct, the_one_barred_tls13_suite_does_not_enable_direct, a_client_hello_is_tls_but_not_a_verdict, non_tls_traffic_stops_after_the_packet_budget, a_short_buffer_is_handled_without_panicking
A Vision adapter is only in front of a Vision request. The server read framer refuses another flow. a_plain_request_is_refused_by_the_server_framer
No sealed record follows a raw byte. poll_write_switch flushes our direct frame and the REALITY stream before the first raw write, and nothing is sealed after it. two_of_our_vision_peers_reach_the_raw_socket
No byte is lost or reordered at the switch. poll_switch flushes before into_raw_parts and serves leftover, plaintext, then buffered bytes. two_of_our_vision_peers_reach_the_raw_socket, vision_splices_inner_tls_xray_client_to_our_server, vision_splices_inner_tls_our_client_to_xray_server
Situation What happens
A request without the Vision flow at a Vision inbound The read framer fails InvalidData; the runtime’s read fails and the supervisor logs vless connection from <source> ended: transport: vless vision: the request did not carry the vision flow.
A malformed request header at a Vision inbound The read framer meets it first, with the same errors as parse_request_header, reported with the prefix transport:.
A framed read or write after the switch NotConnected: vless vision: framed read after the direct switch, vless vision: framed write after the direct switch, or vless vision: the stream is past the direct switch. They guard states the poll methods are not expected to reach.
into_raw_parts fails The error is returned from the poll that ran the switch, and the connection ends.
A write of zero bytes to the REALITY stream WriteZero.
Cancellation Dropping the VisionStream drops the REALITY stream or the raw socket with it; the shell owns no task, channel or timer.
Name Value Where
MAX_BUFFER 8192 bytes per block vision/mod.rs
FIRST_FRAME_OVERHEAD, HEADER_LEN 21 and 5 bytes vision/mod.rs
MAX_CONTENT 8171 bytes of content per block; a buffer this long or longer is split in two vision/framer.rs → reshape
DEFAULT_SEED [900, 500, 900, 256] vision/mod.rs
PACKETS_TO_FILTER 8 buffers, both directions together vision/filter.rs
Early COMMAND_END for traffic not seen as TLS 1.2 or later once at most one buffer of the budget is left vision/framer.rs → pad_body
READ_CHUNK 16 KiB of plaintext per read vision/stream.rs
Framed bytes waiting for the socket One write’s worth vision/stream.rs → poll_write

The unit tests are compiled into the library through #[path] attributes. The sans-I/O ones run with cargo test -p etemenanki-protocols --lib vless::vision. VisionStream’s own test is compiled only with the reality feature, so cargo test -p etemenanki-protocols --features reality --lib vless::vision runs it too. The app’s integration tests drive the adapter against Xray and against itself.

Test File What it pins
a_frame_carries_its_header_and_content, long_padding_hides_a_short_header protocols/tests/unit/vless/vision/padding.rs The block layout and both padding branches.
unpad_recovers_the_content_and_reports_the_command, unpad_works_across_any_chunk_boundary, a_wrong_leading_uuid_is_treated_as_raw, a_continue_only_stream_yields_no_terminal_command same Unpad: content, terminal command and leftover, at every split.
an_inner_tls13_handshake_enables_direct, tls12_does_not_enable_direct, the_one_barred_tls13_suite_does_not_enable_direct, a_client_hello_is_tls_but_not_a_verdict, non_tls_traffic_stops_after_the_packet_budget, a_short_buffer_is_handled_without_panicking protocols/tests/unit/vless/vision/filter.rs The filter’s verdicts on synthetic ServerHello and ClientHello records.
client_uplink_reaches_the_server_unframed_header_and_body, server_downlink_reaches_the_client_unframed_header_and_body, a_reader_rebuilds_across_tiny_reads, non_tls_traffic_ends_the_framing, a_plain_request_is_refused_by_the_server_framer protocols/tests/unit/vless/vision/framer.rs The two framers against each other: the header, the flow stripped, one-byte reads, COMMAND_END on the seventh write of traffic that is not TLS, and the refusal.
a_client_sends_direct_with_its_first_application_data_after_tls13, a_partial_application_data_record_keeps_the_framing, inner_tls12_ends_the_framing_on_application_data same The writer’s terminal. A client shown a synthetic TLS 1.3 ServerHello keeps framing its change_cipher_spec and Finished, sends COMMAND_DIRECT with its first whole application-data record and then passes writes through, and the server reader reports direct with every byte in order. Part of a record keeps the framing. After a TLS 1.2 ServerHello the first application data ends with COMMAND_END and the rest arrives plain.
two_of_our_vision_peers_reach_the_raw_socket protocols/tests/unit/vless/vision/stream.rs Our client and server VisionStream over a real REALITY pair on 127.0.0.2, with a local OpenSSL dest: an inner TLS 1.3 echo through them answers two short rounds and a 48 KiB one byte for byte, and both sides end with the socket raw both ways.
xray_vision_client_reaches_our_server, our_vision_client_reaches_an_xray_server app/tests/integration/e2e_xray_reality.rs A payload through xray-core v26.10.17 with the Vision flow over REALITY, in both directions.
vision_splices_inner_tls_xray_client_to_our_server, vision_splices_inner_tls_our_client_to_xray_server same A SOCKS CONNECT to a local TLS 1.3 echo, then an OpenSSL client over it, so a real inner TLS 1.3 session crosses the tunnel and both peers leave the outer TLS; the payload must come back byte for byte.
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 same SOCKS UDP through a Vision outbound, as XUDP: three datagrams alternating between two UDP echoes, each answered by the peer it went to and attributed to that peer. Our client to our server, our client to Xray’s server, and Xray’s Vision client to our server.

The integration tests run with cargo test -p etemenanki-app --test integration e2e_xray_reality. The ones that drive Xray build it from the reference tree with go build and skip themselves without Go, as the other Xray interop tests do; our_vision_client_carries_udp_to_our_server runs two etemenanki-app processes and needs no Xray. dest and the TLS echo are local OpenSSL servers on 127.0.0.2, so no test needs the network.