eric b83e44ec9f refactor(chain): work out what each actor does before running any of it
A chain has to answer three questions about every actor -- which of its two
handlers runs, what address it is told to reach, and which actor the caller
should dial before any of it starts -- and it answered them in the middle of
doing the I/O. `next_connect_addr` served two of those questions at once with
subtly different rules on the stream and datagram sides, recomputed per actor
per connection; the datagram fold then made the same decisions again in five
branches with a lookahead. Nothing said that actor zero is the one nearest the
wire, or why only the last one is shown the client's stream.

The rules now live in `outbound/plan.rs` as a function from actors to stages:
one backward pass for what each suffix names, one forward fold for which
handler each actor runs. It touches no sockets, so the seven tests under it
are the first statement anywhere of what a chain is supposed to do -- that a
transport leaves the address to what is inside it, that every actor but the
last is told to reach the next hop, that a datagram stays a stream until the
actor that tunnels it. The handlers are left with the I/O and with naming the
actor in any error, which they never did.

Inbound had the same fold written four times -- two handlers and two functions
for the actors behind a multiplexed transport -- agreeing on the interesting
parts and differing in the rest: one panicked with `unimplemented!()` where
another returned, one timed out each actor and the others did not. One fold
now, and the case that used to panic ends the chain instead.

Behaviour is unchanged with two exceptions, both where the old code was
indefensible: a datagram handed to an actor that speaks only streams was
silently dropped and reported as that actor being handed nothing, and is now
an error naming it; and the datagram lookahead asked about the wrong suffix
for every actor after the first, which no configuration here reaches but which
was wrong on its own terms.

Verified against 178 end-to-end cases that put traffic through chains -- every
stack, every relay shape, quic and amux and ws among them -- plus leaf's own
suite.
2026-09-09 22:58:32 +08:00
2026-05-28 15:44:46 +08:00
2026-03-19 07:17:33 +08:00
2026-03-13 16:58:55 +08:00
2026-03-13 16:58:55 +08:00
2026-01-01 21:24:55 +08:00
2026-03-14 10:31:18 +08:00
2026-01-06 10:28:26 +08:00
2026-03-14 10:05:51 +08:00
2020-10-10 18:49:55 +08:00
2024-05-01 23:59:44 +08:00
2026-05-28 15:44:46 +08:00

Leaf Logo

Leaf

A versatile and efficient proxy framework.

Supported Protocols

Proxy Protocols

Protocol Inbound Outbound
HTTP ✅ ❌
SOCKS5 ✅ ✅
Shadowsocks ✅ ✅
Trojan ✅ ✅
VMess ❌ ✅
Vless ❌ ✅

Transports & Security

Transport Inbound Outbound Notes
WebSocket ✅ ✅
TLS ✅ ✅
QUIC ✅ ✅
AMux ✅ ✅ Leaf specific multiplexing
Obfs ❌ ✅ Simple obfuscation
Reality ❌ ✅ Xray Reality
MPTP ✅ ✅ Multi-path Transport Protocol (Aggregation) (Architecture, Usage)

Traffic Control

Feature Inbound Outbound Notes
Chain ✅ ✅ Proxy chaining
Failover ❌ ✅ Failover with health check

Transparent Proxying

Mechanism Inbound Outbound Notes
TUN ✅ ❌ Linux, macOS, Windows, iOS, Android; lwip, smoltcp
NF ✅ ❌ Windows, NetFilter SDK
TPROXY ❌ ❌ Linux; Coming soon

Building

cargo build -p leaf-cli --release
./target/debug/leaf --help

License

This project is licensed under the Apache License 2.0.

S
Description
A versatile and efficient proxy framework.
Readme Apache-2.0
4.5 MiB
0 Stars 1 Watchers 0 Forks
Languages
Rust 99.5%
Shell 0.5%