Skip to content

AnyTLS

Source files: 60 · checked against Etemenanki 46c12e4 · katana v6.1.0
  • Etemenanki/protocols/src/anytls/mod.rs
  • Etemenanki/protocols/src/anytls/frame.rs
  • Etemenanki/protocols/src/anytls/settings.rs
  • Etemenanki/protocols/src/anytls/padding.rs
  • Etemenanki/protocols/src/anytls/users.rs
  • Etemenanki/protocols/src/anytls/uot.rs
  • Etemenanki/protocols/src/anytls/core.rs
  • Etemenanki/protocols/src/anytls/client/mod.rs
  • Etemenanki/protocols/src/anytls/client/session.rs
  • Etemenanki/protocols/src/anytls/client/stream.rs
  • Etemenanki/protocols/src/anytls/client/datagram.rs
  • Etemenanki/protocols/src/core/mod.rs
  • Etemenanki/protocols/src/helpers/address.rs
  • Etemenanki/protocols/src/helpers/crypto.rs
  • Etemenanki/protocols/src/sniff/mod.rs
  • Etemenanki/concepts/src/core.rs
  • Etemenanki/concepts/src/link.rs
  • Etemenanki/supervisor/src/topology/spec_plan/mod.rs
  • Etemenanki/supervisor/src/topology/spec_plan/inbound.rs
  • Etemenanki/supervisor/src/topology/spec_plan/outbound.rs
  • Etemenanki/supervisor/src/build/validate.rs
  • Etemenanki/supervisor/src/build/users.rs
  • Etemenanki/supervisor/src/build/inbound.rs
  • Etemenanki/supervisor/src/build/outbound.rs
  • Etemenanki/supervisor/src/serve.rs
  • Etemenanki/supervisor/src/topology/inbound/mod.rs
  • Etemenanki/supervisor/src/topology/outbound/mod.rs
  • Etemenanki/app/src/config.rs
  • Etemenanki/app/src/lower.rs
  • Etemenanki/app/src/subscribe.rs
  • Etemenanki/subscribe/src/lib.rs
  • Etemenanki/subscribe/src/proxy_servers.rs
  • Etemenanki/ffi/src/client.rs
  • Etemenanki/ffi/src/inspect.rs
  • Etemenanki/protocols/tests/unit/anytls/frame.rs
  • Etemenanki/protocols/tests/unit/anytls/settings.rs
  • Etemenanki/protocols/tests/unit/anytls/padding.rs
  • Etemenanki/protocols/tests/unit/anytls/users.rs
  • Etemenanki/protocols/tests/unit/anytls/uot.rs
  • Etemenanki/protocols/tests/unit/anytls/core.rs
  • Etemenanki/protocols/tests/unit/anytls/client_session.rs
  • Etemenanki/protocols/tests/pipeline/anytls.rs
  • Etemenanki/protocols/tests/support/pipeline.rs
  • Etemenanki/supervisor/tests/anytls.rs
  • Etemenanki/supervisor/tests/unit/validate.rs
  • Etemenanki/app/tests/unit/lower.rs
  • Etemenanki/app/tests/unit/subscribe.rs
  • Etemenanki/app/tests/integration/e2e_singbox_anytls.rs
  • Etemenanki/app/tests/support/mod.rs
  • Etemenanki/subscribe/tests/unit/subscribe.rs
  • katana/src/api/mod.rs
  • katana/src/api/helium.rs
  • katana/src/api/newv2board.rs
  • katana/src/lower/inbound.rs
  • katana/src/manager/node.rs
  • katana/tests/unit/api/helium.rs
  • katana/tests/unit/api/newv2board.rs
  • katana/tests/unit/lower/inbound.rs
  • katana/tests/unit/lower/spec.rs
  • katana/tests/unit/manager/node.rs

AnyTLS runs inside an ordinary TLS connection and adds no cryptography of its own. Right after the TLS handshake the client authenticates once with sha256(password), and from then on both sides exchange frames that carry streams over that one connection, which the protocol calls a session. A padding scheme that the server pushes shapes the sizes of the client’s first writes. The module speaks version 2 of anytls-go’s protocol (its docs/protocol.md), as sing-box speaks it, and is tested against sing-box 1.14.3 in both directions.

This page covers protocols/src/anytls/: the wire primitives, the padding scheme, the user table, sing’s UDP-over-TCP, the sans-I/O server core AnyTlsCore and the pooled client AnyTlsConnector. It then covers how the supervisor serves an AnyTLS inbound and builds an AnyTLS outbound, and how etemenanki-app, subscribe files and katana lower their settings into a spec. The module is always compiled; there is no cargo feature for it.

The module does It leaves to others
Encode and parse the authentication, the 7-byte frame header and the key=value settings blocks. TLS itself: the TLS transport under the session (protocols/src/transports/).
Parse a padding scheme strictly, keep its raw bytes and md5, and draw record sizes from it. Deciding which scheme a server pushes: the front end’s config or panel.
Look up a client’s sha256(password) in a hash map, comparing digests in constant time. Adding or removing users: the supervisor builds a new Validator when an inbound’s users change.
Run a server session as a sans-I/O core: authentication, settings, streams keyed by id, UDP-over-TCP streams, SYNACK, heartbeats, Alerts. Accepting sockets, permits, routing, dialing and accounting: the supervisor’s listener, drive, the AppConnector and the session.
Dial sessions, pool them, give each to one stream at a time, shape the first writes by the padding scheme, and carry UDP over UDP-over-TCP. Dialing TCP and TLS: the TransportConnector the client is built over.
File Contents
protocols/src/anytls/mod.rs Re-exports AnyTlsClientConfig, AnyTlsConnector, AnyTlsDatagram, AnyTlsStream, AnyTlsCore, StreamKey, Command, PaddingScheme, SchemeError, AnyTlsUser, Validator.
protocols/src/anytls/frame.rs Command, Header, put_frame, stage_frame, password_hash, parse_auth_prefix, encode_auth, and the length constants.
protocols/src/anytls/settings.rs Settings, the key=value block of a Settings or ServerSettings frame, encode, the key names and PROTOCOL_VERSION.
protocols/src/anytls/padding.rs PaddingScheme, Item, RecordSize, SchemeError, DEFAULT_SCHEME and the bounds.
protocols/src/anytls/users.rs AnyTlsUser, UserEntry, Validator, and the private Credential key.
protocols/src/anytls/uot.rs sing’s UDP-over-TCP: the two magic domains, Version, Request, PacketHeader, their parsers and writers.
protocols/src/anytls/core.rs AnyTlsCore<T>, the server as a ProxyCoreDecode, and StreamKey.
protocols/src/anytls/client/mod.rs AnyTlsClientConfig, AnyTlsConnector, the shared pool state and the reaper.
protocols/src/anytls/client/session.rs ClientSession: one TLS connection’s frame reader and padded writer; Io, BoxIo, Got, Updates.
protocols/src/anytls/client/stream.rs AnyTlsStream: one TCP flow, owning its session while it lives.
protocols/src/anytls/client/datagram.rs AnyTlsDatagram: a UDP flow over one UDP-over-TCP stream.

