Skip to content

Transports: REALITY

Source files: 25 · checked against Etemenanki 46c12e4 · katana v6.1.0
  • Etemenanki/protocols/Cargo.toml
  • Etemenanki/protocols/src/transports/mod.rs
  • Etemenanki/protocols/src/transports/reality.rs
  • Etemenanki/protocols/src/transports/camouflage.rs
  • Etemenanki/protocols/src/transports/accept.rs
  • Etemenanki/protocols/src/transports/connect.rs
  • Etemenanki/protocols/src/transports/stream.rs
  • Etemenanki/protocols/src/core/mod.rs
  • Etemenanki/supervisor/Cargo.toml
  • Etemenanki/supervisor/src/topology/spec_plan/transport.rs
  • Etemenanki/supervisor/src/topology/spec_plan/plan.rs
  • Etemenanki/supervisor/src/build/validate.rs
  • Etemenanki/supervisor/src/build/inbound.rs
  • Etemenanki/supervisor/src/build/outbound.rs
  • Etemenanki/supervisor/src/serve.rs
  • Etemenanki/app/src/transport.rs
  • Etemenanki/app/src/lower.rs
  • Etemenanki/protocols/tests/pipeline/reality.rs
  • Etemenanki/supervisor/tests/unit/serve.rs
  • Etemenanki/supervisor/tests/unit/validate.rs
  • Etemenanki/app/tests/unit/transport.rs
  • Etemenanki/app/tests/unit/lower.rs
  • Etemenanki/app/tests/integration/e2e_xray_reality.rs
  • katana/src/lower/inbound.rs
  • katana/src/api/newv2board.rs

REALITY is a transport for VLESS only: a TLS 1.3 of its own that passes a server off as another site, dest. The protocol itself lives in the etemenanki-reality crate (overview). This page covers the glue around it: the protocols crate’s reality feature and its wrapper types, the inbound transport that dials dest and may hand a socket back as a relay, the client dial, and how the supervisor validates, builds and serves a VLESS + REALITY inbound or outbound. It ends with the interop tests against a real Xray.

The XTLS Vision flow, which rides only over REALITY, is on VLESS Vision. How a user configures REALITY is on the REALITY guide.

Layer Does File
protocols Wraps the crate’s server, client, stream and relay in types of its own; decodes Xray’s formats into io::Error results protocols/src/transports/reality.rs, camouflage.rs
protocols Dials dest for every accepted socket and returns either a stream or a Disposition::Camouflage protocols/src/transports/accept.rs
protocols Dials a REALITY server as a client protocols/src/transports/connect.rs
supervisor Holds the decoded settings in the spec, refuses REALITY under anything but VLESS, builds the transport supervisor/src/topology/spec_plan/transport.rs, supervisor/src/build/
supervisor Runs a camouflage relay after dropping the handshake permit, outside the ban guard supervisor/src/serve.rs
front ends Lower their config into RealityServerSpec or RealityClientSpec with the protocols decoders etemenanki-app, katana

etemenanki-protocols takes etemenanki-reality as an optional dependency of its reality feature, off by default like hysteria and tun:

protocols/Cargo.toml
reality = ["dep:etemenanki-reality"]

The supervisor depends on the protocols crate with features = ["hysteria", "tun", "reality"], and etemenanki-app names the same three, so every build of the app or katana has REALITY.

No type of etemenanki-reality appears in the protocols crate’s public API, and a crate-local mirror of RawParts keeps the reality crate’s type out of the Vision code too. A REALITY fix is therefore a release of etemenanki-reality alone; downstreams pick it up through a lockfile update.

