Limits, timeouts and memory
Source files: 170 · checked against Etemenanki 46c12e4 · shinku-quic v0.1.0 · katana v6.1.0
Etemenanki/concepts/src/core.rsEtemenanki/concepts/src/runtime.rsEtemenanki/concepts/src/client.rsEtemenanki/concepts/src/buffer.rsEtemenanki/concepts/src/relay.rsEtemenanki/concepts/src/wake.rsEtemenanki/protocols/src/core/mod.rsEtemenanki/protocols/src/core/harness.rsEtemenanki/protocols/src/sniff/mod.rsEtemenanki/protocols/src/sniff/collector.rsEtemenanki/protocols/src/transports/accept.rsEtemenanki/protocols/src/transports/coalesce.rsEtemenanki/protocols/src/transports/proxy_protocol.rsEtemenanki/protocols/src/transports/connect.rsEtemenanki/protocols/src/transports/keepalive.rsEtemenanki/protocols/src/transports/ws/endpoint.rsEtemenanki/protocols/src/transports/ws/stream.rsEtemenanki/protocols/src/transports/grpc/settings.rsEtemenanki/protocols/src/transports/grpc/liveness.rsEtemenanki/protocols/src/transports/grpc/framing.rsEtemenanki/protocols/src/transports/tls/config.rsEtemenanki/environment/src/dial/tcp.rsEtemenanki/environment/src/dial/socket.rsEtemenanki/protocols/src/mux/demux.rsEtemenanki/protocols/src/mux/frame.rsEtemenanki/protocols/src/helpers/address.rsEtemenanki/protocols/src/http/protocol.rsEtemenanki/protocols/src/http/core.rsEtemenanki/protocols/src/http/codec.rsEtemenanki/protocols/src/socks/server.rsEtemenanki/protocols/src/socks/protocol.rsEtemenanki/protocols/src/socks/codec.rsEtemenanki/protocols/src/socks/udp_link.rsEtemenanki/protocols/src/trojan/protocol.rsEtemenanki/protocols/src/trojan/core.rsEtemenanki/protocols/src/trojan/codec.rsEtemenanki/protocols/src/vless/protocol.rsEtemenanki/protocols/src/vless/core.rsEtemenanki/protocols/src/vless/codec.rsEtemenanki/protocols/src/vmess/core.rsEtemenanki/protocols/src/vmess/codec.rsEtemenanki/protocols/src/vmess/framing.rsEtemenanki/protocols/src/vmess/accounts.rsEtemenanki/protocols/src/ss_aead.rsEtemenanki/protocols/src/ss_legacy/aead.rsEtemenanki/protocols/src/ss_legacy/core.rsEtemenanki/protocols/src/ss_legacy/codec.rsEtemenanki/protocols/src/ss_2022/crypto.rsEtemenanki/protocols/src/ss_2022/protocol.rsEtemenanki/protocols/src/ss_2022/core.rsEtemenanki/protocols/src/ss_2022/codec.rsEtemenanki/protocols/src/ss_2022/replay.rsEtemenanki/protocols/src/hysteria/config.rsEtemenanki/protocols/src/hysteria/protocol.rsEtemenanki/protocols/src/hysteria/connection.rsEtemenanki/protocols/src/hysteria/slot.rsEtemenanki/protocols/src/hysteria/server/config.rsEtemenanki/protocols/src/hysteria/server/endpoint.rsEtemenanki/protocols/src/hysteria/server/inbound.rsEtemenanki/protocols/src/hysteria/server/datagrams.rsEtemenanki/protocols/src/hysteria/server/shim.rsEtemenanki/protocols/src/hysteria/obfs.rsEtemenanki/protocols/src/wireguard/config.rsEtemenanki/protocols/src/wireguard/device.rsEtemenanki/protocols/src/wireguard/slot.rsEtemenanki/protocols/src/tun/config.rsEtemenanki/protocols/src/tun/inbound.rsEtemenanki/protocols/src/tun/ipv6.rsEtemenanki/protocols/src/tun/udp.rsEtemenanki/protocols/src/dns/mod.rsEtemenanki/protocols/src/dns/message.rsEtemenanki/protocols/src/anytls/core.rsEtemenanki/protocols/src/anytls/settings.rsEtemenanki/protocols/src/anytls/padding.rsEtemenanki/protocols/src/anytls/client/mod.rsEtemenanki/protocols/src/anytls/client/session.rsEtemenanki/protocols/src/anytls/client/stream.rsEtemenanki/protocols/src/sss/protocol.rsEtemenanki/protocols/src/sss/server.rsEtemenanki/protocols/src/sss/core.rsEtemenanki/protocols/src/sss/codec.rsEtemenanki/protocols/src/sss/transform/mod.rsEtemenanki/protocols/src/sss/transform/stream.rsEtemenanki/protocols/src/transports/reality.rsEtemenanki/protocols/src/transports/camouflage.rsEtemenanki/protocols/src/vless/vision/mod.rsEtemenanki/protocols/src/vless/vision/filter.rsEtemenanki/protocols/src/vless/vision/framer.rsEtemenanki/reality/src/server/mod.rsEtemenanki/reality/src/server/accept.rsEtemenanki/reality/src/server/handshake.rsEtemenanki/reality/src/tls13/messages.rsEtemenanki/reality/src/camouflage.rsEtemenanki/reality/src/stream.rsEtemenanki/supervisor/src/serve.rsEtemenanki/supervisor/src/connector.rsEtemenanki/supervisor/src/guard.rsEtemenanki/supervisor/src/carrier.rsEtemenanki/supervisor/src/policy.rsEtemenanki/supervisor/src/entity/session.rsEtemenanki/supervisor/src/supervisor.rsEtemenanki/supervisor/src/ping.rsEtemenanki/supervisor/src/topology/outbound/mod.rsEtemenanki/supervisor/src/topology/outbound/proxy.rsEtemenanki/supervisor/src/topology/outbound/freedom.rsEtemenanki/supervisor/src/topology/outbound/udp_fanout.rsEtemenanki/supervisor/src/topology/balancer.rsEtemenanki/supervisor/src/track/mod.rsEtemenanki/supervisor/src/track/pace.rsEtemenanki/supervisor/src/track/sampler.rsEtemenanki/supervisor/src/build/validate.rsEtemenanki/supervisor/src/system/handoff.rsEtemenanki/supervisor/src/system/listener.rsEtemenanki/app/src/config.rsEtemenanki/app/src/lower.rsEtemenanki/app/src/main.rsEtemenanki/ffi/src/proxy.rsEtemenanki/webclient/src/router.rsEtemenanki/concepts/tests/runtime.rsEtemenanki/concepts/tests/client.rsEtemenanki/environment/tests/integration/tcp.rsEtemenanki/protocols/tests/unit/core/mod.rsEtemenanki/protocols/tests/unit/sniff/collector.rsEtemenanki/protocols/tests/unit/transports/accept.rsEtemenanki/protocols/tests/unit/transports/coalesce.rsEtemenanki/protocols/tests/unit/transports/proxy_protocol.rsEtemenanki/protocols/tests/unit/transports/grpc_framing.rsEtemenanki/protocols/tests/unit/transports/grpc_liveness.rsEtemenanki/protocols/tests/unit/transports/ws_endpoint.rsEtemenanki/protocols/tests/unit/mux/demux.rsEtemenanki/protocols/tests/unit/mux/frame.rsEtemenanki/protocols/tests/unit/http/core.rsEtemenanki/protocols/tests/unit/socks/server.rsEtemenanki/protocols/tests/pipeline/socks.rsEtemenanki/protocols/tests/unit/trojan/protocol.rsEtemenanki/protocols/tests/unit/trojan/core.rsEtemenanki/protocols/tests/unit/vmess/accounts.rsEtemenanki/protocols/tests/unit/hysteria/protocol.rsEtemenanki/protocols/tests/unit/hysteria/slot.rsEtemenanki/protocols/tests/unit/hysteria/server/datagrams.rsEtemenanki/protocols/tests/unit/wireguard/slot.rsEtemenanki/protocols/tests/unit/wireguard/device.rsEtemenanki/protocols/tests/unit/wireguard/connector.rsEtemenanki/protocols/tests/pipeline/wireguard.rsEtemenanki/protocols/tests/unit/tun/udp.rsEtemenanki/protocols/tests/unit/dns/mod.rsEtemenanki/protocols/tests/unit/anytls/core.rsEtemenanki/protocols/tests/unit/anytls/settings.rsEtemenanki/protocols/tests/unit/sss/server.rsEtemenanki/protocols/tests/unit/sss/transform/stream.rsEtemenanki/protocols/tests/unit/vless/vision/filter.rsEtemenanki/protocols/tests/unit/vless/vision/framer.rsEtemenanki/protocols/tests/unit/vless/codec.rsEtemenanki/reality/tests/unit/server/handshake.rsEtemenanki/reality/tests/unit/stream.rsEtemenanki/supervisor/tests/unit/serve.rsEtemenanki/supervisor/tests/unit/guard.rsEtemenanki/supervisor/tests/unit/session.rsEtemenanki/supervisor/tests/guard.rsEtemenanki/supervisor/tests/ping.rsEtemenanki/supervisor/tests/unit/balancer.rsEtemenanki/supervisor/tests/unit/validate.rsEtemenanki/supervisor/tests/unit/track.rsEtemenanki/app/tests/unit/lower.rsEtemenanki/app/tests/integration/e2e_udp_route.rsEtemenanki/app/tests/integration/e2e_balancer.rsshinku-quic/shinku-quic/src/hop.rskatana/src/lower/inbound.rskatana/src/api/hysteria.rskatana/tests/unit/lower/inbound.rs
This page lists every timeout, cap and buffer size in the Etemenanki kernel crates (etemenanki-reality among them), in etemenanki-supervisor, and in etemenanki-app. For each one it gives the Rust name, the value, the file that defines it and the mechanism that enforces it. The second half turns the buffer constants into a per-connection memory budget: what one proxied connection costs at most for each server core and each client codec, and what it holds before it moves any data.
Read it before you change a limit, add a protocol, or try to explain why a connection ended. The runtime, the cores, the transports, AnyTLS, sss, REALITY, Vision, Hysteria 2, WireGuard and TUN each have their own page. This page covers only the numbers and where they apply. The few limits an operator can set in the configuration file are described for operators in Limits.
Responsibilities
Section titled “Responsibilities”A limit in the code takes one of three forms:
| Form | Where it lives | Who can change it |
|---|---|---|
A const in a kernel, supervisor or app module |
Next to the code that enforces it, usually pub or pub(crate) so tests can name it |
Only a code change and a release |
| A configuration default | A DEFAULT_* constant that app/src/lower.rs uses when a key is absent |
The operator, through the keys in Configurable limits |
| A derived bound | A const fn or a const expression over other constants, such as downlink_overhead(Self::BUF_SIZE) |
Only by changing its inputs |
Two rules keep the buffer numbers consistent. Both are enforced in code:
- The byte buffers of a runtime are capped at
BUF_SIZEand grown on demand (concepts/src/buffer.rs, since concepts 2.1.0).ReadBufferandWriteBufferareVec<u8>s that never passN: the read buffer starts atINITIAL(2 KiB, orNif smaller) and doubles as reading uses it up, the staging buffer holds nothing until its first stage, and the runtime’sscratchis a boxed array (boxed_array) allocated whole at the first outbound read. Backpressure comes from a buffer full at its cap, not from a queue. - A runtime refuses to be built when its buffer cannot hold the core’s or codec’s staging reserve.
ProxyServerRuntime::buildassertsBUF_SIZE > Core::STAGING_RESERVEandProxyClientRuntime::newassertsBUF_SIZE > Codec::STAGING_RESERVE. Both panic, withBUF_SIZE must exceed the core's STAGING_RESERVE or nothing is ever readandBUF_SIZE must exceed the codec's STAGING_RESERVE or nothing can be sealed.
Key types
Section titled “Key types”Buffer sizes and reserves
Section titled “Buffer sizes and reserves”BUF_SIZE is a const generic of both runtimes. It is a cap, not an allocation size:
pub struct ProxyServerRuntime<const BUF_SIZE: usize, Core, Trans, Conn, Mode = ProxyRunsQuiet>where Core: ProxyCoreDecode, Conn: Connector<Core::Target>,pub struct ProxyClientRuntime<const BUF_SIZE: usize, Codec, Conn>where Codec: ProxyCoreEncodeHandshake, Conn: Connector<Codec::Target>,
impl<const BUF_SIZE: usize, Codec, Conn> ProxyClientRuntime<BUF_SIZE, Codec, Conn>where Codec: ProxyCoreEncodeHandshake, Codec::Error: Error + Send + Sync + 'static, Conn: Connector<Codec::Target>,{ pub fn new(codec: Codec, connector: &mut Conn, target: Codec::Target) -> Self}BUF_SIZE is not a trait item. Each server core exposes it as an inherent constant, for example pub const BUF_SIZE: usize = 16 * 1024 on impl<T> TrojanCore<T>. SssCore has two, TCP_BUF_SIZE and UDP_BUF_SIZE, one per command. The caller instantiates the runtime with it, as in drive::<{ TrojanCore::<Principal>::BUF_SIZE }, _, _> in supervisor/src/serve.rs. Client buffer sizes are chosen by the supervisor, in supervisor/src/topology/outbound/mod.rs, as the first parameter of ProxyClient<const BUF: usize, S, D, C = TransportConnector>.
The two reserve constants are trait items:
pub trait ProxyCoreDecode { type Key: Copy + Ord + Send + Sync + 'static; type Target; type Error; type TransportAddr: Clone + Send + Sync + 'static;
const STAGING_RESERVE: usize; const MAX_DATAGRAM: usize = 4096;
fn handle( &mut self, event: Event<'_, Self>, effects: &mut Effects<'_, Self>, ) -> Result<usize, Self::Error>;
fn held(&self) -> &[u8] { &[] }}
pub trait ProxyCoreEncodeHandshake { type Target; type Error;
const STAGING_RESERVE: usize;
fn start(&mut self, out: &mut Staging<'_>) -> Result<Handshake, Self::Error>; fn reply(&mut self, wire: &mut [u8], out: &mut Staging<'_>) -> Result<Reply, Self::Error>; fn finish(&mut self, out: &mut Staging<'_>) -> Result<(), Self::Error>;}STAGING_RESERVEon a server core is the most the core stages toward the transport while it handles one event, not counting the event’s own payload.STAGING_RESERVEon a client codec is the most onestart,reply,finishor seal call adds beyond the plaintext it takes: header, length prefix, tag and padding.MAX_DATAGRAMis the largest packet delivered whole on either side of a server runtime. A longer packet is truncated, the way a kernelrecvtruncates.
The runtime turns the last two into the largest datagram it reads from a datagram outbound:
impl<const BUF_SIZE: usize, Core, Trans, Conn, Mode> ProxyServerRuntime<BUF_SIZE, Core, Trans, Conn, Mode>where Core: ProxyCoreDecode, Trans: Transport<Addr = Core::TransportAddr>, Conn: Connector<Core::Target>, Conn::Datagram: DatagramLink<Addr = Destination>,{ pub const fn datagram_limit() -> usize}datagram_limit() returns min(Core::MAX_DATAGRAM, BUF_SIZE - Core::STAGING_RESERVE).
Mux carriers size their reserve with one shared helper, so the Keep headers that one outbound read splits into always fit:
pub const fn downlink_overhead(read_size: usize) -> usizeIt returns read_size.div_ceil(MAX_DATA_LEN).saturating_mul(FRAME_OVERHEAD_MAX).
Deadlines
Section titled “Deadlines”Every core keeps its one deadline in a Timing value from protocols/src/core/mod.rs:
pub const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(10);pub const RELAY_IDLE_TIMEOUT: Duration = Duration::from_secs(300);
impl Timing { pub fn new() -> Self pub fn phase(&self) -> Phase pub fn is_established(&self) -> bool pub fn touch<C: ProxyCoreDecode>(&mut self, fx: &mut Effects<'_, C>) pub fn enter<C: ProxyCoreDecode>(&mut self, phase: Phase, fx: &mut Effects<'_, C>) pub fn expired<C: ProxyCoreDecode>(&mut self, fx: &mut Effects<'_, C>) -> Expired}A runtime delivers no event while the client is silent, so the supervisor also watches the handshake from outside the runtime:
async fn drive<const BUF: usize, Core, S>( stream: S, make_core: impl FnOnce() -> Core, connector: AppConnector, handshake: Arc<OwnedSemaphorePermit>, report: Report,) -> io::Result<()>where S: AsyncRead + AsyncWrite + Unpin, Core: ProxyCoreDecode<Target = Flow, Error = io::Error, TransportAddr = ()> + Established,
pub trait Established { fn is_established(&self) -> bool;}Other limit-bearing entry points
Section titled “Other limit-bearing entry points”pub fn set_keepalive(stream: &TcpStream)
// environment/src/dial/tcp.rsimpl TcpDialer { pub fn with_connect_timeout(mut self, timeout: Duration) -> Self pub async fn connect(&self, addr: SocketAddr) -> io::Result<TcpStream> pub async fn connect_any(&self, addrs: &[SocketAddr]) -> io::Result<TcpStream>}
// environment/src/dial/socket.rsimpl SocketOptions { pub fn with_tcp_keepalive(mut self, idle: Duration) -> Self}
// protocols/src/transports/ws/endpoint.rspub(crate) fn ws_config() -> tokio_tungstenite::tungstenite::protocol::WebSocketConfigimpl WsRoute { pub fn real_ip_header(self, name: &str) -> io::Result<Self>}
// protocols/src/transports/accept.rsimpl InboundTransport { pub async fn accept<F>(&self, tcp: TcpStream, mut sink: F) -> io::Result<Disposition>}
// protocols/src/transports/camouflage.rsimpl Camouflage { pub async fn run(self, idle: Duration) -> io::Result<()>}
// protocols/src/sss/server.rspub async fn accept<S, T>(stream: S, settings: &ServerSettings, users: &Validator<T>) -> Accepted<S>
// protocols/src/transports/proxy_protocol.rspub const MAX_V2_LEN: usize = 4096;pub fn decode_v2(bytes: &[u8]) -> io::Result<Header>pub async fn read_v2(tcp: &mut TcpStream) -> io::Result<Option<SocketAddr>>
// protocols/src/vmess/accounts.rsimpl<T> AccountValidator<T> { pub fn hot_tier_due(&self) -> bool pub fn prepare_hot_tier(&self) -> PreparedHotTier<T> pub fn install_hot_tier(&self, prepared: PreparedHotTier<T>)}
// protocols/src/transports/grpc/liveness.rsimpl Liveness { pub(crate) fn new(ping_pong: Option<PingPong>, heard: ReadClock) -> Self pub(crate) fn note_progress(&mut self) pub(crate) fn note_going_away(&mut self) pub(crate) async fn watch(&mut self, idle: bool) -> Verdict}
// protocols/src/dns/mod.rsimpl Resolver { pub fn with_ttl_bounds(self, min: Duration, max: Duration) -> Self pub async fn resolve(&self, host: &str) -> io::Result<Vec<IpAddr>>}
// protocols/src/hysteria/slot.rs (ConnSlot) and protocols/src/wireguard/slot.rs (DeviceSlot)pub fn died_young(&self) -> boolpub fn note_failure(&mut self)
// supervisor/src/topology/balancer.rsimpl Balancer { pub fn spawn_probe( self: &Arc<Self>, tracker: &TaskTracker, token: CancellationToken, interval: Duration, timeout: Duration, resolver: Resolver, dialer: TcpDialer, )}
// supervisor/src/guard.rspub(crate) const SWEEP_INTERVAL: Durationimpl Guard { pub(crate) fn set_policy(&self, policies: &Policies) pub(crate) fn is_banned(&self, ip: IpAddr) -> bool pub(crate) fn sweep(&self)}
// supervisor/src/policy.rspub struct IpBanPolicy { pub max_failures: NonZeroU32, pub window: Duration, pub duration: Duration,}
// protocols/src/hysteria/config.rsimpl QuicOptions { pub const fn client() -> Self pub const fn server() -> Self}
// supervisor/src/track/pace.rsimpl Pacer { pub(crate) fn set_rate(&self, rate: Option<NonZeroU64>) pub(crate) fn charge(&self, n: usize) pub(crate) fn poll_ready(&self, cx: &mut Context<'_>, pause: &mut Option<Pin<Box<Sleep>>>) -> Poll<()>}Data flow
Section titled “Data flow”The diagram follows one TCP connection through the supervisor, as every front end runs it, and marks where each group of limits applies. Hysteria 2 and TUN inbounds own their sockets and run their own admission; their sections below cover them.
flowchart TB accept["accept loop: ACCEPT_ERROR_BACKOFF"] admit["live permit, then handshake permit"] guard["serve_socket: PROXY_HEADER_TIMEOUT, guard IP ban"] transport["InboundTransport::accept: keepalive, TRANSPORT_HANDSHAKE_TIMEOUT"] carrier["WS and gRPC: message caps, idle and PING deadlines, carrier_max_failures"] runtime["ProxyServerRuntime: up to 3 x BUF_SIZE, FrameTooLarge"] timing["core Timing: handshake, sniff, idle"] watchdog["drive: HANDSHAKE_TIMEOUT per step until established"] mux["mux.cool Demux: MAX_SESSIONS, MAX_DATA_LEN"] connector["AppConnector: device limit at the first flow"] tcp["freedom: DEFAULT_CONNECT_TIMEOUT per address"] fanout["UDP flow: FanOutLink, MAX_SUBS"] client["proxy outbound: ProxyClientRuntime, up to 2 x BUF"] dns["Resolver: QUERY_TIMEOUT, CACHE_CAPACITY"] meter["Metered: kill flag, user pacer (MIN_WAIT, MAX_WAIT)"] accept --> admit --> guard --> transport --> carrier --> runtime runtime --> timing watchdog --> runtime runtime --> mux runtime --> connector mux --> connector connector --> meter meter --> tcp connector --> fanout meter --> client tcp --> dns
Each core has exactly one deadline, and its meaning depends on the phase. Timing::touch runs at the top of every byte-carrying event, and Timing::enter moves to a new phase and arms that phase’s deadline:
stateDiagram-v2 [*] --> Handshake: runtime built, nothing armed Handshake --> Handshake: first byte event arms HANDSHAKE_TIMEOUT Handshake --> Sniff: request parsed, IP target, sniffing on Handshake --> Relay: request parsed, flow opened Sniff --> Relay: domain found, budget spent, or SNIFF_TIMEOUT Relay --> Relay: every byte event re-arms RELAY_IDLE_TIMEOUT Relay --> Closing: Expired Idle, Timing pushes Finish Relay --> [*]: both halves closed, core pushes Finish Closing --> [*]: runtime finishes Handshake --> [*]: Expired Handshake, core returns an error
A connection handed over on a handoff socket joins this path in serve_socket: handoff::receive, bounded by RECEIVE_TIMEOUT, stands where the PROXY header read stands on a TCP listener.
Two inbounds can leave the path before a runtime exists. InboundTransport::accept returns a Disposition: Done once every stream the socket yielded went to its runtime, or, from a REALITY transport only, Camouflage for a socket that is not a client of ours. The supervisor then gives back that connection’s handshake permit, keeps its live permit, and relays the socket to dest under RELAY_IDLE_TIMEOUT (see REALITY and Vision). An sss inbound reads its request header through sss’s gate, under T_h and B_pre, before it builds a runtime (see sss).
No core enters Phase::Closing itself. Only Timing::expired moves a relaying connection there, in the same step that pushes Effect::Finish. When both halves of a single-flow relay close normally, Passthrough pushes Finish while Timing is still in Phase::Relay.
The two handshake guards complement each other:
| Client behaviour | What ends it | Error text |
|---|---|---|
| Sends nothing at all | drive wraps each runtime.next() in tokio::time::timeout(HANDSHAKE_TIMEOUT, …) until the core reports is_established() |
inbound handshake timed out after 10s |
| Sends a first byte, then trickles the rest | Timing arms HANDSHAKE_TIMEOUT once, on the first byte event, and never refreshes it in Phase::Handshake, so it limits the whole request rather than the gap between bytes |
client did not complete its request in time |
The idle deadline, by contrast, is re-armed on every byte event in Relay and Closing. That makes it an idle limit, not a lifetime limit.
Limits by layer
Section titled “Limits by layer”Values are exact. Sizes are given in KiB or MiB where the source writes n * 1024.
Runtime and core
Section titled “Runtime and core”| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
BUF_SIZE (const generic) |
Per core; see Server cores | ProxyServerRuntime in concepts/src/runtime.rs |
Caps up (a ReadBuffer), staging (a WriteBuffer) and scratch. None is allocated at the cap up front. |
INITIAL |
2048 bytes | concepts/src/buffer.rs |
The size a ReadBuffer starts at (or N, if smaller). make_room moves the unparsed tail to the front and doubles the storage, up to N, each time reading uses up the free tail; compact also doubles it when moving the tail frees nothing; grow_to(len) grows it for a whole datagram before a datagram read. A WriteBuffer holds nothing until its first stage, when Staging::reserve grows it to the largest of what the stage needs, twice the current storage and INITIAL, never past N; its room() is still counted against N. |
ProxyCoreDecode::STAGING_RESERVE |
Per core | concepts/src/core.rs |
poll_transport_read reads the transport only when staging.room() is at least the reserve. A stream outbound is read only with STAGING_RESERVE + 1 bytes of room, and then into at most room - STAGING_RESERVE bytes of scratch. A datagram outbound is read only with STAGING_RESERVE + datagram_limit() of room. |
ProxyCoreDecode::MAX_DATAGRAM |
4096 by default; some cores raise it | concepts/src/core.rs |
A datagram outbound is read into scratch[..datagram_limit()]. A datagram transport is read into up.free()[..MAX_DATAGRAM.min(BUF_SIZE)], after compact and grow_to(MAX_DATAGRAM.min(BUF_SIZE)). |
RuntimeError::FrameTooLarge |
When the unparsed region fills all BUF_SIZE bytes |
concepts/src/runtime.rs, in poll_transport_read |
ReadBuffer::is_saturated() (start == 0 && end == N) while the core still wants more; below that, make_room grows the buffer. Error text: protocol frame exceeds the read buffer. |
client down saturation |
When an unopened frame fills the client’s BUF_SIZE |
concepts/src/client.rs |
The same is_saturated() check on the client runtime’s down buffer, which starts at 2 KiB and grows through ReadBuffer::make_room. Error text: upstream frame larger than the client runtime's buffer. On the sending side, the client runtime’s own make_room fails with frame larger than the client runtime's buffer when a packet plus the reserve cannot fit even in an empty staging buffer. |
WORK_BUDGET |
64 units of work | concepts/src/runtime.rs |
Future::poll of a quiet runtime calls poll_once at most 64 times, then wakes itself and returns Pending, so a busy connection cannot monopolise a worker. The progress mode (showing_progress) is a Stream that yields after every unit instead. The Hysteria 2 stream and datagram runtimes and the TUN UDP associations are awaited as quiet futures; the supervisor’s drive and the TUN inbound’s serve_stream use progress mode. |
INLINE_EFFECTS |
4 | concepts/src/core.rs |
Inline capacity of EffectList, a SmallVec. A longer effect list spills to the heap. Sized for Open + Forward + SetDeadline. |
HANDSHAKE_TIMEOUT |
10 s | protocols/src/core/mod.rs |
Timing in every core. The supervisor’s drive, the TUN inbound’s serve_stream and the SOCKS driver use the same constant for their own watchdogs. |
RELAY_IDLE_TIMEOUT |
300 s | protocols/src/core/mod.rs |
Timing::touch re-arms it on every byte event in Relay and Closing. On expiry Timing::expired pushes Effect::Finish. The SOCKS driver reuses it; see Protocol frame caps and drivers. |
SNIFF_TIMEOUT |
300 ms | protocols/src/sniff/mod.rs |
Timing::enter(Phase::Sniff, …). On expiry the core opens the flow with what it has collected. |
SNIFF_LIMIT |
4 KiB, across frames | protocols/src/sniff/mod.rs |
Collector::push returns Verdict::Exhausted once 4 KiB are held; Collector::remaining never offers more. A Collector owns no memory until its first non-empty push, which reserves the whole 4 KiB at once; SniffPrefix::clear frees it once the held forward is applied. |
MAX_DOMAIN_LEN |
253 | protocols/src/sniff/mod.rs |
plausible_domain rejects a longer sniffed host. |
HARNESS_STAGING |
64 KiB | protocols/src/core/harness.rs |
The staging room CoreHarness offers a core per call. The harness drives a core by hand for tests and does no I/O; no production path uses it. |
BidirectionalConnection BUF_SIZE |
8192 per direction by default | concepts/src/relay.rs |
One Box<[u8; BUF_SIZE]> per direction. The SOCKS driver instantiates it with RELAY_BUF. |
Each opened outbound also costs one Arc<KeyWaker> (concepts/src/wake.rs), the connector’s future while it dials, and one BTreeMap entry. The runtime itself puts no cap on the number of outbounds. A core that multiplexes bounds them; see Mux.
Transports and dialing
Section titled “Transports and dialing”| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
TRANSPORT_HANDSHAKE_TIMEOUT |
10 s | protocols/src/transports/accept.rs |
within() wraps one step of InboundTransport::accept: the TLS accept for tls, or, for ws and grpc, the optional TLS accept and the WebSocket upgrade or HTTP/2 handshake together, under one 10 s budget. Error text: tls handshake timed out, websocket handshake timed out, grpc handshake timed out; a WebSocket or gRPC transport over TLS reports its own name even when TLS was the slow part. serve_socket logs the failure at debug as inbound transport failed: <error>. Plain TCP and Unix sockets have no transport step. A REALITY transport is not wrapped in within(): it bounds its dial to dest with the same 10 s (dialing dest timed out) and gives the REALITY handshake the same value as its own deadline (see REALITY and Vision). |
TCP_KEEPALIVE_IDLE |
120 s | protocols/src/transports/keepalive.rs |
set_keepalive, applied to every TCP socket InboundTransport::accept receives and to the socket a REALITY transport dials to dest. Best effort: when the platform rejects the option, it logs could not enable TCP keepalive at debug and keeps the connection. |
TCP_KEEPALIVE_INTERVAL |
30 s | same | same |
TCP_KEEPALIVE_RETRIES |
3 | same | same |
DEFAULT_CONNECT_TIMEOUT |
10 s per address | environment/src/dial/tcp.rs |
TcpDialer::connect wraps socket.connect in tokio::time::timeout: connect to <addr> timed out. connect_any tries addresses one after another (not Happy Eyeballs), so the worst case is 10 s times the number of addresses; when all fail it returns failed to connect to any address (…) with every per-address error. Used by the freedom outbound and by TransportConnector. with_connect_timeout overrides the value; nothing in the kernel, the supervisor or the app calls it. |
SocketOptions::tcp_keepalive |
None by default |
environment/src/dial/socket.rs |
Part of the host socket policy a front end installs with SupervisorBuilder::socket_options. When set with with_tcp_keepalive, TcpDialer::socket sets the keepalive idle time on the sockets it opens. See Dialers. |
MAX_EARLY_DATA |
16 KiB | protocols/src/transports/ws/endpoint.rs |
Inbound: decode_early_data_header refuses a larger decoded Sec-WebSocket-Protocol payload, and the upgrade is answered 413 Payload Too Large. Outbound: an ?ed=N limit is clamped to N.min(MAX_EARLY_DATA). |
MAX_WS_MESSAGE_LEN |
1 MiB | protocols/src/transports/ws/endpoint.rs |
ws_config() sets both max_message_size and max_frame_size, replacing tungstenite’s defaults of 64 MiB and 16 MiB, on every session, accepted or dialed. |
MAX_REAL_IP_ADDRESSES |
32 | protocols/src/transports/ws/endpoint.rs |
On a route built with WsRoute::real_ip_header (an inbound whose spec sets real_ip), the upgrade callback reads the named header after the path and Host check: every line in order, split on ,, each entry a bare IP address. A 33rd address, like any entry that is not an address, makes the header RealIpHeader::Malformed, and the connection keeps the client it had. |
WS_KEEPALIVE_INTERVAL |
60 s | protocols/src/transports/ws/stream.rs |
The read side of WsStream queues a Ping when this timer fires. touch() resets it on every received frame and every write. |
WS_IDLE_TIMEOUT |
300 s | protocols/src/transports/ws/stream.rs |
The read side reports end of stream when 300 s pass with no received frame and no write. Any frame counts, Pong included, which is what makes the Ping a liveness probe. |
H2_INITIAL_STREAM_WINDOW_SIZE |
4 MiB | protocols/src/transports/grpc/settings.rs |
configured_server_builder and configured_client_builder (HTTP/2 flow control). |
H2_INITIAL_CONNECTION_WINDOW_SIZE |
16 MiB | same | same |
H2_MAX_FRAME_SIZE |
256 KiB | same | same |
MAX_GRPC_MESSAGE_LEN |
1 MiB | same | The Hunk decoder in grpc/framing.rs checks the declared length before it buffers the body: grpc message length exceeds the accepted maximum. |
H2_IDLE_TIMEOUT |
30 s | same | Liveness judges a served connection that carries no streams for 30 s idle, and serve_h2 tells it to go away with a GOAWAY (graceful_shutdown); note_going_away then gives it H2_KEEPALIVE_TIMEOUT to finish closing. serve_h2 calls note_progress on every stream it hands to the sink and on every stream-count change while streams are open, which restarts the deadline; a request refused for its path does not. |
H2_KEEPALIVE_INTERVAL |
60 s | same | Liveness sends a PING every 60 s on a served connection. |
H2_KEEPALIVE_TIMEOUT |
20 s | same | The peer is judged dead, and the served connection dropped, once nothing at all has been heard from it for 20 s since the later of the PING and its last word. Any byte counts, not only the PONG: Heard stamps a ReadClock on every read of the connection’s I/O. |
H2_PONG_TIMEOUT |
300 s | same | A PONG still owed 300 s after its PING also ends the connection, even while the peer is heard from, so a peer that keeps sending but never reads does not hold it. The same length as RELAY_IDLE_TIMEOUT. |
HELD_MAX |
16 KiB | protocols/src/transports/coalesce.rs |
Coalesced, under every served HTTP/2 connection and every dialed gRPC connection, holds h2’s writes until h2 flushes, and never more than one TLS record’s plaintext. A write that finds the buffer full sends it first, so a stalled socket stalls the writer instead of growing the buffer. The first write after a flush allocates the 16 KiB, and the flush frees them. |
Admission
Section titled “Admission”Admission limits decide whether a new connection, stream or flow is taken at all. Apart from the QUIC stream credit (QuicOptions::DEFAULT_MAX_INCOMING_STREAMS), none of them queue: each uses try_acquire_owned, try_send or a check under a lock, and a refusal is immediate.
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
MAX_LIVE_CONNECTIONS_PER_INBOUND |
4,194,304 | supervisor/src/serve.rs |
A Semaphore per stream inbound, for every front end, which its TCP listener and its handoff socket share (InboundCaps): a listener an apply adds beside a kept one joins the kept one’s pool (caps_for in supervisor/src/supervisor.rs). run_stream_inbound takes one permit per accepted socket, and serve_connection holds it (as _live) until the socket and every stream it yields are done. At the limit the socket is dropped and the loop logs dropping inbound connection; live connection limit reached at debug. Its comment calls it a guardrail rather than a quota: far above normal traffic, with room left under the process file-descriptor limit for each session’s outbound socket. |
MAX_HANDSHAKES_PER_INBOUND |
204,800 | supervisor/src/serve.rs |
A second Semaphore per stream inbound, shared the same way and taken after the live permit. drive drops its handshake permit (handshake.take()) once the core reports is_established(). Two connections give it back without a runtime: a REALITY socket handed to dest, before its relay runs, and an sss stream refused before authentication when it falls back; an sss stream that drains keeps it, as one still waiting for its header would. At the limit: dropping inbound connection; handshake limit reached at debug. |
ACCEPT_ERROR_BACKOFF |
100 ms | supervisor/src/serve.rs |
After an accept error other than ConnectionAborted or Interrupted (for example EMFILE), should_backoff_accept_error is true, the loop logs accept error, backing off 100ms at warn, and sleeps 100 ms or until cancelled. |
PROXY_HEADER_TIMEOUT |
10 s | supervisor/src/serve.rs |
On an inbound whose spec sets proxy_protocol, a TCP listener reads a PROXY protocol v2 header when one is sent and takes the client address from it; the read is bounded by this timeout. A connection without a header keeps its socket peer. |
RECEIVE_TIMEOUT |
5 s | supervisor/src/system/handoff.rs |
A relay’s control connection on a handoff socket has 5 s from its accept to deliver its one message: the handed-over socket and its PROXY protocol v2 header, with no bytes after the header (a message with any is refused, 0x01). One silent past it is closed unanswered, logged as handoff: no message within 5s at debug; one that hangs up without sending is not answered either. |
MAX_V2_LEN |
4096 bytes | protocols/src/transports/proxy_protocol.rs |
The longest PROXY protocol v2 header decode_v2 takes, from the signature to the end of its address block, TLVs included. read_v2 on a TCP listener refuses a longer one from its fixed part, before reading the rest: PROXY protocol v2: the header is too long. A handoff socket reads its message into MAX_V2_LEN + 1 bytes, so a byte after a header of the full length is read and refused as trailing data. |
MAX_SOCKET_PATH |
107 bytes | supervisor/src/build/validate.rs |
The longest handoff socket path, as sun_path holds 108 bytes with its terminating NUL. Validation refuses a longer one: the handoff socket <path> is longer than 107 bytes. A Unix or handoff socket’s staging name, a dot and random letters beside the path, never makes the staged path longer than this either. katana holds its sockets to the same bound in src/lower/inbound.rs (its own MAX_SOCKET_PATH, 107): handoff_dir, a / and the node’s longest socket name, its name at port 65535 (65535.sock on every address, <listen_ip>-65535.sock on one), must fit, or handoff_dir is refused with handoff_dir "<dir>" is too long: with "<name>" in it, a socket's path would pass the 107 bytes a Unix socket's path may have. |
STAGING_ATTEMPTS |
16 | supervisor/src/system/listener.rs |
How many staging names a Unix or handoff bind draws. A name is passed over only when a file already has it (AddrInUse); after 16 the bind fails with no free name to stage <path> under. |
| Handoff socket backlog | libc::SOMAXCONN |
supervisor/src/system/listener.rs → bind_handoff |
The listen queue of a handoff socket. Every handed-over connection arrives on a control connection of its own, so a burst of clients at the relay is a burst of connects. The socket file is given its mode (katana’s is 0o660) and group after it is bound and before it listens; a missing directory is created with mode 0o750, in the same group. |
Policies::ip_ban (IpBanPolicy) |
None by default: nobody is banned |
supervisor/src/policy.rs, supervisor/src/guard.rs |
A refused credential (a PermissionDenied core error before the core is established) counts against the client’s IP: an IPv4 client by its address, an IPv6 client by its /64, and an IPv4-mapped IPv6 address as its IPv4 address (BanKey). Once max_failures have counted within window of the first, the IP is banned for duration, and serve_socket drops its new TCP connections before their transport handshake; its open connections run on. A successful authentication clears the count, but a ban runs to its end. Turning bans off lifts every ban. A wrong AnyTLS password counts like any refused credential. A REALITY socket handed to dest and an sss stream refused before authentication are never reported to the guard. |
SWEEP_INTERVAL |
30 s | supervisor/src/guard.rs |
guard::sweep_until drops the records (one per IPv4 address or IPv6 /64) neither banned nor within their window. |
Policies::carrier_max_failures |
None by default: never |
supervisor/src/policy.rs, supervisor/src/guard.rs, supervisor/src/carrier.rs |
A gRPC connection is closed once this many of its streams in a row have failed to authenticate (the count is in the connection’s Carrier). A success resets the count. |
UserSpec::device_limit |
None by default: any number of IPs |
supervisor/src/entity/session.rs |
When a session binds at its first flow, it is refused (PermissionDenied, its token cancelled) if the user’s bound sessions already come from as many distinct IPs as the limit and its IP is not one of them. An IP frees its place when its last session ends; a lowered limit closes no session. |
DEFAULT_MAX_CONNECTIONS |
262,144 | protocols/src/hysteria/server/config.rs |
Hysteria 2 listener: one place per QUIC connection, taken before the handshake with a compare-and-swap on a shared count (Admitted) and held for the connection’s life. At the limit, or while the listener drains, incoming.refuse() tells the client at once. Config key max_connections. |
DEFAULT_MAX_CIRCUITS |
4,194,304 | protocols/src/hysteria/server/config.rs |
ServerConfig::circuit_permits, shared by every connection on the listener. A proxy stream takes a permit before its runtime is spawned and moves it into the task. A UDP session takes one when it opens and keeps it in its Session. At the limit a stream is reset with H3_REQUEST_REJECTED, and a datagram is dropped. Config key max_circuits. |
QuicOptions::DEFAULT_MAX_INCOMING_STREAMS |
65,536 | protocols/src/hysteria/config.rs |
max_concurrent_bidi_streams in the QUIC transport config of every connection a Hysteria 2 server accepts (QuicOptions::server()). Configurable as quic.max_incoming_streams, at least 1. QUIC withholds stream credit, so the client’s open_bi waits rather than being refused. |
MAX_CLASSIFYING_STREAMS |
64 | protocols/src/hysteria/server/inbound.rs |
Capacity of the two mpsc channels between the HTTP/3 layer and the stream classifier of one connection. When the channel toward the classifier is full, Hy2H3Conn::poll_accept_bidi (protocols/src/hysteria/server/shim.rs) resets the new stream with H3_EXCESSIVE_LOAD and logs hysteria2: resetting a stream; too many are awaiting classification at debug. |
DEFAULT_MAX_FLOWS |
65,536 | protocols/src/tun/config.rs |
TUN: one Semaphore per runtime on the device. Each TCP stream and each UDP association (one per client source address) takes a permit. At the limit the flow is dropped: tun: dropping a flow; the flow limit is reached at debug. Config key max_flows. |
FLOW_QUEUE |
16 | protocols/src/tun/udp.rs |
Capacity of the channel that hands new flows of one client source to its association. When it is full, try_send fails and the new flow is dropped; the client retransmits. |
The mux.cool demultiplexer, Demux, is shared by the Trojan, VLESS and VMess cores.
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
MAX_SESSIONS |
256 sub-flows per carrier | protocols/src/mux/demux.rs |
Demux answers a New frame with End and discards its payload when 256 sessions are open or the id is already live. The carrier stays up. |
MAX_META_LEN |
512 | protocols/src/mux/frame.rs |
The frame parsers reject a longer metadata block: mux: metadata length … exceeds 512. |
MAX_DATA_LEN |
8 KiB | protocols/src/mux/frame.rs |
The frame parsers reject a longer data block: mux: data length … exceeds 8192. On the downlink, Demux::on_outbound splits a read into Keep frames of at most 8 KiB, and Demux::on_datagram drops a packet longer than 8 KiB. A VLESS client under Vision drops a longer packet too instead of framing it as XUDP (VlessDatagram::seal_to). |
FRAME_OVERHEAD_MAX |
268 | protocols/src/mux/frame.rs |
2 + MIN_META_LEN + 1 + AddressCodec::MAX_LEN + 2, with MIN_META_LEN = 4: the largest header of a frame this crate emits, a Keep or the XUDP client’s New. |
downlink_overhead(16 * 1024) |
536 | protocols/src/mux/demux.rs |
Two Keep headers. Part of the staging reserve of TrojanCore and VlessCore. |
AnyTLS
Section titled “AnyTLS”An AnyTLS server session is one TLS connection whose streams are the outbounds of one runtime, the shape of the mux.cool demultiplexer. The client is not a client runtime: each flow owns one pooled session while it lives. See AnyTLS.
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
MAX_STREAMS |
256 streams per session | protocols/src/anytls/core.rs |
A SYN while 256 streams are open is answered with a FIN, which declines that stream and keeps the session. |
settings::MAX_LEN |
4 KiB | protocols/src/anytls/settings.rs |
The one frame the core reads whole. A longer Settings frame is a protocol violation: the core stages an Alert (settings too long), closes every stream and ends the session. Every other frame’s data is streamed, so a 64 KiB frame never has to fit the 16 KiB buffer. |
MAX_UDP_PAYLOAD |
8 KiB | protocols/src/anytls/core.rs |
The largest UDP-over-TCP packet relayed, and AnyTlsCore::MAX_DATAGRAM. A larger packet from the client is skipped and its stream goes on. |
UDP_REASSEMBLY_BUDGET |
64 KiB per session | same | What a session holds, in the core’s held buffer, of UDP packets split across frames. A packet that would pass it is skipped. |
MAX_SCHEME_LEN |
2 KiB | protocols/src/anytls/padding.rs |
The longest padding scheme. PaddingScheme::parse refuses a longer one (padding scheme is <n> bytes, more than 2048), and the supervisor’s validation parses every inbound’s scheme. It also sizes the core’s STAGING_RESERVE, because pushing the scheme to a client is one frame. |
MAX_RECORD_SIZE |
1 MiB | same | The largest record size a scheme item may name. |
STREAM_OPEN_TIMEOUT |
3 s | protocols/src/anytls/client/mod.rs |
Client: on a session whose server speaks version 2, every stream after the session’s first is watched. When no frame arrives within 3 s of its SYN, the stream fails with anytls: the server did not answer the stream's SYN and the session is not used again. |
DEFAULT_IDLE |
30 s | same | Client: the default idle_session_check_interval and idle_session_timeout. A reaper closes the sessions idle past the timeout at every check, keeping the newest min_idle_session. |
MIN_IDLE |
5 s | same | Client: an interval or timeout at or below 5 s is raised to DEFAULT_IDLE. |
MAX_PACKET_DATA |
16 KiB less the 7-byte frame header | protocols/src/anytls/client/session.rs |
Client: the most stream data one packet carries. A write takes at most this much, and waits until the session’s previous packet is out before it takes any. |
sss’s own limits are on sss and sss transforms. These are the ones that bound what a server holds before and after authentication, and what a stream buffers:
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
HEADER_MAX |
276 bytes | protocols/src/sss/protocol.rs |
The longest request header, and the STAGING_RESERVE of both client codecs. |
B_pre (Chain::prefix_budget) |
X_C(276) of the up chain, at most MAX_PREFIX (1 MiB) |
protocols/src/sss/transform/mod.rs |
The most raw transport bytes a server reads before authentication. A stream that brings no complete header within it is refused. Chain::new refuses a chain of more than MAX_CHAIN (8) transforms, or one whose budget would pass 1 MiB. |
DEFAULT_HEADER_TIMEOUT (T_h) |
10 s | protocols/src/sss/server.rs |
Counted from the accept. A stream without a complete header by then is refused; a refused stream that drains is closed at the same deadline, and a fallback’s connect must finish within it. Config key header_timeout, above zero. |
MAX_FLUSH_DELAY |
10 ms | protocols/src/sss/transform/stream.rs |
The longest t_c (flush_delay), which holds each flush after the first. Validation refuses a longer one: sss flush_delay must be at most 10ms. |
MAX_DATAGRAM |
65535 | protocols/src/sss/protocol.rs |
The default and largest U (udp_max_datagram), the most data one datagram record carries. Validation refuses 0: sss udp_max_datagram must be at least 1. A record above U fails its stream; a reply above it is dropped. |
CALL_SIZE |
16 KiB | protocols/src/sss/transform/stream.rs |
The most input one call takes before it is encoded without a flush. |
DECODED_LIMIT |
16 KiB | same | Decoding stops once this much decoded input waits for the reader, so a run of small zstd frames never decompresses past one buffer. |
OUTPUT_HIGH |
64 KiB | same | Encoded bytes past this wait for the transport before another write is taken. |
TCP_BUF_SIZE, UDP_BUF_SIZE |
16 KiB, 66 KiB | protocols/src/sss/core.rs |
The runtime an admitted stream gets, by its command; see Server cores. |
| Fallback relay | 8 KiB per direction | protocols/src/sss/server.rs |
A stream handed to the fallback is relayed through a BidirectionalConnection of 8 KiB buffers. Every RELAY_IDLE_TIMEOUT the relayed byte counts are compared with the previous check, and the relay ends with sss: fallback idle when nothing moved. |
REALITY and Vision
Section titled “REALITY and Vision”A REALITY inbound dials dest for every connection, passes the client’s ClientHello on to it as it arrives, and then either authenticates the client or hands both sockets to the camouflage relay. The handshake’s limits live in etemenanki-reality; see REALITY overview and REALITY transport. Vision is on VLESS Vision.
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
TRANSPORT_HANDSHAKE_TIMEOUT |
10 s | protocols/src/transports/accept.rs, used in protocols/src/transports/reality.rs |
RealityServer dials dest within it (dialing dest timed out) and sets it as the handshake’s deadline with ServerConfig::with_handshake_timeout (the crate’s own default, DEFAULT_HANDSHAKE_TIMEOUT in reality/src/server/mod.rs, is also 10 s). Until our flight is sent, the deadline hands the socket to dest, so a probe sees dest’s timing; after that, it ends the connection. |
DEST_WARN_INTERVAL |
60 s | protocols/src/transports/reality.rs |
A dest that cannot be dialed fails every connection; the failure is logged at warn (reality: dest … unreachable, so no client gets in: …) at most once a minute. |
MAX_CLIENT_HELLO |
64 KiB | reality/src/tls13/messages.rs |
The longest ClientHello body accepted, Go’s maxHandshake. A longer one is not a client of ours, and the socket goes to dest. |
MAX_HELLO_BYTES |
128 KiB | reality/src/server/accept.rs |
The most raw ClientHello bytes kept, so a 64 KiB hello in many small records still fits. Past it, the socket goes to dest. |
DEST_CAPTURE_LIMIT |
17 KiB | reality/src/server/handshake.rs |
The most of dest’s answer kept while it is captured, XTLS’s limit. An answer, or a record in it, longer than that sends the socket to dest. |
MAX_USELESS_RECORDS |
32 | same | The records with nothing in them (ChangeCipherSpec, empty fragments) a client may send before its Finished; an established RealityStream takes as many empty records in a row. One more ends the connection. |
RELAY_BUFFER |
16 KiB per direction | reality/src/camouflage.rs |
The camouflage relay’s two fixed buffers. The relay passes each end of file on as a half-close; the supervisor runs it with RELAY_IDLE_TIMEOUT (300 s) as its idle limit, after which it ends with TimedOut if no byte moved either way. |
PACKETS_TO_FILTER |
8 buffers | protocols/src/vless/vision/filter.rs |
Vision’s inner-TLS filter inspects at most the first 8 buffers, both directions together, for an inner TLS 1.3 ServerHello. With no verdict by then it stops, and no raw switch happens. Traffic not seen as TLS 1.2 or later ends its framing with COMMAND_END once at most one buffer of the budget is left (pad_body in vision/framer.rs). |
MAX_BUFFER |
8192 | protocols/src/vless/vision/mod.rs |
The most one Vision frame carries, Xray’s buf.Size. The write framer cuts a write into buffers of this size, and splits a buffer of MAX_CONTENT (8171) bytes or more in two (reshape in vision/framer.rs). |
UDP fan-out
Section titled “UDP fan-out”The supervisor does not dial a UDP flow as a unit. AppConnector::connect returns a FanOutLink, which routes each datagram by its own destination and keeps one sub-link per outbound version it routes to.
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
MAX_SUBS |
64 sub-links per association | supervisor/src/topology/outbound/udp_fanout.rs |
FanOutLink::poll_opening pushes the new sub-link and, when the table then holds more than 64, removes the front entry. A send moves its sub-link to the back, so the evicted one is the least recently sent to. Dropping it ends that sub-link’s tracked flow and closes its link. |
A sub-link that fails to open is logged at debug (udp fan-out: opening <tag>@v<version> failed: <error>), and the packet that triggered it is not delivered.
Hysteria 2
Section titled “Hysteria 2”Both ends take their QUIC transport parameters from QuicOptions (protocols/src/hysteria/config.rs), upstream’s quic block. QuicOptions::client() and QuicOptions::server() hold upstream’s defaults, and quic::transport_config turns them into each connection’s quinn TransportConfig. quinn grants a peer its whole receive window up front, so the windows are the ceiling, upstream’s max_* figures. Every value is configurable, within the ranges supervisor/src/build/validate.rs → hy2_quic enforces:
| Constant | Value | Configurable as | Range accepted |
|---|---|---|---|
QuicOptions::DEFAULT_STREAM_RECEIVE_WINDOW |
8 MiB | quic.max_stream_receive_window (init_stream_receive_window alone stands in for it) |
at least MIN_RECEIVE_WINDOW (16,384 bytes) |
QuicOptions::DEFAULT_CONN_RECEIVE_WINDOW |
20 MiB (DEFAULT_STREAM_RECEIVE_WINDOW / 2 * 5) |
quic.max_conn_receive_window (or init_conn_receive_window) |
at least 16,384 bytes |
QuicOptions::DEFAULT_MAX_IDLE_TIMEOUT |
30 s | quic.max_idle_timeout |
whole seconds, 4 to 120 (HY2_IDLE_TIMEOUT) |
QuicOptions::DEFAULT_KEEP_ALIVE_PERIOD |
10 s, client only; a server sends no keep-alive | quic.keep_alive_period (client only) |
whole seconds, 2 to 60 (HY2_KEEP_ALIVE) |
QuicOptions::DEFAULT_MAX_INCOMING_STREAMS |
65,536, server only; a client leaves quinn’s default | quic.max_incoming_streams (server only) |
at least 1 |
Server side:
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
CLASSIFY_TIMEOUT |
10 s | protocols/src/hysteria/server/inbound.rs |
A stream must reveal its frame type within 10 s, or it is reset with H3_REQUEST_CANCELLED. |
DRAIN_TIMEOUT |
3 s | same | Hy2Inbound::shutdown closes the endpoint with CLOSE_CODE, then waits up to 3 s for endpoint.wait_idle(). |
RELEASE_TIMEOUT, RELEASE_POLL |
3 s, 20 ms | same | shutdown then tries to bind the port every 20 ms, for up to 3 s, so the port is free when it returns. A timeout logs hysteria2: <addr> did not come free within 3s at warn. |
CLOSE_CODE |
0x100 |
same | QUIC application error code sent to every client on teardown. |
DISCONNECT_CODE |
0x107 |
same | QUIC application error code when the owner closes one connection (its session’s token is cancelled) or the obfuscation changes. |
MAX_SESSIONS |
256 UDP sessions per connection | protocols/src/hysteria/server/datagrams.rs |
While 256 sessions are open, Hy2UdpCore drops every packet that names a new session id (logged at trace). |
SWEEP_INTERVAL |
1 s | same | The core’s deadline. Each expiry advances its tick clock and closes sessions that have been quiet for udp_idle_timeout whole seconds (at least 1). |
udp_idle_timeout |
60 s default, 2 to 600 s accepted | default in app/src/lower.rs, range HY2_UDP_IDLE in supervisor/src/build/validate.rs |
Validation refuses values outside the range; etemenanki-app refuses the key when udp is off. katana holds [node.hysteria] udp_idle_timeout to the same range before the spec is validated, with the same message and the same 60 s default (src/api/hysteria.rs → udp), and a helium panel’s node config holds its udp.idle_timeout_secs to that range too. |
Protocol and client side:
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
MAX_ADDRESS_LENGTH |
2048 | protocols/src/hysteria/protocol.rs |
Encoding and parsing of TCPRequest and UDPMessage addresses. |
MAX_MESSAGE_LENGTH |
2048 | same | The longest TCPResponse message that is encoded or parsed. |
MAX_MESSAGE_KEPT |
128 | same | How many characters of a server-supplied message survive, sanitised, into an io::Error on the client. |
MAX_PADDING_LENGTH |
4096 | same | The longest padding accepted on any frame. |
MAX_UDP_SIZE |
4096 | same | The Defragger refuses to reassemble beyond 4096 bytes. Also Hy2UdpCore::MAX_DATAGRAM. |
MAX_DATAGRAM_FRAME_SIZE |
1200 | same | The server’s datagram task passes it to Hy2UdpCore as the peer’s datagram size when the connection reports no max_datagram_size(); longer replies are fragmented. |
MIN_PSK_LEN |
4 bytes | protocols/src/hysteria/obfs.rs |
Shortest Salamander key. Validation refuses a shorter key on both sides: salamander obfs key must be at least 4 bytes. |
CONNECT_TIMEOUT |
10 s per address | protocols/src/hysteria/connection.rs |
Hy2Conn::connect bounds each address attempt: the socket bind, the QUIC handshake and the /auth round trip. The server name is resolved once, before the attempts, outside this timeout. A timed-out attempt is recorded as <addr>: timed out, and when every address fails the error is hysteria2: no address answered (…). |
OPEN_STREAM_TIMEOUT |
5 s | same | Bounds open_bi when a proxy stream is opened: hysteria2: timed out opening a proxy stream. |
DEFAULT_MAX_CONCURRENT_STREAMS |
102,400 | protocols/src/hysteria/config.rs |
The client’s streams semaphore. A permit is taken with try_acquire_owned before a stream is opened and held while it relays: hysteria2: connection is at its concurrent-stream limit. The default sits far above upstream Hysteria’s default of 1024 incoming streams per connection, so against such a server the server’s stream credit binds first and open_bi waits, up to OPEN_STREAM_TIMEOUT. Config key max_concurrent_streams; 0 is refused. |
MAX_UDP_SESSIONS |
256 | protocols/src/hysteria/connection.rs |
hysteria2: connection is at its UDP association limit. |
UDP_SESSION_BACKLOG |
256 datagrams | same | Capacity of each association’s receive channel. When it is full, try_send fails and the datagram is dropped, so a slow consumer never stalls the connection’s reader. |
HopInterval::DEFAULT |
30 s | shinku-quic/src/hop.rs |
How long a port-hopping client stays on one port when no interval is configured. See Port hopping. |
HopInterval::MIN_CONFIGURED |
5 s | same | The shortest hop interval validation accepts (port_hopping: the hop interval must be at least 5 seconds). The hop’s port list must not be empty (port hopping needs at least one port) and must not contain 0 (port 0 cannot be hopped to). |
RECONNECT_BACKOFF_BASE, RECONNECT_BACKOFF_MAX |
1 s, 30 s | protocols/src/hysteria/slot.rs |
ConnSlot::note_failure sets retry_at to BASE * 2^min(failures, 5), capped at MAX: 2 s, 4 s, 8 s, 16 s, then 30 s. |
MIN_HEALTHY_LIFETIME |
10 s | same | A connection lost within 10 s of starting counts as a failure (died_young), so backoff accumulates against a server that authenticates and then closes. |
WireGuard
Section titled “WireGuard”| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
DEFAULT_MTU |
1420 | protocols/src/wireguard/config.rs |
InMemoryDevice reports it as smoltcp’s max_transmission_unit. Config key mtu. |
CHANNEL_CAP |
256 items | protocols/src/wireguard/device.rs |
Capacity of the device’s command channel and of the two mpsc channels between each tunnel flow and the application side. The channels count items, not bytes: one WgStream write is one item of the caller’s buffer size. The driver holds at most one uplink item per connection (Uplink) and reads that connection’s channel only while it holds none, so the most one connection can queue on its way up is its 64 KiB TCP_BUFFER send ring, plus 256 channel items, plus 1 held item; past that, the writer waits. CHANNEL_CAP is also the most items the driver hands one connection’s socket per pass, so no producer can keep the driver to itself. On the way down, the driver reads a socket only while that connection’s channel has room; a downlink channel found full is waited on by RoomWaits, which wakes the driver once it has room. |
TCP_BUFFER |
64 KiB | same | Size of each smoltcp TCP ring buffer (one per direction), and of the payload store of each UDP packet buffer (one per direction, with 64 metadata slots). A UDP datagram that finds the send ring full is held until the next poll empties it. A datagram larger than the whole 64 KiB send ring can never be sent, so the driver drops it (logged at trace) instead of retrying it, and later datagrams keep flowing. |
SCRATCH |
64 KiB | same | The driver’s encapsulation scratch buffer and its UDP receive buffer, once per device. |
TIMER_TICK |
250 ms | same | tokio::time::interval that drives Tunn::update_timers. |
RECV_BATCH |
64 datagrams | same | The most datagrams taken from the peer socket in one driver pass: whatever has arrived joins the pass the first one wakes, because every pass sweeps every socket. |
Lifetimes |
keep-alive 60 s, timeout 180 s, orphan linger 60 s | same | Per tunnel TCP connection: an idle connection is probed after 60 s without traffic, a connection is aborted once nothing from its remote has been accepted for 180 s, and one whose application dropped both halves is aborted 60 s later if it has not closed. smoltcp bounds none of this by itself. |
REKEY_RETRY |
5 s | same | While any connection depends on a tunnel whose session expired after unanswered handshakes, the driver starts a handshake every 5 s, boringtun’s own retry interval. |
EPHEMERAL_BASE |
49152 | same | First tunnel-side source port. Each PortCursor wraps back here after 65535 and skips ports a live socket still holds, so 16,384 ports per protocol. |
| smoltcp poll delay | smoltcp’s own delay, else 3600 s | compute_sleep in the same file |
An inline literal, not a named constant. |
| smoltcp features | Cubic congestion control, 16 assembler segments, 4 reassembly buffers | protocols/Cargo.toml |
socket-tcp-cubic, assembler-max-segment-count-16 (room for 16 out-of-order segments per socket instead of 4) and reassembly-buffer-count-4 (4 IPv4 datagrams in reassembly at once instead of 1). |
FAILED_LOOKUP_TTL |
10 s | protocols/src/wireguard/connector.rs |
A name a UDP association could not resolve stays unresolved for 10 s; the next datagram after that looks it up again. An address once found is kept for the association’s life. |
TCP_CONNECT_ATTEMPT_TIMEOUT |
10 s per address | protocols/src/wireguard/slot.rs |
connect_tcp_any bounds each in-tunnel TCP connect. |
REBUILD_BACKOFF_BASE, REBUILD_BACKOFF_MAX |
1 s, 30 s | same | DeviceSlot::note_failure, with the same arithmetic as the Hysteria slot. While the slot is backing off, acquire_device fails with wireguard: tunnel is down, waiting before the next attempt and builds no tunnel. |
MIN_HEALTHY_LIFETIME |
10 s | same | A device that dies within 10 s counts as a failed start, because WgDevice::start performs no handshake and succeeds even against an unreachable peer. |
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
DEFAULT_MTU |
1500 | protocols/src/tun/config.rs |
Passed to the device and to IpStackConfig::mtu. Validation refuses an mtu below MIN_TUN_MTU (1280, supervisor/src/build/validate.rs): tun mtu must be at least 1280. |
DEFAULT_UDP_IDLE_TIMEOUT |
60 s | same | IpStackConfig::udp_timeout: the stack ends a quiet (source, destination) UDP flow. Config key udp_idle_timeout. |
DEFAULT_MAX_FLOWS |
65,536 per runtime | same | See Admission. |
FLOW_QUEUE |
16 | protocols/src/tun/udp.rs |
See Admission. |
RELEASE_TIMEOUT, RELEASE_POLL |
3 s, 20 ms | protocols/src/tun/inbound.rs |
TunInbound::shutdown polls every 20 ms, for up to 3 s, until the device handle and every tracked TCP flow are released. A timeout logs a warn. |
HOP_LIMIT |
64 | protocols/src/tun/ipv6.rs |
The hop limit of the RST Ipv6Screen answers a refused IPv6 SYN with. |
Two timers apply to TUN UDP. The stack’s udp_timeout ends each (source, destination) flow, and the association’s TunUdpCore runs Timing, so a whole association that is quiet for RELAY_IDLE_TIMEOUT finishes.
A TCP flow in the TUN inbound dials its outbound only after the client’s first bytes. serve_stream therefore wraps each runtime step in HANDSHAKE_TIMEOUT until the PassthroughCore is established, and a server-speaks-first protocol ends with tun: the client never spoke after 10 s.
Before the stack sees an IPv6 SYN, Ipv6Screen may refuse it with an RST: always when the inbound’s ipv6 is false (which also drops every other IPv6 packet), and otherwise when every target the route table may send the flow to lacks IPv6. See How Hysteria 2 and TUN enter.
| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
CACHE_CAPACITY |
8192 names | protocols/src/dns/mod.rs |
moka::future::Cache::max_capacity. The key is a name a client chooses, so the cache must be bounded. |
SYSTEM_TTL |
60 s | same | TTL for Backend::System answers, because getaddrinfo reports none. |
MIN_TTL, MAX_TTL |
5 s, 3600 s | same | resolve clamps every TTL into this range before it caches the answer. MAX_TTL is also moka’s cache-wide time_to_live. with_ttl_bounds overrides the range; the supervisor does not call it. |
QUERY_TIMEOUT |
5 s | same | Bounds each exchange with one server. |
UDP_BUF |
512 bytes | same | Receive buffer of the resolver’s own UDP queries. |
MAX_POINTER_HOPS |
16 | protocols/src/dns/message.rs |
skip_name steps over at most 16 labels of a name before it gives up (Truncated("dns name pointer chain")). It never follows a compression pointer (a pointer ends the name in place), so a pointer cycle cannot loop. |
MAX_NAME_LEN |
255 | same | Longest name encode_query accepts: dns: name too long (<n> bytes). |
Balancer
Section titled “Balancer”| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
DEFAULT_PROBE_INTERVAL |
30 s | supervisor/src/topology/balancer.rs |
spawn_probe runs one task per member on the supervisor’s task tracker. It probes at once, then sleeps this long after each probe, so the period is the probe’s duration plus the interval. etemenanki-app’s config key probe_interval (seconds) overrides it. |
DEFAULT_PROBE_TIMEOUT |
5 s | same | A probe resolves the member’s upstream and tries a TCP connect to each address in turn, all inside one tokio::time::timeout. Config key probe_timeout (seconds). |
Members start healthy. A change of state is logged at info as balancer member <tag> is now up or down. When every member is down, Balancer::select falls back to the first member instead of failing the flow.
Tracking and speed limits
Section titled “Tracking and speed limits”| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
EVENT_CAPACITY |
1024 events | supervisor/src/track/mod.rs |
The broadcast channel of flow lifecycle events. Sending never waits; a subscriber more than 1024 events behind gets RecvError::Lagged(n) and continues from the oldest event still kept. |
DEFAULT_SAMPLE_INTERVAL |
1 s | supervisor/src/track/sampler.rs |
The sampler’s tick: per-tick rates and totals, and the usage ledger’s reconcile. |
MIN_WAIT, MAX_WAIT |
1 ms, 1 s | supervisor/src/track/pace.rs |
A paced flow sleeps until its user’s debt is paid, clamped to this range, so a sliver of debt does not spin the timer and a raised or removed limit is felt within a second. The bucket holds one second of the user’s rate. |
Protocol frame caps and drivers
Section titled “Protocol frame caps and drivers”These bound what a parser accepts, what an encoder produces, or what a protocol driver buffers. A parser cap fails the frame where it is parsed. A frame with no parser cap is bounded only by the buffer it has to fit in, and ends the connection with FrameTooLarge when it does not.
| Constant | Value | Defined in | Meaning |
|---|---|---|---|
MAX_HEAD |
64 KiB | protocols/src/http/protocol.rs |
Longest HTTP request head, and HttpCore::BUF_SIZE. HttpCore fails with http head exceeds maximum size once the unparsed bytes reach it without a complete head. HttpConnect::reply checks the same bound on the proxy’s response head (http: proxy response head exceeds maximum size), but in the supervisor its client runtime of HTTP_BUF (16 KiB) saturates first. |
MAX_HEADERS |
128 | same | httparse header slots per head. |
HttpConnect::REQUEST_MAX |
1024 | protocols/src/http/codec.rs |
Upper bound on the CONNECT request the HTTP client stages, and its STAGING_RESERVE. |
AddressCodec::MAX_LEN |
259 | protocols/src/helpers/address.rs |
1 + 1 + 255 + 2: type, length, domain, port. Part of every reserve that includes an address. |
RELAY_BUF |
16 KiB | protocols/src/socks/server.rs |
Buffer per direction of a SOCKS CONNECT relay (BidirectionalConnection<A, B, RELAY_BUF>). Every RELAY_IDLE_TIMEOUT, relay_with_idle_guard compares the relayed byte counts with the previous check, and ends the relay with the error socks: relay idle when nothing moved. An idle relay therefore ends between 300 s and 600 s after its last byte. |
HUB_BUF |
64 KiB | same | Each of the two packet buffers of a SOCKS UDP ASSOCIATE relay. The association resets its RELAY_IDLE_TIMEOUT timer on every packet it forwards in either direction and ends when the timer fires. ExpectedSender::admits checks each datagram’s sender before the packet is parsed, and a datagram from an IP other than the client’s, or from another port once the client’s port is pinned, is discarded without resetting the timer, so traffic from another address cannot hold an association open. See The association’s client. |
RECV_BUF |
64 KiB | protocols/src/socks/udp_link.rs |
Receive buffer of SocksUdpLink, the SOCKS client’s UDP association. Every datagram is read into it, and one whose sender is not the relay, compared with endpoint (protocols/src/socks/protocol.rs), is discarded before it is parsed. |
MAX_LENGTH |
8192 | protocols/src/trojan/protocol.rs |
Largest Trojan UDP packet payload, and TrojanCore::MAX_DATAGRAM. |
MAX_PAYLOAD (VMess) |
1966 | protocols/src/vmess/framing.rs |
2048 - TAG_SIZE - 2 - 64: the most plaintext VMessCore and the VMess codecs put in one body chunk they seal, so a padded chunk never exceeds 2 KiB. |
MAX_PADDING, CHUNK_OVERHEAD_MAX |
64, 82 | same | Longest global-padding run on a chunk, and the most one sealed chunk adds beyond its plaintext (2 + TAG_SIZE + MAX_PADDING). |
AUTHID_WINDOW_SECS |
120 s | protocols/src/vmess/accounts.rs |
An auth id is accepted while its timestamp is within 120 s of the server clock, in either direction, unless the inbound’s clock check is off. |
PLAUSIBLE_STAMP_LIMIT |
2^33 s | same | With clock_check = false (AccountValidator::with_clock_check(false)), any stamp from 0 up to, but not including, 2^33 s (the year 2242) passes instead of the window. The replay set is the same. |
REPLAY_TTL |
240 s | same | 2 * AUTHID_WINDOW_SECS: how long a seen auth id is remembered, across REPLAY_SHARDS (64) shards. With the clock check off, it is the only replay protection left: an id replayed more than 240 s after it first arrived is admitted again. |
HINT_SETS, HINT_WAYS |
1024 sets of 16 addresses | same | SourceHints, the address hints: an address (an IPv4 address, or an IPv6 address’s /64) hashes, under a RandomState of the validator’s own, to one set, which keeps its 16 most recently matched addresses and evicts the least recent. However many addresses connect, at most 16,384 are remembered. |
HINT_USERS |
4 per address | same | The users that last matched from one address, most recent first; a fifth user pushes the oldest out. |
HOT_USERS |
4096 | same | The hot tier: the users with the newest match times, newest first, up to 4096, with copies of their key schedules. |
COLD_HITS_PER_REFRESH |
16 | same | Admitted matches that only the full scan found since the hot tier was last prepared. At 16, hot_tier_due() is true. A handshake never changes the tier; the listener refreshes it (HOT_TIER_POLL). |
MAX_PAYLOAD (Shadowsocks) |
0x3FFF |
protocols/src/ss_legacy/aead.rs |
Largest AEAD chunk payload, sealed or accepted. RECORD_OVERHEAD (protocols/src/ss_aead.rs) is 34 (2 + 16 + 16). The chunk decoder refuses a larger declared length before it waits for the payload: shadowsocks: record length 0x4000 exceeds 0x3fff. |
MAX_PADDING_LENGTH |
900 | protocols/src/ss_2022/protocol.rs |
The Shadowsocks 2022 client adds 1 to 900 random padding bytes to a request whose initial payload is shorter than 900 bytes. |
MAX_PACKET_SIZE |
0xFFFF |
protocols/src/ss_2022/crypto.rs |
Largest Shadowsocks 2022 record payload. The server core and the client codec split what they seal into records of at most this size. MAX_RECORD_LEN is MAX_PACKET_SIZE + RECORD_OVERHEAD (65,569): the BUF_SIZE of both, so every record the protocol allows is opened in place whole. |
REMEMBER |
60 s | protocols/src/ss_2022/replay.rs |
Length of one generation of the Shadowsocks 2022 request-salt filter; a salt is kept between one and two generations. |
Supervisor and front ends
Section titled “Supervisor and front ends”| Constant | Value | Defined in | Enforced by |
|---|---|---|---|
HTTP_BUF, SOCKS_BUF, TROJAN_BUF, VLESS_BUF |
16 KiB | supervisor/src/topology/outbound/mod.rs |
Client runtime buffer sizes; see Client codecs. |
VMESS_BUF |
32 KiB | same | same |
SS_BUF |
SsStream::BUF_SIZE, 20 KiB |
same | same |
SS2022_BUF |
Ss2022Stream::BUF_SIZE, MAX_RECORD_LEN = 65,569 bytes |
same | same |
SSS_TCP_BUF, SSS_UDP_BUF |
SssCore::TCP_BUF_SIZE (16 KiB), SssCore::UDP_BUF_SIZE (66 KiB) |
same | same: an sss TCP flow and an sss UDP flow each get a runtime of their own size |
SHUTDOWN_GRACE |
5 s | app/src/main.rs |
The grace etemenanki-app gives Supervisor::shutdown on SIGTERM or Ctrl-C. |
STOP_GRACE |
2 s | ffi/src/proxy.rs |
The grace the mobile library gives Supervisor::shutdown when the app stops the proxy. |
MAX_HEAD |
16 KiB | supervisor/src/ping.rs |
Supervisor::http_ping reads a response head up to this size; a longer one fails the delay test with the response head is over 16384 bytes. The whole test, dial included, runs under the timeout its caller passes. |
DEFAULT_DELAY_TIMEOUT, MAX_DELAY_TIMEOUT |
5 s, 30 s | webclient/src/router.rs |
The REST API’s GET /v1/outbounds/{tag}/delay: the timeout query, in milliseconds, is 5 s when absent and cut to 30 s when longer. |
HOT_TIER_POLL |
1 s | supervisor/src/serve.rs |
refresh_hot_tiers, spawned by run_stream_inbound, looks at the listener’s current handler once a second. When it is VMess and hot_tier_due(), it prepares the hot tier on the blocking pool and installs it, so a listener refreshes its tier at most once a second. It returns when the listener stops. |
Configurable limits
Section titled “Configurable limits”These are the limits etemenanki-app reads from its configuration file; everything else on this page is compiled in. The operator’s view of every key is in Limits.
| Config key | Struct in app/src/config.rs |
Default when absent | Refused |
|---|---|---|---|
max_connections |
Hysteria2InboundSettings |
DEFAULT_MAX_CONNECTIONS (262,144) |
0: max_connections and max_circuits must be at least 1 |
max_circuits |
Hysteria2InboundSettings |
DEFAULT_MAX_CIRCUITS (4,194,304) |
0: the same message |
udp_idle_timeout |
Hysteria2InboundSettings |
60 s | Outside 2 to 600 s: udp_idle_timeout must be between 2 and 600 seconds. Set while udp is off: udp_idle_timeout is set but udp is not enabled |
max_concurrent_streams |
Hysteria2OutboundSettings |
DEFAULT_MAX_CONCURRENT_STREAMS (102,400) |
0: max_concurrent_streams must be at least 1. No upper bound. |
mtu |
TunInboundSettings |
DEFAULT_MTU (1500) |
Below 1280: tun mtu must be at least 1280 |
obfs_password |
Hysteria2InboundSettings, Hysteria2OutboundSettings |
None | Shorter than MIN_PSK_LEN (4) bytes when obfs = "salamander": salamander obfs key must be at least 4 bytes |
mtu |
WireguardOutboundSettings |
DEFAULT_MTU (1420) |
None |
keepalive |
WireguardOutboundSettings |
None (no persistent keepalive) | A u16 number of seconds, passed to boringtun’s Tunn::new as the persistent keepalive interval |
ed=N in path |
WsStreamConfig, on an outbound |
No early data | Parsed from the path’s query by WsTarget::new; the limit is clamped to MAX_EARLY_DATA (16 KiB), and 0 disables early data |
probe_interval, probe_timeout |
BalancerConfig |
DEFAULT_PROBE_INTERVAL (30 s), DEFAULT_PROBE_TIMEOUT (5 s) |
Whole seconds (see Balancer) |
bandwidth.up, bandwidth.down |
Hysteria2BandwidthCfg, in Hysteria2InboundSettings and Hysteria2OutboundSettings |
None: no fixed rate | A bare number or an unknown unit: bandwidth.<field>: a bandwidth is a number and a unit, such as "100 mbps", or unknown bandwidth unit …; use bps, kbps, mbps, gbps or tbps |
ignore_client_bandwidth |
Hysteria2InboundSettings |
true exactly when neither bandwidth.up nor bandwidth.down is set |
None |
congestion |
Hysteria2InboundSettings, Hysteria2OutboundSettings |
cubic |
Anything but cubic, bbr, reno, newreno or new_reno: unknown congestion "x" (expected "cubic", "bbr" or "reno") |
quic.init_*, quic.max_* receive windows |
Hysteria2QuicCfg |
8 MiB per stream, 20 MiB per connection | Below 16,384 bytes; an init_* above its max_*: quic.init_<n> is above quic.max_<n> |
quic.max_idle_timeout |
Hysteria2QuicCfg |
30 s | Outside 4 to 120 s |
quic.keep_alive_period |
Hysteria2QuicCfg, outbound only |
10 s | Outside 2 to 60 s; on an inbound: quic.keep_alive_period is a client setting; a server does not ping |
quic.max_incoming_streams |
Hysteria2QuicCfg, inbound only |
65,536 | 0; on an outbound: quic.max_incoming_streams is a server setting |
ports |
Hysteria2OutboundSettings |
None: no hopping | A part that is not a port or a range: ports "…": "…" is not a port or a range of them; a list containing 0, or none |
hop_interval, or min_hop_interval with max_hop_interval |
Hysteria2OutboundSettings |
HopInterval::DEFAULT (30 s) when ports is set |
Below HopInterval::MIN_CONFIGURED (5 s); 0; both forms at once; one of min_hop_interval and max_hop_interval alone; an interval without ports |
clock_check |
VmessInboundSettings |
true |
None |
ipv6 |
TunInboundSettings |
true |
None |
padding_scheme |
AnytlsInboundSettings |
The reference scheme (DEFAULT_SCHEME, 137 bytes) |
A scheme that does not parse, or one over MAX_SCHEME_LEN (2 KiB) |
idle_session_check_interval, idle_session_timeout |
AnytlsOutboundSettings |
DEFAULT_IDLE (30 s) |
None; whole seconds, and a value of 5 or less means 30 s (MIN_IDLE) |
min_idle_session |
AnytlsOutboundSettings |
0 |
None |
udp_max_datagram |
SssInboundSettings, SssOutboundSettings |
MAX_DATAGRAM (65535) |
0: sss udp_max_datagram must be at least 1 |
flush_delay |
SssInboundSettings, SssOutboundSettings |
None: no delay | Over 10 ms: sss flush_delay must be at most 10ms; a value that is not a duration such as "5ms" or "10s" |
header_timeout |
SssInboundSettings |
DEFAULT_HEADER_TIMEOUT (10 s) |
"0s": sss header_timeout must be above zero; a value that is not a duration |
max_time_diff |
RealityStreamConfig, on an inbound |
None: no clock check | None; whole seconds, and 0 also means no check |
The numeric ranges live in the supervisor’s validation (supervisor/src/build/validate.rs), the sss ones and the AnyTLS scheme check included, so every front end gets them; the udp pairing, the rate and congestion spellings, the init_* and max_* pairing, which side a quic key belongs to, and the shape of the hop keys are etemenanki-app’s own (app/src/lower.rs). Each message is prefixed with its context. For an inbound tagged h, etemenanki-app --test -c on a config with max_connections = 0 logs an error line ending in configuration invalid: inbound h: max_connections and max_circuits must be at least 1 and exits with a failure status.
Per-connection memory budget
Section titled “Per-connection memory budget”The buffer cost of a connection is bounded by a sum of constants. The constants are caps: since concepts 2.1.0 a buffer grows with the bytes that pass through it, so the tables below give the most a connection can hold.
- A server runtime (
ProxyServerRuntime) has three buffers capped atBUF_SIZE:up(transport reads),staging(bytes toward the transport) andscratch(outbound reads). At first it allocates onlyup, at 2 KiB (INITIAL, orBUF_SIZEif smaller).staginggrows from nothing at its first stage, andscratchis allocated whole at the first outbound read. - A client runtime (
ProxyClientRuntime) has two buffers capped at itsBUF_SIZE:staging(sealed bytes toward the upstream) anddown(wire bytes from it). At first it allocates onlydown, at 2 KiB, and the boxed dial future, which it holds until the dial completes.
A connection that never gets past its handshake, such as a client that fails to authenticate, holds 2 KiB of buffers. One moving data reaches the caps within its first few reads. A connection routed to a proxy outbound pays for both runtimes. A connection routed to freedom pays only for the server side, because the outbound is a kernel socket.
Server cores
Section titled “Server cores”| Core | Runs | BUF_SIZE |
Sized for | STAGING_RESERVE |
MAX_DATAGRAM |
datagram_limit() |
At most, 3 × BUF_SIZE |
|---|---|---|---|---|---|---|---|
HttpCore |
one HTTP inbound connection | 64 KiB (MAX_HEAD) |
a whole request head | 256 | 4096 (default) | stream only | 192 KiB |
TrojanCore |
one Trojan inbound connection | 16 KiB | a UDP frame: header plus 8 KiB | 808 | 8192 (MAX_LENGTH) |
8192 | 48 KiB |
VlessCore |
one VLESS inbound connection | 16 KiB | a UDP frame of MAX_DATAGRAM behind its length |
808 | 8192 | 8192 | 48 KiB |
VMessCore |
one VMess inbound connection | 32 KiB | not stated in the source | 4096 | 8192 | 8192 | 96 KiB |
ShadowsocksCore |
one Shadowsocks inbound connection | 20 KiB | one MAX_PAYLOAD chunk plus overhead |
128 | 4096 (default) | stream only | 60 KiB |
Ss2022Core |
one Shadowsocks 2022 inbound connection | MAX_RECORD_LEN, 65,569 bytes |
the largest frame a client may send | 256 | 4096 (default) | stream only | 192 KiB (196,707 bytes) |
AnyTlsCore |
one AnyTLS session, every stream on it | 16 KiB | a Settings frame or a UDP packet frame whole; everything else is streamed | 2065 (2 * HEADER_LEN + MAX_SCHEME_LEN + 3) |
8192 (MAX_UDP_PAYLOAD) |
8192 | 48 KiB |
SssCore, TCP |
one sss TCP stream, after the gate | 16 KiB (TCP_BUF_SIZE) |
not stated in the source | 262 (PACKET_HEADER_MAX) |
65535 | stream only | 48 KiB |
SssCore, UDP |
one sss UDP stream, after the gate | 66 KiB (UDP_BUF_SIZE) |
a whole record of U = 65535 |
262 | 65535 (MAX_DATAGRAM) |
65535 | 198 KiB |
Hy2StreamCore |
one Hysteria 2 proxy stream | 8 KiB | a request with the longest address and padding | 2048 | 4096 (default) | stream only | 24 KiB |
Hy2UdpCore |
the datagrams of one Hysteria 2 connection | 16 KiB | a reassembled packet plus fragment headers | 4096 | 4096 (MAX_UDP_SIZE) |
4096 | 48 KiB |
PassthroughCore |
one TUN TCP flow | 8 KiB | “every buffer size this core needs” | 0 | 4096 (default) | stream only | 24 KiB |
TunUdpCore |
one TUN UDP association (one client source) | 8 KiB | a datagram plus the reserve | 4096 | 4096 | 4096 | 24 KiB |
How the non-literal reserves add up:
- Trojan:
PACKET_HEADER_MAX.next_multiple_of(16) + downlink_overhead(Self::BUF_SIZE).PACKET_HEADER_MAXis259 + 2 + 2 = 263, rounded up to 272, anddownlink_overhead(16 * 1024)is2 * 268 = 536, so the total is 808. - VLESS:
272 + downlink_overhead(Self::BUF_SIZE), also 808. - Shadowsocks:
32 + 2 * RECORD_OVERHEAD + 28, withRECORD_OVERHEAD = 34, is 128. - Shadowsocks 2022:
32 + 1 + 8 + 32 + 2 + 2 * TAG_LEN + RECORD_OVERHEAD + 115, withTAG_LEN = 16andRECORD_OVERHEAD = 34, is 256. - AnyTLS: two 7-byte frame headers, the longest padding scheme (2048) and
v=2(3): the core’s largest reply to one frame, its padding scheme and ServerSettings after the client’s Settings. Const assertions inprotocols/src/anytls/core.rshold every other reply below it, and the buffer above it plus a whole UDP packet frame. - sss:
PACKET_HEADER_MAXisADDRESS_MAX + varint::MAX_LEN,259 + 3: one datagram record’s header beyond its data.
A core that opens frames in place needs each frame to fit in BUF_SIZE, and a larger frame ends the connection with FrameTooLarge. Ss2022Core’s buffer is MAX_RECORD_LEN, so the largest record the protocol allows (a 0xFFFF payload plus its 34-byte RECORD_OVERHEAD) fits whole. ShadowsocksCore refuses a declared chunk length above MAX_PAYLOAD (0x3FFF) before it waits for the payload, so every chunk it accepts fits in its 20 KiB buffer.
The Hysteria 2 listener costs at most 24 KiB per proxy stream, plus at most 48 KiB per connection when udp is enabled; the datagram runtime starts only after the connection authenticates.
An sss stream builds no runtime before its gate admits it: while it waits for its header it reads at most B_pre raw bytes (never more than 1 MiB), and an inbound that falls back keeps a copy of them to replay. A REALITY socket handed to dest builds no runtime either; it costs the relay’s two buffers of RELAY_BUFFER (16 KiB) each, longer when what one side already sent during the handshake is longer.
SOCKS inbound
Section titled “SOCKS inbound”The SOCKS inbound is the one stream protocol that does not run a core, so it has its own budget:
| SOCKS path | Buffers | Total |
|---|---|---|
CONNECT |
BidirectionalConnection<A, B, RELAY_BUF>: one 16 KiB buffer per direction, allocated when the relay starts. With sniffing on and an IP target, collect_prefix first holds a 4 KiB read chunk and a Collector with 4 KiB of capacity (8 KiB before the relay exists). The collected prefix stays in scope in connect for the rest of the relay. |
32 KiB, or 36 KiB after a sniff |
UDP ASSOCIATE |
up and down, each HUB_BUF (64 KiB), a 2 KiB packet BytesMut and a 256-byte sink array. associate allocates them only after ExpectedSender::new has accepted the request and the relay socket is bound, so an association refused with reply 0x02 costs none of them. |
about 130 KiB |
Client codecs
Section titled “Client codecs”| Outbound | Codec | Buffer constant | STAGING_RESERVE |
At most, 2 × BUF |
|---|---|---|---|---|
| HTTP | HttpConnect |
HTTP_BUF = 16 KiB |
1024 (REQUEST_MAX) |
32 KiB |
SOCKS (CONNECT) |
SocksConnect |
SOCKS_BUF = 16 KiB |
528 (a 513-byte credential message, or a request with a full address) | 32 KiB |
| Trojan | TrojanStream, TrojanDatagram |
TROJAN_BUF = 16 KiB |
320 (REQUEST_HEADER_MAX = 56 + 2 + 1 + 259 + 2) |
32 KiB |
| VLESS | VlessStream, VlessDatagram |
VLESS_BUF = 16 KiB |
296 (RESERVE = REQUEST_HEADER_MAX + ENCODED_MAX = 1 + 16 + 1 + 1 + 259 + 18, a header with the Vision addons) |
32 KiB |
| VMess | VMessStream, VMessDatagram |
VMESS_BUF = 32 KiB |
384 (HEADER_MAX = 358, rounded up to a multiple of 64) |
64 KiB |
| Shadowsocks | SsStream |
SS_BUF = 20 KiB |
386 (32 + RECORD_OVERHEAD + AddressCodec::MAX_LEN + 61) |
40 KiB |
| Shadowsocks 2022 | Ss2022Stream |
SS2022_BUF = MAX_RECORD_LEN, 65,569 bytes |
2048 | 128 KiB (131,138 bytes) |
| sss, TCP | SssStream |
SSS_TCP_BUF = 16 KiB |
276 (HEADER_MAX) |
32 KiB |
| sss, UDP | SssDatagram |
SSS_UDP_BUF = 66 KiB |
276 (HEADER_MAX) |
132 KiB |
Outbounds that do not use a client runtime:
| Outbound | Per-flow userspace buffers |
|---|---|
freedom |
None; the outbound is a kernel socket. |
blackhole |
None. |
SOCKS UDP ASSOCIATE |
SocksUdpLink: a 64 KiB RECV_BUF array and a 2 KiB scratch BytesMut, about 66 KiB. |
| WireGuard, TCP flow | Two smoltcp ring buffers of TCP_BUFFER: 128 KiB. Channel items come on top of the two rings, and they are bounded: up to CHANNEL_CAP (256) plus one held item on the way up, and up to 256 on the way down, each as large as the write or socket read that produced it. The device adds 2 × SCRATCH (128 KiB) once, shared by all its flows. |
| WireGuard, UDP flow | Two smoltcp packet buffers with TCP_BUFFER of payload each: 128 KiB. Channel items come on top, bounded the same way: up to CHANNEL_CAP (256) datagrams plus one held on the way up, and up to 256 on the way down. |
| Hysteria 2 | No fixed buffer. QUIC flow control bounds data in flight at the receive windows of QuicOptions: by default 8 MiB per stream and 20 MiB per connection, both configurable. |
| AnyTLS | No client runtime. A flow owns one session while it lives: a read buffer of up to 16 KiB (READ_BUF), and its queued writes, which a new write waits to drain before it queues one packet of at most MAX_PACKET_DATA. Padding records are written from a shared buffer of zeros. |
Worked totals
Section titled “Worked totals”| Inbound → outbound | Server side, at most | Client side, at most | Total, at most |
|---|---|---|---|
Trojan → freedom |
48 KiB | 0 | 48 KiB |
| VLESS → VLESS | 48 KiB | 32 KiB | 80 KiB |
| VMess → VMess | 96 KiB | 64 KiB | 160 KiB |
HTTP → freedom |
192 KiB | 0 | 192 KiB |
| Shadowsocks 2022 → WireGuard (TCP) | 192 KiB | 128 KiB | 320 KiB |
AnyTLS (one session) → freedom |
48 KiB | 0 | 48 KiB |
| sss UDP → sss UDP | 198 KiB | 132 KiB | 330 KiB |
SOCKS CONNECT → Trojan |
32 KiB | 32 KiB | 64 KiB |
TUN TCP → freedom |
24 KiB | 0 | 24 KiB |
A mux.cool carrier pays for its server runtime once. Each sub-flow routed to a proxy outbound adds its own client runtime. A Trojan carrier with the maximum 256 sub-flows through a VLESS outbound therefore holds at most 48 KiB + 256 × 32 KiB = 8,240 KiB, about 8 MiB.
Invariants
Section titled “Invariants”| Invariant | Mechanism | Pinned by |
|---|---|---|
| A runtime can always stage its reserve | assert!(BUF_SIZE > Core::STAGING_RESERVE) in ProxyServerRuntime::build, assert!(BUF_SIZE > Codec::STAGING_RESERVE) in ProxyClientRuntime::new |
Every runtime built in the tests, at each core’s own BUF_SIZE; there is no dedicated should_panic test |
A buffer grows to BUF_SIZE and no further |
ReadBuffer doubling and Staging::reserve stop at N |
read_buffer_starts_small_and_doubles_up_to_n, make_room_moves_the_tail_and_grows_below_n, write_buffer_holds_nothing_until_a_stage, staging_grows_to_n_and_no_further in concepts/src/buffer.rs |
A frame larger than BUF_SIZE is an error, not a stall |
poll_transport_read grows the read buffer with make_room, and returns FrameTooLarge once up.is_saturated() |
frame_larger_than_the_buffer_is_an_error, a_frame_past_the_first_read_buffer_is_relayed_whole_both_ways, a_frame_past_the_grown_buffer_is_still_an_error in concepts/tests/runtime.rs |
| Staging backpressure never truncates a datagram from an outbound | A datagram outbound is polled only with STAGING_RESERVE + datagram_limit() of room |
datagram_outbound_is_never_truncated_by_staging_backpressure in concepts/tests/runtime.rs |
| A stalled outbound stalls its own uplink, not other downlinks | Effects apply in order, and a blocked forward pins the transport read | stalled_outbound_holds_uplink_but_not_other_downlink in concepts/tests/runtime.rs |
| The client runtime never buffers beyond its two capped buffers | poll_write waits for STAGING_RESERVE + 1 bytes of room |
backpressure_from_the_wire_reaches_the_writer in concepts/tests/client.rs |
| The handshake deadline is armed once, the idle deadline on every byte event | Timing::touch |
timing_arms_handshake_once_then_idle_per_byte_event in protocols/tests/unit/core/mod.rs |
| A deadline fires against the tokio clock | The runtime’s timer is a tokio Sleep, so a paused test clock advances it |
deadline_event_lets_the_core_time_out, deadline_is_armed_against_the_tokio_clock in concepts/tests/runtime.rs |
Sniffing never takes more than SNIFF_LIMIT, and costs nothing until it is given bytes |
SniffPrefix::push takes at most Collector::remaining(); Collector::push reserves SNIFF_LIMIT at its first non-empty push |
sniff_prefix_takes_no_more_than_its_budget in protocols/tests/unit/core/mod.rs; a_new_collector_owns_no_memory, pushing_nothing_reserves_nothing, the_first_bytes_reserve_the_whole_budget_and_filling_it_never_moves_it in protocols/tests/unit/sniff/collector.rs |
| A served gRPC connection with no streams is told to go away, and one whose peer stops answering is dropped | Liveness: H2_IDLE_TIMEOUT, H2_KEEPALIVE_TIMEOUT against the ReadClock, H2_PONG_TIMEOUT |
an_idle_connection_is_told_to_go_away, a_refused_stream_does_not_restart_the_idle_deadline, a_peer_that_goes_silent_is_dropped_once_a_ping_goes_unheard, a_peer_that_sends_but_never_reads_is_dropped_once_its_pong_is_overdue in protocols/tests/unit/transports/accept.rs |
An IP is banned only after max_failures within its window, and only for duration |
Guard::failed restarts a count whose window or ban is over; Failures::banned_at |
an_ip_is_banned_at_the_limit_and_until_the_ban_ends, failures_outside_the_window_start_a_new_count, a_success_clears_the_count_but_not_a_ban in supervisor/tests/unit/guard.rs |
| An IPv6 client is counted and banned by its /64, and an IPv4-mapped address as its IPv4 address | BanKey::of, the key of every failure, ban and clearing success |
an_ipv6_client_is_counted_and_banned_by_its_64, a_success_anywhere_in_the_64_clears_its_count, an_ipv4_mapped_address_counts_as_its_ipv4 in supervisor/tests/unit/guard.rs |
| Hysteria 2 QUIC settings and port hopping stay within upstream’s limits | hy2_quic, port_hopping in supervisor/src/build/validate.rs |
hysteria2_quic_settings_stay_within_upstreams_limits, hysteria2_port_hopping_needs_ports_and_a_sane_interval in supervisor/tests/unit/validate.rs |
| A mux carrier never holds more than 256 sub-flows | Demux declines New with End |
unknown_or_excess_sessions_are_declined_with_end in protocols/tests/unit/mux/demux.rs |
| An AnyTLS session never holds more than 256 streams, and its split UDP packets never more than 64 KiB | A SYN past MAX_STREAMS gets a FIN; a packet over MAX_UDP_PAYLOAD or past UDP_REASSEMBLY_BUDGET is skipped |
the_257th_stream_is_declined_and_the_session_goes_on, an_oversized_packet_is_skipped_and_the_next_one_goes_through, reassembly_stops_at_the_session_budget in protocols/tests/unit/anytls/core.rs |
An sss server reads at most B_pre raw bytes, for at most T_h, before authentication |
TransformStream::with_budget limits every read to what is left of the budget; accept reads the header under timeout_at |
no_header_within_the_budget_stops_reading_at_the_budget in protocols/tests/unit/sss/transform/stream.rs; an_incomplete_header_times_out_at_t_h, a_drained_stream_closes_at_t_h_like_a_waiting_one in protocols/tests/unit/sss/server.rs |
| A REALITY socket handed to dest holds no handshake permit and is never reported to the ban guard | The supervisor drops the handshake permit before Camouflage::run and keeps the live one |
a_camouflaged_connection_gives_its_handshake_permit_back in supervisor/tests/unit/serve.rs |
| gRPC and WebSocket never buffer a message beyond 1 MiB | The MAX_GRPC_MESSAGE_LEN check runs before buffering; ws_config() |
decoder_rejects_an_oversized_length_before_buffering_the_body in grpc_framing.rs; the_configured_limits_replace_tungstenite_defaults in ws_endpoint.rs |
| An HTTP/2 connection’s write buffer never holds more than one TLS record’s plaintext | Coalesced::poll_write takes only what fits in HELD_MAX and sends a full buffer before it takes more |
a_full_buffer_goes_out_before_more_is_taken, a_stalled_stream_stalls_the_writer_instead_of_growing_the_buffer, a_flush_frees_the_buffer in protocols/tests/unit/transports/coalesce.rs |
| A real-IP header lists at most 32 addresses | RealIpHeader::read calls a longer list Malformed |
a_forwarded_list_keeps_its_order_across_lines in ws_endpoint.rs |
| The VMess address hints stay bounded however many addresses connect | SourceHints::remember evicts a full set’s least recently matched address |
the_hints_are_bounded, an_address_remembers_its_last_few_users in protocols/tests/unit/vmess/accounts.rs |
| A dial tries every address before failing | TcpDialer::connect_any |
connect_any_falls_through_a_dead_address in environment/tests/integration/tcp.rs |
| The DNS cache stays bounded under distinct names | moka max_capacity(CACHE_CAPACITY) |
the_cache_stays_bounded_under_distinct_names in protocols/tests/unit/dns/mod.rs |
| Reconnect backoff grows and is capped | note_failure shifts by at most 5, then takes min(MAX) |
backoff_grows_with_each_failure_and_is_capped (Hysteria), repeated_failures_escalate_the_backoff (WireGuard) |
| A SOCKS UDP association’s buffers and idle timer serve only its client | ExpectedSender::admits runs before parse_udp_packet and before the idle timer is reset: every datagram must come from the control connection’s IP, and the first one forwarded pins the port unless the request already named it with that IP. Over a Unix socket, the request must name the exact IP and port |
udp_association_ignores_another_ip (Linux only) and udp_association_ignores_another_port_once_pinned in protocols/tests/pipeline/socks.rs; only_the_control_peer_is_heard_and_its_first_datagram_pins_the_port in protocols/tests/unit/socks/server.rs |
| Hysteria UDP sessions count against the circuit budget | Hy2UdpCore takes a circuit_permits permit per session |
the_circuit_limit_refuses_new_sessions in protocols/tests/unit/hysteria/server/datagrams.rs |
| The WireGuard driver holds at most one uplink item per connection; a stalled tunnelled flow blocks its writer, not its siblings | Uplink holds at most one item that the socket has not accepted, and poll_refill reads the channel only while nothing is held, so a full socket fills the bounded channel and the application’s sender waits |
a_stalled_tcp_flow_blocks_its_writer in protocols/tests/pipeline/wireguard.rs (a writer of 1 KiB chunks must wait before 512 KiB are in, against an expected 385 KiB, while another flow on the same tunnel still echoes); a_held_item_keeps_the_channel_unread in protocols/tests/unit/wireguard/device.rs |
Failure paths and cancellation
Section titled “Failure paths and cancellation”When a limit trips, the result is one of five kinds. Knowing the kind tells you where to look in the logs.
| Kind | Limits | What the peer sees | Log |
|---|---|---|---|
| Silent drop at admission | MAX_LIVE_CONNECTIONS_PER_INBOUND, MAX_HANDSHAKES_PER_INBOUND, a banned IP (Policies::ip_ban), TUN max_flows and FLOW_QUEUE, Hysteria UDP MAX_SESSIONS, the circuit limit for Hysteria datagrams |
The socket closes, or the packet is lost | debug or trace; a ban is logged at info when it starts (banned <ip> for <n>s after <n> failed authentications, where <ip> is the IPv4 address or the IPv6 /64, such as 2001:db8:1:2::/64), and the connections it drops are not |
| Explicit refusal | A handoff refused (0x01 to the relay, which keeps its connection), Hysteria max_connections (incoming.refuse()), the circuit limit on a Hysteria stream (H3_REQUEST_REJECTED), MAX_CLASSIFYING_STREAMS (H3_EXCESSIVE_LOAD), mux MAX_SESSIONS (an End frame), AnyTLS MAX_STREAMS (a FIN), WebSocket early data (413) |
A protocol-level refusal; the carrier connection survives where there is one | debug; the mux and AnyTLS declines log nothing |
| Connection error | FrameTooLarge, HANDSHAKE_TIMEOUT, TRANSPORT_HANDSHAKE_TIMEOUT, PROXY_HEADER_TIMEOUT, MAX_GRPC_MESSAGE_LEN, MAX_WS_MESSAGE_LEN, the parser frame caps, the SOCKS relay idle check, a user’s device_limit, carrier_max_failures, an AnyTLS Settings frame over settings::MAX_LEN (after an Alert), a REALITY handshake that runs out of time after our flight, MAX_USELESS_RECORDS |
The connection closes | debug. For a stream inbound, a transport failure is inbound transport failed: <error> from serve_socket, and a runtime or driver error is <protocol> connection from <source> ended: <error> from serve_connection, with the source printed as an Option |
| Handed elsewhere, or drained | A socket that fails the REALITY decision, a ClientHello past MAX_HELLO_BYTES or MAX_CLIENT_HELLO, dest’s answer past DEST_CAPTURE_LIMIT, the REALITY deadline before our flight; an sss stream refused before authentication (no valid header naming a known user within B_pre and T_h) |
REALITY: dest’s own answers, through the camouflage relay. sss: nothing at all while the stream is drained until the peer closes or T_h, or the fallback’s answers |
debug, a category only: <tag>: <source> goes to dest: <reason> and <tag>: sss stream from <source> refused: <reason>. Neither is reported to the IP ban guard |
| Clean end | RELAY_IDLE_TIMEOUT in a core, WS_IDLE_TIMEOUT, H2_IDLE_TIMEOUT (a GOAWAY), the PING and PONG timeouts, the QUIC idle timeout (quic.max_idle_timeout), the Hysteria UDP sweep, the SOCKS UDP ASSOCIATE idle timer |
The stream ends as if the peer had gone | Usually none |
Cancellation does not depend on any of these timers. Every stream connection runs under its session’s token (Shared::spawn_until), a child of the supervisor’s root token; a REALITY camouflage relay and an sss drain or fallback are closed with their session like any other connection. The Hysteria 2 and TUN inbounds own their per-connection work in a JoinSet inside their run future. Closing a session, stopping a TUN listener or shutting the supervisor down drops each runtime, and with it its buffers and permits. The Hysteria 2 and TUN inbounds then wait up to DRAIN_TIMEOUT and RELEASE_TIMEOUT for their socket or device to come free. See Listeners and the serve loop.
| Test | File | Pins |
|---|---|---|
read_buffer_starts_small_and_doubles_up_to_n, make_room_moves_the_tail_and_grows_below_n, compact_frees_room_in_any_buffer_short_of_saturated, a_small_n_is_allocated_whole, grow_to_makes_room_for_a_whole_datagram_up_to_n, write_buffer_holds_nothing_until_a_stage, staging_grows_to_n_and_no_further |
concepts/src/buffer.rs (inline) |
INITIAL, doubling up to N, grow_to, staging growth |
frame_larger_than_the_buffer_is_an_error, a_frame_past_the_first_read_buffer_is_relayed_whole_both_ways, a_frame_past_the_grown_buffer_is_still_an_error, a_datagram_past_the_first_read_buffer_is_delivered_whole |
concepts/tests/runtime.rs |
FrameTooLarge at the cap, growth below it |
datagram_outbound_is_never_truncated_by_staging_backpressure |
concepts/tests/runtime.rs |
datagram_limit() and the datagram read condition |
stalled_outbound_holds_uplink_but_not_other_downlink |
concepts/tests/runtime.rs |
Ordered effects as backpressure |
deadline_event_lets_the_core_time_out, deadline_is_armed_against_the_tokio_clock |
concepts/tests/runtime.rs |
The single core deadline |
backpressure_from_the_wire_reaches_the_writer |
concepts/tests/client.rs |
Client runtime staging bound |
connect_any_falls_through_a_dead_address |
environment/tests/integration/tcp.rs |
Sequential per-address dialing |
timing_arms_handshake_once_then_idle_per_byte_event, timing_reports_handshake_and_sniff_expiry_to_the_core |
protocols/tests/unit/core/mod.rs |
Timing |
sniff_prefix_takes_no_more_than_its_budget, a_sniffing_passthrough_core_opens_on_the_sniff_deadline, passthrough_core_finishes_when_the_outbound_fails_or_idles |
protocols/tests/unit/core/mod.rs |
SNIFF_LIMIT, SNIFF_TIMEOUT, RELAY_IDLE_TIMEOUT |
handshake_deadline_fails_the_connection, sniff_deadline_opens_with_what_was_collected |
protocols/tests/unit/trojan/core.rs |
Handshake and sniff deadlines in a real core |
the_budget_ends_the_search_without_a_match, a_new_collector_owns_no_memory, pushing_nothing_reserves_nothing, the_first_bytes_reserve_the_whole_budget_and_filling_it_never_moves_it |
protocols/tests/unit/sniff/collector.rs |
SNIFF_LIMIT, and when the collector allocates it |
a_connection_that_opens_no_stream_is_given_up_on, an_idle_connection_is_told_to_go_away, a_refused_stream_does_not_restart_the_idle_deadline |
protocols/tests/unit/transports/accept.rs |
H2_IDLE_TIMEOUT and the GOAWAY, end to end |
a_peer_still_sending_is_kept_while_its_pong_waits_behind_a_slow_downlink, a_peer_that_goes_silent_is_dropped_once_a_ping_goes_unheard, a_peer_that_sends_but_never_reads_is_dropped_once_its_pong_is_overdue |
protocols/tests/unit/transports/accept.rs |
H2_KEEPALIVE_TIMEOUT against any byte heard, H2_PONG_TIMEOUT |
liveness_gives_up_on_a_connection_with_no_streams, liveness_keeps_a_connection_carrying_streams, liveness_restarts_the_idle_deadline_on_progress, liveness_gives_a_departing_connection_a_pong_s_time |
protocols/tests/unit/transports/grpc_liveness.rs |
Liveness |
decoder_accepts_a_message_at_the_maximum, decoder_rejects_a_message_longer_than_the_maximum, decoder_rejects_an_oversized_length_before_buffering_the_body |
protocols/tests/unit/transports/grpc_framing.rs |
MAX_GRPC_MESSAGE_LEN |
rejects_oversized_early_data_header, callback_rejects_oversized_early_data, the_configured_limits_replace_tungstenite_defaults, a_forwarded_list_keeps_its_order_across_lines |
protocols/tests/unit/transports/ws_endpoint.rs |
MAX_EARLY_DATA, MAX_WS_MESSAGE_LEN, MAX_REAL_IP_ADDRESSES |
the_longest_header_is_taken, a_malformed_header_is_refused |
protocols/tests/unit/transports/proxy_protocol.rs |
MAX_V2_LEN: a header of exactly 4096 bytes is taken, one byte longer is refused |
a_full_buffer_goes_out_before_more_is_taken, a_stalled_stream_stalls_the_writer_instead_of_growing_the_buffer, a_flush_frees_the_buffer |
protocols/tests/unit/transports/coalesce.rs |
HELD_MAX: a full buffer goes out first, a stalled stream stalls the writer, a flush frees the buffer |
unknown_or_excess_sessions_are_declined_with_end |
protocols/tests/unit/mux/demux.rs |
Mux MAX_SESSIONS |
parse_frame_enforces_the_length_caps |
protocols/tests/unit/mux/frame.rs |
MAX_META_LEN, MAX_DATA_LEN |
an_oversized_head_is_refused |
protocols/tests/unit/http/core.rs |
MAX_HEAD |
udp_association_ignores_another_ip, udp_association_ignores_another_port_once_pinned, udp_association_refuses_a_relay_that_cannot_hear_the_client, udp_link_ignores_datagrams_not_from_the_relay |
protocols/tests/pipeline/socks.rs |
Which datagrams the SOCKS UDP ASSOCIATE relay (HUB_BUF) and SocksUdpLink (RECV_BUF) act on, and the 0x02 refusal of an association whose client the relay could never hear |
only_the_control_peer_is_heard_and_its_first_datagram_pins_the_port, a_relay_that_cannot_hear_the_client_is_refused |
protocols/tests/unit/socks/server.rs |
ExpectedSender and hears |
rejects_oversize_udp_packet |
protocols/tests/unit/trojan/protocol.rs |
Trojan MAX_LENGTH |
user_not_found_outside_time_window, replayed_authid_is_rejected, expired_ids_leave_the_set |
protocols/tests/unit/vmess/accounts.rs |
AUTHID_WINDOW_SECS, REPLAY_TTL |
an_address_remembers_its_last_few_users, the_hints_are_bounded, the_hot_tier_changes_only_when_a_refresh_is_installed, the_hot_tier_is_the_most_recent_users_newest_first |
protocols/tests/unit/vmess/accounts.rs |
HINT_USERS, HINT_SETS and HINT_WAYS, COLD_HITS_PER_REFRESH, HOT_USERS |
an_idle_session_is_closed_by_the_sweep, the_circuit_limit_refuses_new_sessions |
protocols/tests/unit/hysteria/server/datagrams.rs |
SWEEP_INTERVAL, circuit permits |
reassembly_stops_at_the_maximum_datagram_size, a_payload_needing_more_than_255_fragments_is_refused, sanitise_message_caps_length_and_tolerates_bad_utf8 |
protocols/tests/unit/hysteria/protocol.rs |
MAX_UDP_SIZE, fragmentation, MAX_MESSAGE_KEPT |
backoff_grows_with_each_failure_and_is_capped, a_connection_that_never_started_counts_as_dying_young, a_backing_off_slot_refuses_without_dialling |
protocols/tests/unit/hysteria/slot.rs |
Reconnect backoff, MIN_HEALTHY_LIFETIME |
repeated_failures_escalate_the_backoff, a_short_lived_tunnel_counts_as_a_failure, the_backoff_gate_refuses_without_building_another_tunnel |
protocols/tests/unit/wireguard/slot.rs |
Rebuild backoff, MIN_HEALTHY_LIFETIME |
a_held_item_keeps_the_channel_unread, the_uplink_finishes_only_after_its_last_item |
protocols/tests/unit/wireguard/device.rs |
Uplink: one held item, the channel left unread behind it, and the end of the uplink seen only after its last item is handed on |
an_orphan_whose_remote_went_silent_is_reaped_after_its_linger, a_remote_that_vanishes_under_an_idle_connection_is_given_up_on, an_idle_connection_to_a_live_remote_outlives_the_timeout |
protocols/tests/unit/wireguard/device.rs |
Lifetimes |
an_expired_session_in_use_is_revived_every_retry_interval, an_expired_session_nobody_uses_stays_quiet, a_tunnel_revives_after_its_peer_was_gone_past_the_handshake_budget |
protocols/tests/unit/wireguard/device.rs |
REKEY_RETRY |
a_full_downlink_channel_wakes_the_driver_once_it_has_room, a_stalled_reader_does_not_keep_the_driver_busy |
protocols/tests/unit/wireguard/device.rs |
RoomWaits |
a_failed_lookup_is_retried_once_its_ttl_is_up |
protocols/tests/unit/wireguard/connector.rs |
FAILED_LOOKUP_TTL |
a_stalled_tcp_flow_blocks_its_writer, an_oversized_datagram_does_not_wedge_the_association |
protocols/tests/pipeline/wireguard.rs |
The CHANNEL_CAP bound on a stalled TCP flow; dropping a datagram larger than the TCP_BUFFER send ring |
the_association_finishes_when_the_outbound_fails_or_idles |
protocols/tests/unit/tun/udp.rs |
TUN UDP association idle |
the_cache_stays_bounded_under_distinct_names, an_expired_entry_is_looked_up_again |
protocols/tests/unit/dns/mod.rs |
CACHE_CAPACITY, TTL expiry |
the_257th_stream_is_declined_and_the_session_goes_on, violations_end_the_session_with_an_alert, an_oversized_packet_is_skipped_and_the_next_one_goes_through, reassembly_stops_at_the_session_budget |
protocols/tests/unit/anytls/core.rs |
MAX_STREAMS, a Settings frame over settings::MAX_LEN, MAX_UDP_PAYLOAD, UDP_REASSEMBLY_BUDGET |
settings_longer_than_the_bound_are_refused |
protocols/tests/unit/anytls/settings.rs |
settings::MAX_LEN: 4096 bytes parse, 4097 do not |
an_incomplete_header_times_out_at_t_h, a_drained_stream_closes_at_t_h_like_a_waiting_one |
protocols/tests/unit/sss/server.rs |
T_h for a waiting and a drained stream |
no_header_within_the_budget_stops_reading_at_the_budget, the_flush_delay_is_capped_at_ten_milliseconds |
protocols/tests/unit/sss/transform/stream.rs |
B_pre, MAX_FLUSH_DELAY |
useless_records_are_limited |
reality/tests/unit/server/handshake.rs |
MAX_USELESS_RECORDS before the client’s Finished |
empty_records_are_limited |
reality/tests/unit/stream.rs |
MAX_USELESS_RECORDS on an established stream |
non_tls_traffic_stops_after_the_packet_budget |
protocols/tests/unit/vless/vision/filter.rs |
PACKETS_TO_FILTER |
non_tls_traffic_ends_the_framing |
protocols/tests/unit/vless/vision/framer.rs |
The early COMMAND_END: plain after the seventh write of traffic that is not TLS |
the_longest_vision_header_fits_the_declared_reserve |
protocols/tests/unit/vless/codec.rs |
The VLESS client STAGING_RESERVE, 296 bytes, for both codecs |
failures_say_why_and_never_outlast_the_timeout |
supervisor/tests/ping.rs |
A delay test toward a silent server ends with PingError::Timeout within a second of its 300 ms timeout |
a_hysteria2_udp_idle_timeout_is_between_2_and_600_seconds, hysteria2_serves_at_least_one_connection_and_one_circuit, a_tun_device_mtu_is_at_least_1280, a_salamander_key_is_at_least_4_bytes_on_either_side |
supervisor/tests/unit/validate.rs |
Validation of limits |
a_hysteria2_client_needs_a_password_and_a_stream |
supervisor/tests/unit/validate.rs |
max_concurrent_streams of 0 |
a_handoff_socket_is_an_absolute_path_a_unix_socket_can_take |
supervisor/tests/unit/validate.rs |
MAX_SOCKET_PATH: a 107-byte handoff path is taken, a 108-byte one refused |
a_handoff_setting_the_relay_could_not_use_is_refused |
katana tests/unit/lower/inbound.rs |
katana’s MAX_SOCKET_PATH: a 96-byte handoff_dir is taken for a node on every address and refused for one on 2001:db8::1, and a 97-byte one is refused |
hysteria2_quic_settings_stay_within_upstreams_limits, hysteria2_port_hopping_needs_ports_and_a_sane_interval |
supervisor/tests/unit/validate.rs |
The quic ranges, HopInterval::MIN_CONFIGURED, the port list |
an_ip_is_banned_at_the_limit_and_until_the_ban_ends, failures_outside_the_window_start_a_new_count, a_success_clears_the_count_but_not_a_ban, an_ipv6_client_is_counted_and_banned_by_its_64, a_success_anywhere_in_the_64_clears_its_count, an_ipv4_mapped_address_counts_as_its_ipv4, a_sweep_drops_what_no_longer_counts, without_a_ban_policy_nothing_is_counted, a_carrier_is_closed_after_failed_streams_in_a_row |
supervisor/tests/unit/guard.rs |
IpBanPolicy and its key (BanKey), SWEEP_INTERVAL’s sweep, carrier_max_failures |
a_session_from_one_ip_too_many_is_refused_and_closed, an_ip_frees_its_slot_when_its_last_session_ends, the_limit_is_per_user_and_absent_means_any |
supervisor/tests/unit/session.rs |
device_limit |
a_users_sessions_come_from_no_more_ips_than_their_device_limit, an_ip_failing_to_authenticate_is_turned_away_and_others_are_not, a_grpc_connection_whose_streams_keep_failing_is_closed |
supervisor/tests/guard.rs |
The device limit, the IP ban and carrier_max_failures, end to end |
accept_error_backoff_classification |
supervisor/tests/unit/serve.rs |
Which accept errors back off |
a_camouflaged_connection_gives_its_handshake_permit_back |
supervisor/tests/unit/serve.rs |
A REALITY socket handed to dest: its handshake permit back while the relay runs, the live permit held until it ends, nothing reported to the ban guard, and the relay ended by closing its session |
a_due_hot_tier_is_refreshed_by_the_listener |
supervisor/tests/unit/serve.rs |
HOT_TIER_POLL: a due tier is refreshed, and the refresher stops with its listener |
every_member_down_still_selects_rather_than_dropping |
supervisor/tests/unit/balancer.rs |
Balancer fallback |
a_limited_users_flow_moves_at_its_limit, a_raised_or_removed_limit_is_felt_within_a_second |
supervisor/tests/unit/track.rs |
Pacing, MAX_WAIT |
traffic_moves_off_a_member_that_stops_answering |
app/tests/integration/e2e_balancer.rs |
Probe interval and timeout, end to end |
one_association_routes_each_peer_separately, replies_from_several_peers_merge_back_correctly |
app/tests/integration/e2e_udp_route.rs |
The UDP fan-out |
At this revision, these limits have no test that names them: WORK_BUDGET, MAX_SUBS eviction, MAX_LIVE_CONNECTIONS_PER_INBOUND, MAX_HANDSHAKES_PER_INBOUND, PROXY_HEADER_TIMEOUT, the handoff RECEIVE_TIMEOUT, TRANSPORT_HANDSHAKE_TIMEOUT, the TCP keepalive schedule, WS_KEEPALIVE_INTERVAL and WS_IDLE_TIMEOUT, downlink_overhead, the WireGuard RECV_BATCH, the delay test’s MAX_HEAD and the REST API’s DEFAULT_DELAY_TIMEOUT and MAX_DELAY_TIMEOUT, and the client-side Hysteria limits (OPEN_STREAM_TIMEOUT, MAX_UDP_SESSIONS, UDP_SESSION_BACKLOG).
Changing a limit
Section titled “Changing a limit”-
Find every value derived from it. Search for the constant’s name. Reserves are often computed from other constants (
downlink_overhead(Self::BUF_SIZE),REQUEST_HEADER_MAX,AddressCodec::MAX_LEN), so raising a core’sBUF_SIZEcan raise its own reserve. -
Keep the reserve below the buffer.
BUF_SIZEmust stay larger thanSTAGING_RESERVE, or the runtime panics when it is built. For a datagram core, also check thatBUF_SIZE - STAGING_RESERVEis at leastMAX_DATAGRAM. Otherwisedatagram_limit()quietly shrinks and packets are truncated. -
Size a core’s
BUF_SIZEto its largest whole frame. A frame the core must see whole (an HTTP head, a Shadowsocks chunk or record, a UDP frame behind its length) has to fit inBUF_SIZE, or the connection ends withFrameTooLarge. Size a client buffer to the largest wire frame its codec opens, plus the codec’s reserve. -
Update the memory budget. A server buffer cap adds up to three times the change, a client buffer cap up to twice. Update the tables on this page and, for a default an operator can see, the user guide.
-
Pin it with a test. Refer to the constant by name in the test instead of repeating the literal, as
the_cache_stays_bounded_under_distinct_namesdoes withCACHE_CAPACITY. Then run the gates in Testing.