All multi-byte integers are big-endian.

The client sends this once per session, before any frame:

Field Size Content
Password hash 32 (HASH_LEN) sha256(password), raw bytes
padding0 length 2 u16
padding0 that many Zero bytes, discarded by the server

AUTH_PREFIX_LEN (34) is the part up to padding0. encode_auth(hash, padding) builds the whole authentication; the client’s padding scheme decides the length (packet 0, below).

Everything after the authentication, in both directions, is frames:

Field Size Content
Command 1 One of the commands below
Stream id 4 u32; 0 for session-level commands
Data length 2 u16, so at most MAX_DATA_LEN (65535) bytes of data
Data that many

HEADER_LEN is 7. A larger write is split into several frames.

Byte Command Data Sent by Meaning
0 Waste Yes Both Padding, read and discarded
1 Syn No Client Open stream id
2 Psh Yes Both Stream data. The first data of a client’s stream is its destination, a SOCKS address.
3 Fin No Both The stream is closed; never answered with another FIN
4 Settings Yes Client The client’s settings, the first frame of every session
5 Alert Yes Server A warning text, after which both sides close
6 UpdatePaddingScheme Yes Server The server’s padding scheme, raw
7 SynAck Optional Server Version 2: stream id’s outbound connected (no data) or failed (error text)
8 HeartRequest No Both Version 2: a keep-alive the receiver answers
9 HeartResponse No Both Version 2: the answer
10 ServerSettings Yes Server Version 2: the server’s settings, after a version 2 client’s

Command::carries_data, sent_by_client and sent_by_server encode the last two columns. Every byte above 10 is unknown, and this implementation refuses it rather than skip it: Header::parse returns anytls: unknown command <n> (InvalidData).

A Settings or ServerSettings frame carries key=value lines joined by \n. Settings::get splits a line at its first =, so a value may hold =; a line without = is skipped and the last of a repeated key wins, as in every reference implementation. No order is assumed, because anytls-go writes its keys from a map. Settings::parse refuses a block longer than MAX_LEN (4096 bytes) with anytls: settings too long.

Key Constant Sent by Meaning
v KEY_VERSION Both The sender’s protocol version. Absent or not a number reads as version 1.
client KEY_CLIENT Client The client software’s name and version; may be empty.
padding-md5 KEY_PADDING_MD5 Client The lowercase hex md5 of the client’s current padding scheme.

PROTOCOL_VERSION is 2. This client sends v=2, its client value and its scheme’s md5; this server answers a version 2 client with exactly v=2.

uot.rs is sing’s UDP-over-TCP (sing/common/uot). A stream whose destination is one of two magic domains carries packets instead of a byte stream. version_of compares only the domain, ignoring ASCII case, and ignores the port, as sing-box does.

Domain Version Stream content
sp.v2.udp-over-tcp.arpa (MAGIC_V2) V2 A request, isConnect (one byte, 0 or 1) and a SOCKS address, then packets. With isConnect set, every packet goes to and comes from the request’s address and carries no address.
sp.udp-over-tcp.arpa (MAGIC_V1) V1 Packets only, each naming its peer.

A packet is [address] | length u16 | payload. Its address uses its own type bytes (ADDR: 0x00 IPv4, 0x01 IPv6, 0x02 domain, port last), not SOCKS’s, while the version 2 request’s address is a SOCKS one. A request flag other than 0 or 1 is uot: request flag is not a boolean; a SOCKS type byte in a packet fails as an unknown address type. MAX_PACKET_HEADER is AddressCodec::MAX_LEN + 2 = 261 bytes and MAX_REQUEST is 260.

A scheme is key=value lines joined by \n. stop=N pads the client’s first N packets. Packet 0 is the authentication’s padding0; from packet 1 on, a packet is one batch of frames the client queues at once (Write shaping). Line p=… lists packet p’s records, separated by commas: each min-max item is one TLS record of a size drawn from that range, the data cut to it or filled with Waste frames, and c stops the packet there if no data is left.

DEFAULT_SCHEME is anytls-go’s defaultPaddingScheme, byte for byte: 137 bytes, md5 75cff2ad89aadf5e257059ee571ebe11.

stop=8
0=30-30
1=100-400
2=400-500,c,500-1000,c,500-1000,c,500-1000,c,500-1000
3=9-9,500-1000
4=500-1000
5=500-1000
6=500-1000
7=500-1000
pub const DEFAULT_SCHEME: &[u8];
pub const MAX_SCHEME_LEN: usize = 2048;
pub const MAX_RECORD_SIZE: u32 = 1 << 20;
pub enum Item {
Range { min: u32, max: u32 },
Check,
}
pub enum RecordSize {
Bytes(usize),
Check,
}
pub struct PaddingScheme {
raw: Vec<u8>,
md5: String,
stop: u32,
records: BTreeMap<u32, Vec<Item>>,
}
impl PaddingScheme {
pub fn parse(raw: &[u8]) -> Result<Self, SchemeError>;
pub fn from_lines<S: AsRef<str>>(lines: &[S]) -> Result<Self, SchemeError>;
pub fn raw(&self) -> &[u8];
pub fn md5_hex(&self) -> &str;
pub fn stop(&self) -> u32;
pub fn pads(&self, packet: u32) -> bool;
pub fn items(&self, packet: u32) -> &[Item];
pub fn record_sizes<R: Rng + ?Sized>(&self, packet: u32, rng: &mut R) -> Vec<RecordSize>;
pub fn handshake_padding<R: Rng + ?Sized>(&self, rng: &mut R) -> u16;
}
impl Default for PaddingScheme; // DEFAULT_SCHEME