protocols/src/transports/reality.rs
pub fn decode_private_key(text: &str) -> io::Result<[u8; 32]>;
pub fn decode_public_key(text: &str) -> io::Result<[u8; 32]>;
pub fn decode_short_id(text: &str) -> io::Result<[u8; 8]>;
pub fn decode_client_version(text: &str) -> io::Result<[u8; 3]>;
#[derive(Clone)]
pub struct RealityServer { /* Arc<ServerConfig>, dest, dialer, resolver, strategy, last warning */ }
impl RealityServer {
pub fn new<N, I>(private_key: &str, server_names: N, short_ids: I, dest: Destination) -> io::Result<Self>;
pub fn from_bytes<N, I>(private_key: &[u8; 32], server_names: N, short_ids: I, dest: Destination)
-> io::Result<Self>;
pub fn max_time_diff(self, max: Duration) -> Self;
pub fn client_versions(self, min: Option<&str>, max: Option<&str>) -> io::Result<Self>;
pub fn client_version_bounds(self, min: Option<[u8; 3]>, max: Option<[u8; 3]>) -> Self;
pub fn hybrid_required(self, required: bool) -> Self;
pub fn dial_with(self, dialer: Dialer, resolver: Resolver, strategy: AddressFamilyStrategy) -> Self;
}
#[derive(Clone, Debug)]
pub struct ClientConfig(/* etemenanki_reality::client::ClientConfig */);
impl ClientConfig {
pub fn new(server_name: &str, public_key: &str, short_id: &str) -> io::Result<Self>;
pub fn from_bytes(server_name: &str, public_key: &[u8; 32], short_id: [u8; 8]) -> io::Result<Self>;
pub fn with_client_version(self, version: [u8; 3]) -> Self;
}
pub struct RealityStream(/* etemenanki_reality::RealityStream<TcpStream> */);
// AsyncRead, AsyncBufRead, AsyncWrite; socket() and into_raw_parts() are crate-private, for Vision

The module exists only with the feature. Every crate error (ConfigError) becomes an io::Error of kind InvalidInput carrying the crate’s message, which never repeats a key or a shortId. The decoders are the ones etemenanki-app calls when it lowers a config, and katana when it reads a UniProxy panel’s REALITY settings and lowers a node. RealityServer’s Debug shows only dest; RealityStream’s shows its name. The two crate-private methods serve the Vision adapter: socket lends the TCP socket under the record layer, so the adapter can write raw bytes once its own direct command is out while reads still come through the stream, and into_raw_parts gives the socket back with the bytes read but not yet returned (The raw switch).

A RealityServer dials dest over TCP whatever network the Destination named. Until dial_with says otherwise it uses default socket options, the system resolver and AddressFamilyStrategy::Auto. It sets the crate’s handshake deadline to the transport handshake limit, 10 s.

protocols/src/transports/camouflage.rs
pub struct Camouflage(/* the reality crate's relay, boxed */);
impl Camouflage {
pub async fn run(self, idle: Duration) -> io::Result<()>;
pub fn reason(&self) -> String; // a category, never a key or a client's identifier
}

The type exists with or without the reality feature, so Disposition reads the same either way; without the feature nothing makes one. It is opaque: run it, or drop it to close both sides. run and reason behave as the crate’s Camouflage (see Server).

protocols/src/transports/accept.rs
#[non_exhaustive]
pub enum InboundTransport {
Tcp, Tls(ServerConfig), Ws { .. }, Grpc { .. },
#[cfg(feature = "reality")]
Reality(RealityServer),
}
#[non_exhaustive]
pub enum Disposition {
Done, // every stream the socket yielded went to the sink
Camouflage(Camouflage), // not a client of ours: run the relay; the sink saw nothing
}
impl InboundTransport {
pub async fn accept<F: FnMut(Accepted)>(&self, tcp: TcpStream, sink: F) -> io::Result<Disposition>;
}
protocols/src/transports/connect.rs and stream.rs
#[non_exhaustive]
pub enum TransportKind {
Tcp, Tls(ClientConfig), Ws { .. }, Grpc { .. },
#[cfg(feature = "reality")]
Reality { config: reality::ClientConfig, vision: Option<[u8; 16]> },
}
impl TransportKind {
pub fn reality(config: reality::ClientConfig) -> Self; // vision: None
pub fn vision(self, uuid: [u8; 16]) -> Self; // no-op on other transports
}
#[non_exhaustive]
pub enum TransportStream {
Tcp(..), Tls(..), Ws(..), Grpc(..),
#[cfg(feature = "reality")]
Reality(Box<RealityStream>),
#[cfg(feature = "reality")]
Vision(Box<VisionStream>),
}