The server never pads. It holds a scheme only to push to clients whose padding-md5 differs, so the raw bytes and their md5 are what matter most: raw() is what UpdatePaddingScheme carries and md5_hex() what a client’s setting is compared with. from_lines joins lines with \n, the way sing-box’s padding_scheme and Xboard’s node settings carry a scheme; every front end goes through it, so they all join the same way. Default parses DEFAULT_SCHEME; should that ever fail, it falls back to a scheme that pads nothing, and a unit test holds the default to parsing.

The reference parsers skip what they cannot read. PaddingScheme::parse is stricter, because a scheme is configuration and a typo in it should fail the configuration rather than silently pad less. Each refusal is a SchemeError, with line numbers counted from 1:

Variant Text Refuses
Empty padding scheme is empty No bytes at all, including from_lines of an empty list
TooLong(n) padding scheme is <n> bytes, more than 2048 A scheme over MAX_SCHEME_LEN, so that pushing one is always one small frame
CarriageReturn padding scheme has a carriage return; join its lines with \n Any \r
NotKeyValue(l) padding scheme line <l> is not key=value A line without =, an empty line, a trailing \n
UnknownKey(l) padding scheme line <l>: the key is neither stop nor a packet number A key other than stop that is not a canonical decimal u32: no sign, no leading zero
DuplicateKey(l) padding scheme line <l> repeats a key A second stop or a second line for one packet
BadStop(l) padding scheme line <l>: stop is not a number A stop value that is not a canonical decimal u32
BadItem(l) padding scheme line <l>: an item is neither c nor min-max with 1 <= min <= max <= 1048576 An empty item, a lone number, min of 0, min above max, max above MAX_RECORD_SIZE
HandshakeTooLong(l) padding scheme line <l>: packet 0 is the authentication's padding, at most 65535 bytes A packet 0 size that a u16 length cannot carry
MissingStop padding scheme has no stop No stop line

MAX_RECORD_SIZE (1 MiB) is sing-anytls’s maxPaddingSize, past which that implementation drops the item. Accepted edge values: stop=0 (nothing padded), a line for a packet at or past stop (never used), and keys in any order.

record_sizes(packet, rng) draws one entry per item. A range draws min + rng.random_range(0..max - min), as anytls-go and sagernet do (min + rand.Int(max - min)): the result lies in min..max, so max is drawn only when it equals min. handshake_padding is packet 0’s first size, or 0 when packet 0 has no line or starts with c.

pub struct AnyTlsUser {
pub password: CompactString,
pub email: CompactString,
}
struct Credential([u8; HASH_LEN]);
pub struct UserEntry<T> {
pub email: CompactString,
pub data: Arc<T>,
}
pub struct Validator<T> {
users: HashMap<Credential, UserEntry<T>>,
}
impl<T> Validator<T> {
pub fn new(users: &[(AnyTlsUser, Arc<T>)]) -> Self;
pub fn get(&self, hash: &[u8; HASH_LEN]) -> Option<&UserEntry<T>>;
pub fn len(&self) -> usize;
pub fn is_empty(&self) -> bool;
}

The credential on the wire is sha256(password), so the table is a hash map keyed by that digest: a handshake costs one lookup, where Trojan’s table compares the client’s key with every user. Validator::new hashes each password once; the plaintext is not kept. Credential’s PartialEq is ct_eq from protocols/src/helpers/crypto.rs, a constant-time comparison, and which bucket a guess lands in depends on the map’s random hash key, so timing tells a client nothing about digests it did not send. A password given twice keeps its last user, as Trojan’s table does; the supervisor never builds such a table. AnyTlsUser’s and Validator’s Debug name no password: the first prints the email, the second the number of users.

T is the per-user payload carried into routing; the supervisor uses T = Principal, the tests ().

pub struct StreamKey(pub u32);
pub const MAX_STREAMS: usize = 256;
pub const MAX_UDP_PAYLOAD: usize = 8 * 1024;
pub const UDP_REASSEMBLY_BUDGET: usize = 64 * 1024;
impl<T> AnyTlsCore<T> {
pub const BUF_SIZE: usize = 16 * 1024;
pub fn new(
validator: Arc<Validator<T>>,
padding: Arc<PaddingScheme>,
sniff: bool,
source: Option<IpAddr>,
) -> Self;
pub fn is_established(&self) -> bool;
}
impl<T: Send + Sync + 'static> ProxyCoreDecode for AnyTlsCore<T> {
type Key = StreamKey;
type Target = Flow<T>;
type Error = io::Error;
type TransportAddr = ();
const STAGING_RESERVE: usize = 2 * HEADER_LEN + MAX_SCHEME_LEN + SERVER_SETTINGS.len();
const MAX_DATAGRAM: usize = MAX_UDP_PAYLOAD;
// handle, held
}

One TLS connection is one session: the client authenticates once, then opens streams with SYN, each an outbound keyed by its wire id. That is the shape of the mux.cool demultiplexer (mux.cool and XUDP), with StreamKey in place of a sub-flow key. Ids only grow within a session, so a key is never reused while its outbound is going away. The core implements ProxyCoreDecode; the event and effect vocabulary is on Server core.

stateDiagram-v2
  [*] --> Auth
  Auth --> Padding: hash matches a user, padding0 length read
  Auth --> [*]: unknown hash, PermissionDenied
  Padding --> Session: padding0 discarded, Relay phase
  Session --> Done: forbidden frame (Alert), transport EOF or idle
  Done --> [*]
  • Auth judges the hash as soon as its 32 bytes are in, before the padding0 length, so a wrong password is refused on the hash alone: anytls: invalid user (PermissionDenied). With the 34-byte prefix in, it builds the session’s NetworkUser, whose username is the entry’s email and whose password field is empty.
  • Padding discards padding0, across as many events as it takes. When the last byte is gone the core enters Phase::Relay, so is_established() turns true: the client has authenticated and sent its padding0.
  • Session parses frames. It holds the context (user, source, sniff flag), the scheme to push, whether the client’s Settings arrived and whether it was version 2, the last SYN id, the streams in a BTreeMap<u32, Stream>, the frame being read, and the UDP held buffer and its reservation.
  • Done consumes everything and does nothing; whatever was staged drains.
State Timing phase Deadline
Auth, Padding Phase::Handshake, armed by the first Event::Transport HANDSHAKE_TIMEOUT, 10 s
Session Phase::Relay RELAY_IDLE_TIMEOUT, 300 s, re-armed by every transport, outbound and datagram event

Session::feed remembers the Waste or PSH frame being read (InFrame: command, stream, bytes left) and forwards whatever part of it the event holds, so a 64 KiB frame never has to fit the 16 KiB read buffer. Only a Settings frame is read whole, and it is at most settings::MAX_LEN. Before it parses a header, feed checks that the staging room can take the largest reply one frame can cause (FRAME_REPLY_MAX, a header and a 64-byte Alert). If not, it returns what it consumed so far; the runtime offers the full reserve on every call, so the next call makes progress.

Frame What the core does
Waste Skips its data.
Settings Read whole. The first one: push the scheme if padding-md5 differs from md5_hex(), answer ServerSettings v=2 if the client’s v is at least 2, both only once the room for them is there. A later one is ignored.
Syn Refused before Settings. Its id must be above the last SYN’s, so 0 is never valid. With MAX_STREAMS streams open, it stages a FIN for the id and keeps the session; otherwise it adds Stream::Address.
Psh Feeds the stream (below). Data for a stream that is gone is consumed and dropped.
Fin Removes the stream and pushes Effect::Close if it was open. No FIN goes back.
HeartRequest Stages a HeartResponse with the same id.
HeartResponse Nothing.

A frame the protocol forbids ends the session: violate stages an Alert whose text names the fault, logs anytls: closing session: <fault> at debug, pushes Close for every open stream, then ShutdownTransport and Finish, sending no FINs. The Alert texts:

Fault Alert text
A command byte above 10 unknown command
Alert, UpdatePaddingScheme, SynAck or ServerSettings from the client command is not sent by clients
Data on Syn, Fin, HeartRequest or HeartResponse command carries data
A Settings frame over 4096 bytes settings too long
A SYN before Settings client did not send its settings
A SYN id not above the last stream id did not increase
enum Stream {
Address(Vec<u8>), // SYN seen: the destination's SOCKS address so far
Request(Vec<u8>), // UDP-over-TCP version 2: the request so far
Tcp, // open or opening
Udp(Udp), // open or opening
}

StreamCx::feed moves a stream through these as its PSH data arrives. accumulate copies bytes until addr_need (or request_need, packet_header_need) says the item is whole, asking again as the type and length bytes become known, so an address split across frames and events is assembled in the stream’s own buffer.

  • A whole SOCKS address becomes a Destination. uot::version_of decides what the stream is. V2 moves to Request. V1 opens a UDP flow toward 0.0.0.0:0, since version 1 names no destination of its own and sing-box routes it as the unspecified address. Anything else opens a TCP flow and forwards the rest of the event’s data.
  • A whole version 2 request opens a UDP flow toward the request’s destination, recording it as the connected peer when isConnect is set.
  • Tcp pushes Effect::Forward for the PSH data, by range into the event, without copying.
  • A bad address type, an unknown request flag or a packet without a peer is an error for that stream only: the core logs anytls: stream <id> refused: <error> at debug, closes the stream’s outbound if it was open, and stages a FIN.

Every flow carries the session’s NetworkUser and the client’s source address.

open_tcp sniffs only the data that came in the same event as the end of the address, and only when sniffing is on and the destination is an IP (worth_sniffing). It calls sniff::sniff on those bytes once and sets flow.sniffed. There is no Phase::Sniff and no held prefix: a stream is routed the moment its address is whole. UDP streams are never sniffed. Sniffing describes the sniffers.

feed_udp reads packets out of a UDP stream’s PSH data:

  • A packet whose payload lies inside the event is sent by range with Effect::SendTo, to the packet’s peer or the connected destination.
  • A packet split across frames is reassembled in the stream’s own buffer. Once whole, it is copied into the session’s held buffer and sent with Effect::SendToHeld. The held buffer is cleared at the next byte event, after the runtime has applied the held sends (the pin rule on Server runtime).
  • A payload above MAX_UDP_PAYLOAD (8 KiB, Trojan’s MAX_LENGTH) is skipped, not fatal.
  • Reassembly reserves the packet’s length from a session-wide budget, UDP_REASSEMBLY_BUDGET (64 KiB); a packet that would go past it is skipped. A stream that ends gives back what it reserved (Session::forget).
Event What the core does
Outbound { key, data } on a TCP stream Stages the bytes as PSH frames for that stream.
Datagram { key, from, data } on a UDP stream Stages one PSH frame holding one UDP-over-TCP packet, naming from unless the stream is connected. A peer the packet address cannot encode is dropped with a debug line.
Connected { key } A version 2 client gets an empty SYNACK.
ConnectFailed { key, .. } Logged as anytls: stream <id> connect failed: <error>. A version 2 client gets a SYNACK with the fixed text outbound connection failed, then a FIN. The text is fixed so that nothing about the server’s network reaches the client.
OutboundError { key, .. } Logged as anytls: stream <id> outbound failed: <error>; a FIN.
OutboundEof { key } A FIN, and Effect::Close for the outbound that is still registered.
SendFailed { to, .. } Logged as anytls: packet to <to> dropped: <error>; the stream goes on.
TransportEof Close for every open stream, ShutdownTransport, Finish. No FINs: closing the connection is the protocol’s session close.
Deadline In the handshake, client did not complete its request in time (TimedOut). In the relay, Timing pushes Finish and the core moves to Done.

A version 1 client gets neither ServerSettings nor any SYNACK. AnyTLS has no half-close, so the core never forwards a half-close in either direction: a client FIN closes the outbound, and an outbound EOF ends the stream.

STAGING_RESERVE is the largest reply to one frame: the scheme and ServerSettings after the client’s Settings, 2 × 7 + 2048 + 3 = 2065 bytes. A const block asserts that every other reply fits it: a UDP packet’s frame header and packet header, a SYNACK error and a FIN, an Alert. It also asserts three things about BUF_SIZE: it exceeds the reserve plus the largest UDP packet with both headers, it exceeds a whole Settings frame, and it is at most a frame’s data limit. So staging a reply never fails in a correct core; a failure is staging_full, a core bug.