InboundTransport, Disposition, TransportKind and TransportStream are #[non_exhaustive], so a later transport is an addition and a match outside the crate keeps a wildcard arm. TCP, TLS, WebSocket and gRPC always return Disposition::Done, as accept returned before REALITY existed. TransportStream::into_vision_server turns a Reality stream into a Vision one and refuses any other transport with vless vision rides only over reality.

InboundTransport::Reality(server) handles an accepted socket in two steps:

  1. Dial dest. The transport resolves dest and connects to the first address that answers, under the dialer’s socket policy, within the transport handshake limit of 10 s (dialing dest timed out past it). dest is the cover site, not a destination: the dial does not go through routing, and nothing it carries is accounted.
  2. Run the REALITY handshake with server::accept over the client socket and the dest socket. An authenticated client’s stream goes to the sink as TransportStream::Reality, and accept returns Done. Anyone else comes back as Disposition::Camouflage(relay) without the sink seeing the socket.

The REALITY decision keeps its own deadline instead of the transport’s within wrapper: running out of time before the decision hands the socket to dest instead of closing it, so a probe sees dest’s timing.

When dest cannot be reached, accept returns the error and the connection closes: while dest is down, no client gets in. The transport logs it at warn at most once a minute per RealityServer, as reality: dest … unreachable, so no client gets in: … with dest and the error.

TransportKind::Reality { config, vision } dials like every proxy transport: TransportConnector resolves the upstream server, connects, and wraps the socket. The wrap runs the crate’s client::connect over it (see Client) and yields TransportStream::Reality, or, when vision holds the VLESS user id, a TransportStream::Vision with the client side of the Vision adapter over it.

supervisor/src/topology/spec_plan/transport.rs
#[non_exhaustive]
pub enum StreamShape { Tcp, Tls, Ws { .. }, Grpc { .. }, Reality }
pub struct RealityServerSpec {
pub private_key: Secret<[u8; 32]>,
pub server_names: Vec<String>,
pub short_ids: Vec<[u8; 8]>,
pub dest: Destination,
pub max_time_diff: Option<Duration>,
pub min_client_version: Option<[u8; 3]>,
pub max_client_version: Option<[u8; 3]>,
pub require_hybrid: bool,
}
pub struct RealityClientSpec {
pub server_name: String,
pub public_key: [u8; 32],
pub short_id: [u8; 8],
pub client_version: Option<[u8; 3]>, // None: the crate's default
}
pub struct InboundTransportSpec { pub shape: StreamShape, pub tls: Option<ServerTlsSpec>, pub reality: Option<RealityServerSpec> }
pub struct OutboundTransportSpec { pub shape: StreamShape, pub tls: Option<ClientTlsSpec>,
pub reality: Option<RealityClientSpec>, pub address_family: AddressFamilyStrategy }

StreamShape::Reality is REALITY over TCP. It is not the project’s TLS: uses_tls() is false for it, and its settings sit in the transport spec’s reality field. Every value is decoded and shape-checked when a front end lowers its config, so two specs compare with == and a bad value shows before an apply; the spec holds no strings to re-parse.

validate checks the REALITY rules on apply and refuses a spec that breaks one with ApplyError::Invalid. Fail closed: a mistyped config stops the apply instead of serving something else.

Rule Reason text
reality is present exactly when the shape is Reality, on either side a reality transport carries no reality settings, the transport carries reality settings but its shape is not reality
An inbound has at least one server name, none empty or containing * reality needs at least one server name, invalid reality server name "…"
An inbound has at least one shortId reality needs at least one shortId
dest has a host and a non-zero port reality dest needs a host, reality dest needs a non-zero port
The client-version bounds are in order reality min_client_version is above max_client_version
An outbound’s server name is not empty and has no * invalid reality server name "…"
REALITY rides only under VLESS, inbound and outbound reality is for vless only
Vision rides only over REALITY vless vision (xtls-rprx-vision) rides only over reality