pub const STREAM_OPEN_TIMEOUT: Duration = Duration::from_secs(3);
pub const DEFAULT_IDLE: Duration = Duration::from_secs(30);
pub const MIN_IDLE: Duration = Duration::from_secs(5);
pub struct AnyTlsClientConfig {
pub password: String,
pub client: String,
pub idle_session_check_interval: Duration,
pub idle_session_timeout: Duration,
pub min_idle_session: usize,
}
impl AnyTlsConnector {
pub fn new(config: AnyTlsClientConfig, transport: TransportConnector, server: Destination) -> Self;
pub fn with_dial(
config: AnyTlsClientConfig,
dial: impl Fn() -> Pin<Box<dyn Future<Output = io::Result<BoxIo>> + Send>>
+ Send + Sync + 'static,
) -> Self;
pub fn idle_sessions(&self) -> usize;
pub fn padding(&self) -> Arc<PaddingScheme>;
pub async fn open_stream(&self, dest: &Destination) -> io::Result<AnyTlsStream>;
pub async fn open_datagram(&self, dest: &Destination) -> io::Result<AnyTlsDatagram>;
}
impl<T: Send + Sync + 'static> Connector<Flow<T>> for AnyTlsConnector {
type Stream = AnyTlsStream;
type Datagram = AnyTlsDatagram;
// connect: a UDP flow opens a datagram, any other a stream
}

AnyTlsConnector is a Connector (concepts/src/link.rs) like Hysteria 2’s (Hysteria 2: protocol and client), not a codec under the client runtime. new dials each session through a TransportConnector, TLS for every AnyTLS server; with_dial takes any byte stream, which the tests use for in-memory pipes. AnyTlsClientConfig::new gives the reference defaults: 30 s checks, a 30 s timeout, no idle session kept, an empty client. with_dial raises an interval or timeout at or below MIN_IDLE to DEFAULT_IDLE, as the reference clients do, and hashes the password once.

Every reference client takes an idle session out of its pool for a new stream and puts it back when the stream closes (anytls-go’s proxy/session/client.go, sing-anytls’s client.go), so a session never carries two live streams. This client does the same. So a stream owns its session’s connection outright while it lives: no shared writer, no per-stream queues, and nothing the runtime would need to admit flows onto a shared carrier.

The clones of a connector, and every stream it opened, share one Shared: the hash, the client value, the pool settings, the current padding scheme in an ArcSwap, a sequence counter, the idle sessions in a Mutex<Vec<ClientSession>>, and whether a reaper runs.

sequenceDiagram
  participant R as Runtime
  participant P as Pool (Shared)
  participant S as ClientSession
  participant U as Server
  R->>P: open_stream(dest)
  P->>P: take_idle takes the newest and revives it
  alt no idle session
    P->>U: dial TLS, a new ClientSession with its auth queued
  end
  P->>S: open_stream queues the SYN and the destination
  S->>U: poll_drain writes auth, settings, SYN and address
  P-->>R: AnyTlsStream (owns S)
  R->>S: reads and writes
  R->>P: drop queues the FIN and releases the session

Shared::open takes the newest idle session that is still usable (take_idle), or dials one (new_session). A reused session that fails at the open is dropped, logged as anytls: idle session failed, dialing anew: <error>, and a new one is dialed. open_on queues the stream and writes the queue out (poll_drain) before it hands the stream out:

  • ClientSession::new queues the authentication, with padding0 drawn from the scheme, and keeps the Settings frame (v=2, client, padding-md5) pending.
  • open_stream takes the next id (ids start at 1) and builds a SYN and a PSH with the SOCKS address. On a new session the pending Settings, the SYN and the PSH form one packet; on a reused session the SYN and the PSH are a packet each, as sing-anytls does. A domain longer than a SOCKS address can carry fails with anytls: domain too long, and running out of ids with anytls: the session ran out of stream ids.
  • For the second and later stream of a session whose server said version 2, open_on arms a watchdog of STREAM_OPEN_TIMEOUT (sing-anytls’s streamOpenTimeout). The first stream rides a connection just made, so the reference client watches only the later ones.

open_datagram opens a stream to sp.v2.udp-over-tcp.arpa and writes a version 2 request with isConnect unset, naming the flow’s destination.

Each batch of frames the session queues at once is a packet in the scheme’s sense: the Settings, SYN and address of a stream on a new session, one write’s data, a FIN, a heartbeat answer. queue_packet (sing-anytls’s writePacketLocked) shapes packets 1 to stop - 1 into records of the scheme’s sizes, each queued as one write. Over OpenSSL, one write of at most 16 KiB is one TLS record. The authentication is packet 0 and one write of its own.

  • For each drawn size, data longer than the size is cut to it. Data that fits is padded to it with Waste frames (push_padded); data that fills all but a frame header’s worth goes out as it is.
  • A size with no data left becomes Waste frames alone, each carrying up to 65535 bytes, so a record of n bytes of padding is one Waste frame of n data bytes and its header.
  • c with no data left ends the packet; with data left it is skipped.
  • Data left after the last item is one more write.
  • A record larger than 16 KiB spans TLS records anyway, so its padding is queued as Chunk::Zeros and written from a shared static buffer of zeros instead of being allocated.
  • From the first packet at or past stop, padding_on is off for the rest of the session and every packet is one write.

poll_drain writes the queue in order and then flushes. A write that pends is retried with the same bytes, as OpenSSL requires, so nothing leaves the queue until it is written. Any write error marks the session dead.

poll_read_for(cx, id, out, updates, saw_frame) reads frames from a 16 KiB buffer until it has something for stream id. Stream data is delivered as it arrives, so a 64 KiB frame never has to fit. saw_frame is set when any frame arrived, which is what the watchdog needs.

Frame Result
Psh for id Data copied into out, Got::Data
Psh for another id, Waste Skipped
Fin for id Got::Fin
SynAck for id with text Got::Refused(text); the session stays usable
SynAck without text, Fin or SynAck for another id, HeartResponse Nothing
HeartRequest A HeartResponse queued as a packet
ServerSettings peer_v2 set when its v is at least 2
UpdatePaddingScheme Parsed and handed to Updates::padding; one that fails to parse is logged at debug and dropped
Alert anytls: alert from server: <text>, and the session is dead
Syn, Settings anytls: the server sent a client command

A control frame too large for the read buffer is skipped: an Alert still ends the session (anytls: alert from server), and a SYNACK for id reads as a refusal with no text. The end of the connection is anytls: the server closed the session (UnexpectedEof). Every error marks the session dead.

Shared implements Updates: a pushed scheme whose md5 differs from the current one is stored, logged as anytls: padding scheme <md5> from the server, and used by the connector’s next session.

  • Reads first poll the watchdog. If it fired, the session is marked dead and the read fails with anytls: the server did not answer the stream's SYN (TimedOut). Any frame clears the watchdog. Each read also drains queued writes (a heartbeat answer, the tail of a packet), because a flow that only reads would otherwise never send them.
  • Writes drain the queue, take at most MAX_PACKET_DATA (16377) bytes as one packet, and start writing it. After the server’s FIN a write fails with anytls: the server ended the stream; after a refusal, with anytls: the server could not connect: <text> (ConnectionRefused).
  • Shutdown only drains. AnyTLS has no half-close, and every reference server closes the whole stream on a FIN, so a FIN here would lose the response. The stream ends when the server ends it, or when it is dropped.
  • Drop queues a FIN unless the server already ended the stream, starts it on its way without waiting, and returns a session that is not dead to the pool. Whoever takes the session next writes the rest first.

A UDP flow over one UDP-over-TCP version 2 stream, every packet naming its peer. poll_send_to refuses a payload above MAX_PAYLOAD, MAX_PACKET_DATA - MAX_PACKET_HEADER = 16116 bytes, with anytls: datagram too large for UDP-over-TCP, so a packet and its header always fit one stream packet. DatagramLink has no flush and the runtime polls receives constantly, so poll_recv_from writes out queued sends first. It then reassembles replies across frames in a held buffer of at most one packet and the start of the next (MAX_HELD, a longest header and 65535 bytes), and delivers one packet per call, truncated to the caller’s buffer as a socket would. A reply without a peer is uot: reply without a peer, a buffer that fills without a whole packet is uot: reply larger than a packet, and the stream’s end is anytls: the server ended the UDP stream.

  • release stamps idle_since and pushes the session into the pool. The first release spawns reap on the current tokio runtime, if there is one.
  • reap holds only a Weak<Shared>, so it ends with the connector. Every check interval it upgrades the reference and calls prune.
  • prune sorts the pool newest first and keeps a session only if it is not dead, it is among the newest min_idle_session or not idle past the timeout, and revive succeeds.
  • revive reads whatever arrived while the session sat idle, without waiting, through poll_read_for with id 0, which no stream has: late frames of its last stream are dropped, heartbeats answered, pushed schemes kept. It then drains what that queued. An Alert, an error or the connection’s end makes the session unusable, logged as anytls: idle session gone: <error>.
  • take_idle takes the session with the highest sequence number and revives it, trying the next one if that fails.

A pruned session is dropped, which closes its connection.

InboundProtocolSpec::Anytls {
transport: InboundTransportSpec,
padding_scheme: Option<Vec<String>>,
}
OutboundProtocolSpec::Anytls(AnytlsOutboundSpec)
pub struct AnytlsOutboundSpec {
pub upstream: ProxyUpstream,
pub password: Secret<String>,
pub client: String,
pub idle_session_check_interval: Duration,
pub idle_session_timeout: Duration,
pub min_idle_session: usize,
}

padding_scheme holds the scheme as lines, joined with \n as sing-box and Xboard write it; None is the reference default. InboundProtocolSpec, OutboundProtocolSpec and StreamShape became #[non_exhaustive] in the same change, so adding a protocol or a transport later is not a breaking change; etemenanki-app and etemenanki-ffi have wildcard arms. spec_plan re-exports AnytlsOutboundSpec.

supervisor/src/build/validate.rs checks:

Check Error
No REALITY shape under anything but VLESS (the generic transport rule, which runs first) reality is for vless only
The inbound’s shape is Tls anytls runs over tls only; its shape must be tls
The inbound has a user set the protocol has no open mode and needs a user set
The inbound’s padding_scheme parses with PaddingScheme::from_lines The SchemeError text
The outbound’s shape is Tls anytls runs over tls only; its shape must be tls
The outbound’s password is not empty anytls password must not be empty

probe_target gives an AnyTLS outbound its upstream server, so a balancer’s health probe reaches it over TCP.

build/users.rs → credential_kind admits AnyTLS users by CredentialKind::Password, as for Trojan and Shadowsocks, so two users with one password are refused (users <a> and <b> present the same credential). build/inbound.rs → user_table builds UserTable::Anytls(anytls::Validator<Principal>) from the admitted passwords, each user’s email being its principal’s label. The live inbound holds:

StreamProtocol::Anytls {
users: ArcSwap<anytls::Validator<Principal>>,
padding: Arc<PaddingScheme>,
}

A user-set change stores a new table into users (UserTable::store_into), and a connection loads the table current at its accept. The scheme sits outside the cell: a scheme change swaps the handler, so live connections keep the scheme they started with and new ones get the new one. build/inbound.rs → padding parses the lines again when it builds the handler, or takes the default.

serve.rs → serve_connection runs each connection on the ordinary path:

StreamProtocol::Anytls { users, padding } => {
drive::<{ AnyTlsCore::<Principal>::BUF_SIZE }, _, _>(
stream,
|| AnyTlsCore::new(users.load_full(), padding.clone(), sniff, source),
connector,
handshake,
report,
)
.await
}

AnyTlsCore is in the established! list, so drive releases the handshake permit once the password and padding0 are read. The live permit and the connection’s session cover every stream of the session. A wrong password is PermissionDenied, which drive reports to the guard with Report::failed, so it counts toward the IP ban. A connection that ends in an error is logged at debug as anytls connection from <source> ended: <error>. How sessions, permits and the guard work is on Listeners and the serve loop.

Usage counts the session’s bytes inside TLS, the runtime’s transport side: the authentication, every frame and the padding, for every stream of the session, toward the session’s one user. streams_of_one_session_count_exactly_toward_its_user pins it.

build/outbound.rs builds Outbound::Anytls(AnyTlsConnector::new(…)) over the upstream’s TransportConnector, in Hysteria 2’s shape: topology/outbound/mod.rs turns a stream into OutboundStream::Proxy and a datagram into an OutboundDatagram link. lacks_ipv6 is false: the server is assumed to reach what its protocol can address. How outbounds and balancers are built is on Outbounds, UDP fan-out and balancers.