A Unix listener’s transport must be plain TCP, so a REALITY inbound needs a TCP listener. The outbound rule makes a mistyped security = "reality" under Trojan, SOCKS or any other outbound fail instead of dialing REALITY as that protocol. For an inbound, what the crate checks beyond these (the characters of a server name, a key OpenSSL refuses) fails when the handler is built.

build_transport turns StreamShape::Reality into InboundTransport::Reality through build_reality:

  • RealityServer::from_bytes with the decoded key, names, shortIds and dest;
  • dial_with(Dialer::new(socket), Resolver::default(), AddressFamilyStrategy::default()): dest is dialed under the spec’s socket policy and the system resolver, not the configured DNS. It is a direct dial outside the routing plane, as Xray’s own REALITY does it, because dest is the operator’s cover site rather than proxied traffic;
  • hybrid_required, client_version_bounds and, when set, max_time_diff from the spec.

The handler is built in an apply’s prepare step, so a key the crate refuses fails the apply there and the running handler stays. A change of REALITY settings on an unchanged bind is an ordinary handler swap: swap_disruption has no REALITY case, so the change is not disruptive. A connection past its REALITY handshake is not affected; the next accepted socket meets the new settings.

On the outbound side, transport_connector builds reality::ClientConfig::from_bytes from RealityClientSpec, adds the client version when the spec has one, and makes TransportKind::reality(client), with .vision(uuid) when the VLESS outbound’s flow is Vision. Unlike dest, the upstream server is resolved through the configured DNS servers with the outbound’s address family, like any proxy upstream.

serve_tcp runs every inbound transport over an accepted socket. For REALITY:

flowchart TB
  acc["accepted socket: live and handshake permits, a session"] --> ban{"banned source?"}
  ban -- yes --> drop["dropped"]
  ban -- no --> tr["InboundTransport::Reality accept"]
  tr --> dial["dial dest"]
  dial -- fails --> close["connection closed, debug log"]
  dial --> hs["server::accept"]
  hs -- authenticated --> sink["sink: VLESS, or Vision then VLESS"]
  hs -- "Disposition::Camouflage" --> relay["drop handshake permit, keep live permit"]
  relay --> run["relay.run(RELAY_IDLE_TIMEOUT)"]
  • An authenticated stream is served like any other: the VLESS core runs over it, or, for an inbound with the Vision flow, into_vision_server wraps it first while its concrete type is still in hand.
  • A camouflaged socket is the cover site’s now. The handshake is over, so the connection’s handshake permit is dropped; the live permit stays until the relay ends. The relay runs under the socket’s session like any connection, so closing the inbound’s sessions (a shutdown, a removal) ends it. Its idle limit is RELAY_IDLE_TIMEOUT, 300 s. Its reason is logged at debug.
  • Nothing in the relay is reported to the ban guard: a probe must not see the server react, and the browsers behind its address must not pay for it.

etemenanki-app takes security = "reality" in a [stream] block. resolve_stream turns it into StreamShape::Reality only over network = "tcp" and refuses any other network with security = "reality" needs network = "tcp". The [inbound.stream.reality] and [outbound.stream.reality] tables are decoded into RealityServerSpec and RealityClientSpec with the protocols decoders; their keys are on the REALITY guide.