Front end Where What it does
etemenanki-app inbound app/src/config.rs → AnytlsInboundSettings, TrojanUserCfg; app/src/lower.rs → lower_inbound users through InlineUsers (password and email, as for Trojan), the transport through inbound_transport, padding_scheme passed through as lines. The settings table denies unknown keys.
etemenanki-app outbound AnytlsOutboundSettings; lower_outbound password, client (default empty), idle_session_check_interval and idle_session_timeout in seconds (default DEFAULT_IDLE), min_idle_session (default 0). The settings table denies unknown keys. A non-TLS stream fails at apply, through the supervisor’s validation.
Subscribe files subscribe/src/proxy_servers.rs → Anytls; app/src/subscribe.rs → node_outbound A node carries password, server_name and allow_insecure, and no stream: AnyTLS is TLS over TCP and nothing else, so a stream table would only let a file say something invalid. The pool’s tuning keys are the client’s and are left out. The app turns the node into an anytls outbound over Stream::Tcp { tls: Some(…) }, which is network = "tls". subscribe::VERSION is the revision a client announces; AnyTLS nodes need 0.3 or later. Protocol is #[non_exhaustive].
etemenanki-ffi ffi/src/inspect.rs, ffi/src/client.rs → refuse_servers Inspection reports an AnyTLS node as anytls over tcp with TLS. A config that serves AnyTLS is refused, like every other server inbound.
katana src/api/mod.rs → NodeType::Anytls, Node; src/api/newv2board.rs → parse_node_config; src/api/helium.rs → node_info; src/lower/inbound.rs → lower_stream_protocol, credentials; src/manager/node.rs → disruptive_part Every panel’s node is helium-node-api’s node config, here Node::Anytls with a port and an optional padding_scheme, whose lines must be non-empty, have no line break and join to at most 2048 bytes. A helium panel describes the node itself, as protocol anytls. On newV2board, node_type = "AnyTLS" (any case), and parse_node_config reads the port and the padding scheme’s lines; an absent or empty list is None, the default. katana keeps the lines as they are. The node is always TLS over TCP with the node’s certificate: lower_stream_protocol gives it the Tls shape, and credentials gives each user their UUID as the password, the XrayR convention. disruptive_part leaves the padding scheme out, so a new scheme drops no connection and reaches the sessions that start after it. The inbound tag is AnyTLS_<listen>_<port>.

katana’s lowering is described on Lowering.

Invariant Mechanism Pinned by
A wrong password is refused on the 32-byte hash, before padding0 is read, and nothing is written. State::Auth looks the hash up before it parses the prefix; PermissionDenied. a_wrong_password_is_refused_on_the_hash_alone (unit/anytls/core.rs), a_wrong_password_ends_the_connection_without_a_word (pipeline/anytls.rs)
The handshake permit covers only the authentication and padding0. is_established turns true when Padding hands over to Session. auth_split_across_events_and_a_slow_padding0 (unit/anytls/core.rs)
A frame the protocol forbids ends the session with an Alert naming the fault, and nothing else. violate stages the Alert, closes every stream and finishes. violations_end_the_session_with_an_alert, a_forbidden_frame_gets_an_alert_then_the_end
A frame larger than the read buffer is streamed, not buffered. InFrame tracks the bytes left; PSH data is forwarded by range. a_frame_larger_than_the_buffer_is_streamed
Every reply fits the staging reserve. The const assertions after the core; feed and on_settings check the room before they parse. replies_wait_for_staging_room
A session never holds more than 256 streams, and declining one keeps the session. MAX_STREAMS check on SYN, FIN for the id. the_257th_stream_is_declined_and_the_session_goes_on
A refused destination tells a version 2 client a fixed text, never the error. CONNECT_FAILED in the SYNACK. a_failed_connect_tells_a_v2_client_why_without_detail, a_refused_destination_is_reported
UDP reassembly is bounded per session. UDP_REASSEMBLY_BUDGET, released by forget. reassembly_stops_at_the_session_budget
A bad destination or packet ends only its stream. StreamCx::feed errors become a FIN for that id. a_bad_address_ends_only_its_stream, a_bad_packet_address_or_request_ends_the_stream
Only the data that came with an address is sniffed. open_tcp sniffs the rest of the event once. sniffing_reads_only_the_data_that_came_with_the_address
The user lookup is one map lookup with a constant-time compare. Credential’s PartialEq is ct_eq. finds_a_user_by_password_digest (unit/anytls/users.rs); the timing is not pinned
The password never reaches a Flow or Debug output. The flow’s password field is empty; AnyTlsUser’s Debug prints the email only. debug_output_never_shows_a_password
The scheme parser accepts exactly the documented grammar. PaddingScheme::parse. malformed_schemes_are_refused, edge_values_that_are_accepted, random_schemes_parse_back_to_what_was_written
The default scheme is anytls-go’s, byte for byte. DEFAULT_SCHEME. the_default_scheme_is_the_reference_one
The client’s authentication is one write, and the first packets are the scheme’s records. ClientSession::new, queue_packet. the_first_record_is_the_whole_authentication, packets_are_shaped_into_the_schemes_records
A session carries one stream at a time; sequential flows share it, concurrent flows get one each. The stream owns the ClientSession; release on drop. sequential_flows_reuse_one_session, flows_at_once_take_a_session_each (pipeline/anytls.rs)
A dead session is never pooled. dead checked on drop and in prune and revive. a_wrong_password_fails_the_flow, reviving_an_idle_session
A pushed scheme applies from the next session. Updates::padding stores it in Shared; new_session loads it. the_servers_scheme_is_used_from_the_next_session
A scheme change on the server leaves live sessions on their scheme. The scheme is part of the handler, not of the swappable user table. a_padding_change_leaves_live_sessions_alone (supervisor/tests/anytls.rs)
Situation Result
Unknown hash anytls: invalid user (PermissionDenied); counts toward the IP ban
Authentication or padding0 not finished in 10 s from the first byte client did not complete its request in time
Nothing sent after the TLS handshake drive fails the connection with inbound handshake timed out after 10s
Forbidden frame Alert, Close for every stream, ShutdownTransport, Finish
Bad destination, request or packet address A FIN for that stream; the session goes on
Outbound connect fails SYNACK with outbound connection failed (version 2), FIN
Client connection ends Close for every stream, no FINs
Idle 300 s Finish
Client: wrong password The server closes the connection; the flow fails with anytls: the server closed the session and the session is not pooled
Client: no frame within 3 s of a later stream’s SYN on a version 2 server The session is marked dead; the flow fails with anytls: the server did not answer the stream's SYN
Client: a reused session fails at the open Dropped; one new session is dialed for the flow
Client: Alert The flow fails with anytls: alert from server: <text>; the session is dead

Cancellation is structural on both sides. The server core owns no task, channel or timer; dropping the runtime drops the core and every stream’s outbound. On the client, dropping an AnyTlsStream sends its FIN without waiting and returns the session; dropping the connector’s last clone lets the reaper’s Weak fail to upgrade, and the reaper ends.

Constant Value Where Meaning
HASH_LEN 32 bytes frame.rs sha256(password)
HEADER_LEN 7 bytes frame.rs Frame header
MAX_DATA_LEN 65535 bytes frame.rs Data per frame
settings::MAX_LEN 4096 bytes settings.rs Settings block the server reads
MAX_SCHEME_LEN 2048 bytes padding.rs Longest padding scheme
MAX_RECORD_SIZE 1 MiB padding.rs Largest record size an item may name
MAX_STREAMS 256 core.rs Streams per session
MAX_UDP_PAYLOAD 8192 bytes core.rs UDP payload relayed either way; also MAX_DATAGRAM
UDP_REASSEMBLY_BUDGET 64 KiB core.rs UDP bytes held per session for packets split across frames
AnyTlsCore::BUF_SIZE 16 KiB core.rs Read, staging and scratch buffers per connection
STAGING_RESERVE 2065 bytes core.rs Largest reply to one frame
HANDSHAKE_TIMEOUT 10 s protocols/src/core/mod.rs Authentication and padding0
RELAY_IDLE_TIMEOUT 300 s protocols/src/core/mod.rs Session idle limit
STREAM_OPEN_TIMEOUT 3 s client/mod.rs The client’s watchdog on a later stream’s SYN
DEFAULT_IDLE 30 s client/mod.rs Default check interval and idle timeout
MIN_IDLE 5 s client/mod.rs At or below it, an interval or timeout is DEFAULT_IDLE
READ_BUF 16 KiB client/session.rs Client read buffer; larger control frames are skipped
MAX_PACKET_DATA 16377 bytes client/session.rs Stream data per client packet, one TLS record with its header
MAX_PAYLOAD 16116 bytes client/datagram.rs Largest datagram the client sends
Test file Pins
protocols/tests/unit/anytls/frame.rs Every command byte round trips and the rest are refused; which commands carry data and who sends them; the largest length; a split header waits; put_frame and stage_frame refuse more than a frame or the room; the authentication is the hash then padding0
protocols/tests/unit/anytls/settings.rs Keys in any order, values holding =, missing and empty keys, lines without = skipped and the last key winning, a non-numeric version read as absent, the 4096-byte bound, encode
protocols/tests/unit/anytls/padding.rs the_default_scheme_is_the_reference_one (137 bytes, its md5), sagernet_vectors (sing-anytls’s custom, oversized and unsendable schemes), malformed_schemes_are_refused, edge_values_that_are_accepted, drawn_sizes_follow_the_reference_range, random_schemes_parse_back_to_what_was_written, lines_are_joined_with_newlines
protocols/tests/unit/anytls/users.rs Lookup by digest, a repeated password keeping its last user, an empty table, debug_output_never_shows_a_password
protocols/tests/unit/anytls/uot.rs The magic domains ignoring case and port, the request round trip and its flag, packet headers with their own address types, connected headers, a SOCKS type byte refused
protocols/tests/unit/anytls/core.rs The authentication across events, settings and the push, SYN rules, streamed frames, FINs both ways, SYNACK for version 2 only, the 257th stream, sniffing, violations, staging room, UDP-over-TCP v2 in both modes and v1, reassembly and its budget, skipped oversized packets
protocols/tests/unit/anytls/client_session.rs the_first_record_is_the_whole_authentication, packets_are_shaped_into_the_schemes_records, records_with_no_data_left_are_all_waste, records_larger_than_a_frame_are_split_into_waste_frames, a_reused_session_sends_the_syn_and_the_address_apart, control frames while reading, data from a large frame as it comes, a refusal, an Alert and the end, reviving_an_idle_session
protocols/tests/pipeline/anytls.rs The core behind real TLS (serve_runtime_over in protocols/tests/support/pipeline.rs), driven by a minimal client built from the frame primitives: streams in sequence on one session, a 200,000-byte write, UDP-over-TCP in both request modes, a pushed custom scheme, a refused destination, a wrong password, a forbidden frame. Then AnyTlsConnector against the same server: session reuse, a session per concurrent flow, UDP, a refusal, the next session’s scheme, a wrong password; and over in-memory pipes with a paused clock, the idle timeout, min_idle_session and the watchdog
supervisor/tests/anytls.rs Through a supervisor: streams_of_one_session_count_exactly_toward_its_user, a_wrong_password_counts_toward_the_ip_ban, removing_the_user_ends_the_session_and_every_stream, a_padding_change_leaves_live_sessions_alone, and an AnyTLS outbound to an AnyTLS inbound over TCP and UDP, with the right and a wrong password
supervisor/tests/unit/validate.rs anytls_needs_tls_a_user_set_and_a_scheme_that_parses, an_anytls_outbound_needs_tls_and_a_password
app/tests/unit/lower.rs an_anytls_inbound_lowers_its_users_tls_and_padding, an_anytls_outbound_lowers_its_pool_settings
app/tests/unit/subscribe.rs, subscribe/tests/unit/subscribe.rs an_anytls_node_becomes_a_tls_outbound, an_anytls_node_carries_its_tls_keys_in_the_node (a stream key fails the parse)
app/tests/integration/e2e_singbox_anytls.rs etemenanki-app against a real sing-box 1.14.3, both ways: TCP echoes of 43 B to 300 KiB and two flows at once, UDP over UDP-over-TCP, under the default scheme and a custom one the server pushes
katana tests/unit/api/newv2board.rs, tests/unit/api/helium.rs, tests/unit/lower/inbound.rs, tests/unit/lower/spec.rs, tests/unit/manager/node.rs parse_anytls_keeps_the_padding_scheme, helium_socks_http_and_anytls_bodies, every_protocol_helium_writes_is_read, an_anytls_node_is_tls_with_its_padding_scheme, anytls_socks_and_http_users_are_their_uuid, the_new_node_kinds_pass_the_supervisors_validation (the lowered node passes the supervisor’s validation), and only_a_disruptive_change_drops_every_connection (a new padding scheme drops nothing)

sing-box 1.14.3 speaks sing-anytls v0.0.11, whose server reads the authentication from one TLS record and whose client takes only a SYNACK as the answer to a later stream’s SYN; both hold against this implementation. The e2e test builds the pinned sing-box reference tree once per run with go build ./cmd/sing-box (app/tests/support/mod.rs → SINGBOX_BIN) and skips itself with a SKIP: line when Go is missing or the build fails. Its servers listen on 127.0.0.2.

Run them from the Etemenanki workspace:

Terminal window
cargo test -p etemenanki-protocols anytls
cargo test -p etemenanki-supervisor --test anytls
cargo test -p etemenanki-app anytls

How the test suites are organised is described in Testing.