katana lowers a REALITY node into the same RealityServerSpec (reality_spec in src/lower/inbound.rs): the node’s one server name is both the SNI answered and the cover site dialed at its server_port, the private key is the node’s 32 bytes, and the shortId is decoded with decode_short_id; see Lowering inbounds and outbounds. The node arrives as helium-node-api’s VLESS security reality, which runs over transport tcp only. A helium answer carries the key and the shortId in the contract’s forms. A UniProxy (newV2board) answer’s tls_settings are read in src/api/newv2board.rs → reality, which decodes the key with decode_private_key and checks the shortId with decode_short_id, both in Xray’s formats. A REALITY node rides the TCP transport, so the newV2board client checks its TCP header before it reads the REALITY settings: a node whose panel names a header type other than none is refused (katana’s lowering).

  • No type of etemenanki-reality in the protocols crate’s public API; Camouflage and Disposition exist without the feature.
  • REALITY rides only under VLESS, inbound and outbound, and Vision only over REALITY.
  • dest is dialed directly, under the socket policy and the system resolver, never through routing.
  • A camouflaged connection holds a live permit and no handshake permit, and is never reported to the ban guard.
  • A REALITY settings change is a non-disruptive handler swap, and a bad value fails before the running handler is replaced.
Failure Result
A bad key, shortId or version in a front end’s config The lowering fails, naming the field; a key or shortId is never repeated
A spec breaking a rule above ApplyError::Invalid; nothing changes
A value the crate refuses when the handler is built The apply fails in prepare; the running handler stays
dest unreachable or its dial over 10 s The connection closes; a warn line at most once a minute
A client that is not ours, or a handshake failing before the flight Camouflage relay to dest
A handshake failing after the flight, a socket error The connection closes, logged at debug
Limit Value Where
dest dial 10 s TRANSPORT_HANDSHAKE_TIMEOUT (accept.rs), applied by RealityServer’s dest dial
REALITY handshake deadline 10 s RealityServer::from_config sets it to TRANSPORT_HANDSHAKE_TIMEOUT
Camouflage relay idle 300 s RELAY_IDLE_TIMEOUT (protocols/src/core/mod.rs), passed by serve_tcp
Unreachable-dest warning once per 60 s DEST_WARN_INTERVAL
File Covers
protocols/tests/pipeline/reality.rs Over loopback with a local OpenSSL dest: a TLS client that is not ours yields no stream, comes back as a relay with reason not authenticated, and through it gets dest’s certificate and answer; an unreachable dest makes accept fail; a bad setting is refused, with no shortId in the error and no key in Debug.
supervisor/tests/unit/serve.rs a_camouflaged_connection_gives_its_handshake_permit_back: two relays run with every handshake permit back and two live permits held, an IP-ban policy of one failure bans no one, and closing the sessions ends the relays and frees the live permits.
supervisor/tests/unit/validate.rs A VLESS + REALITY inbound validates; each REALITY setting fails closed; the field must match its shape; REALITY is VLESS-only on both sides; a REALITY outbound validates.
app/tests/unit/transport.rs security = "reality" over TCP is its own shape, and refused on any other network.
app/tests/unit/lower.rs A VLESS + REALITY inbound lowers to the expected spec, REALITY lowering fails closed, a REALITY outbound lowers and needs a public key.
app/tests/integration/e2e_xray_reality.rs Interop with a real Xray, below.

e2e_xray_reality.rs runs etemenanki-app against xray built from the Xray-core reference tree at v26.10.17, which uses XTLS/REALITY 83f6217. dest is a local OpenSSL TLS 1.3 server on 127.0.0.2 with a fresh RSA certificate, so no test reaches the network. Each test generates a fresh X25519 key pair. The tests skip themselves when go is missing or the build fails.

Direction Test Asserts
Xray client to our server xray_reality_client_reaches_our_server An xray VLESS + REALITY client (fingerprint chrome) drives a payload through our VLESS + REALITY inbound to a TCP echo, byte for byte
a_wrong_short_id_does_not_get_through, a_wrong_public_key_does_not_get_through The client is relayed to dest and no tunnel forms
a_plain_tls_probe_gets_dests_certificate A plain TLS client sees dest’s certificate
Our client to Xray’s server our_reality_client_reaches_an_xray_server Our SOCKS inbound and VLESS + REALITY outbound reach an xray VLESS + REALITY server, byte for byte: our Chrome hello and seal are what Xray’s server accepts
our_client_with_a_wrong_key_cannot_reach_the_xray_server Pinning an unrelated public key never forms the tunnel
Vision, both ways 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 See VLESS Vision