A new interop lane puts a real leaf with each plugin in front of the servers
people deploy, built from source at pinned revisions: anytls-go, sing-box
stable and its testing branch, mihomo, and the original shadow-tls. Every
pair runs the stream behaviours, plus the server's padding scheme checked on
the wire, fingerprints, and the connections that must fail: wrong password,
hijacked to the real site, TLS 1.2 site in strict mode.
AnyTLS skips half-close-tail, which its protocol cannot carry. ShadowTLS
marks it a known defect: the host shuts the socket's write side while an
engine is still handshaking.
`make interop` runs the lane, `make e2e` leaves it out, and CI runs it in a
job of its own with the built servers cached. The harness no longer hands
out a port twice in one process, and builds upstream Rust servers with their
own toolchain, outside the workspace.
`leaf-e2e` starts real leaf instances and drives them from the outside over
SOCKS5, so a case covers the path a deployment takes -- config parsing, plugin
loading, routing, the dispatcher, the C ABI data plane -- and nothing reaches
into leaf to build a handler by hand. Cases are values rather than `#[test]`
functions, so the suite is a matrix of implementation, protocol, transport and
behaviour instead of a wall of copies, and each runs in its own process, free
to crash, hang, or set load-time environment.
The lanes:
- `differential` runs a behaviour natively and again with a plugin substituted
for one stage, and requires the two to agree. The server is stock leaf, so
these are interoperability tests. `protocols`, `halfclose` and `teardown`
extend that across every stack, relay and selector, the end of a request on
each transport, and shutdown.
- `abi`, `loader` and `coexist` check what the host accepts, refuses, and can
load at once, through a real `dlopen`.
- `hostile` and `datagram` drive conformance plugins -- one in Rust, one in Go
-- that misbehave on request, exercising the host's bounds checks, clamps,
buffer growth and `decode_packet` handling.
- `stress` and the meters measure both sides back to back and assert the ratio,
since absolute numbers from a shared runner say little; throughput, latency,
setup cost and cpu cost land in `meters.json` beside the case logs. What the
process is holding is asserted directly instead, against the case's own
allocator, because what matters there is that it stopped growing.
- `blackbox` runs the shipped binary: on a config file, and on a plugin
library through `--verify-plugin`, whose report has to agree with what the
loader itself would do.
Plugins are built by the harness, and a case whose toolchain is missing is
reported as ignored with the reason; `--strict`, which CI passes, makes that a
failure, so the suite cannot go green by running nothing. The suite runs on
Windows too, where a pause is never shorter than 16ms and cases that dribble
bytes bound their pauses instead.
Two reference plugins on the C ABI, and the first users of the contract.
shadowsocks-cabi-rs is the sample the in-process API used to carry, rewritten
as a stream engine: AEAD ciphers, the SOCKS address codec, and the request
header written when the engine is created rather than on the first push, so a
connection that sends nothing still reaches the far end. The wire header stays
out of the address buffer it is derived from.
tls-cabi-rs wraps rustls as a stream engine, and depends on nothing from leaf,
so the cdylib carries no second copy of the proxy engine.
Both catch a panic at the boundary and report it as an error. A panic that
crosses the ABI is undefined behaviour, and a plugin that faults its host is
worse than one that fails.
The old API handed dynamic libraries Rust trait objects, tying every plugin to
leaf's exact compiler and crate versions and ruling out other languages. It is
removed, along with its shadowsocks sample, which returns on the new ABI in a
later commit.
The host loads plugins over leaf-plugin-abi instead. It validates the
descriptor, dials the endpoint, and drives the engines as sans-io codecs over
its own transport, exposing them as ordinary outbound handlers. Datagram
engines are either unreliable, with a UDP socket of their own, or reliable,
framed over the stream transport. Plugin failures carry the plugin's last error
string, and plugin logs join the session's tracing span.
Everything crossing the boundary is treated as untrusted: counts are checked
against the buffers they describe, reported strings are bounded and escaped,
engines get an opaque id rather than a pointer for host_ctx, and an engine that
takes no input is backpressure rather than failure. A poll does a bounded
amount of work, and a datagram the receiver cannot take is dropped instead of
the session.
An outbound names its path, host and port, and may pin the sha256 of the
library it loads -- the only check on this path that still holds against
someone who can write the file.
`leaf --verify-plugin <path>` runs the same checks without a config file and
prints what the plugin declares: its ABI version, its engines, whether the
outbound must carry host and port, and the digest to pin it to. A build can
then be vetted before it is in the path of any traffic.
Plugins are dynamic libraries, and the boundary between them and leaf has
to be something both sides can name without agreeing on a compiler. This
crate is that boundary and nothing else: dependency-free, no_std, every
repr(C) type and constant in one place, with include/leaf_plugin_abi.h as
the single C declaration for plugins that are not written in Rust.
A plugin exports a descriptor naming its ABI version, its struct sizes,
optional stream and datagram engines, and whether it embeds a language
runtime. abi_major must match exactly; abi_minor is informational and
never gates loading. Each struct freezes a REQUIRED_SIZE prefix for its
major version, and peers validate against that rather than their own
sizeof, so an old plugin runs on a newer host and the reverse.
The contract is written next to the declarations, because the parts that
matter are the ones a signature cannot state: what each object's lifetime
is, that instances move between threads and calls never overlap, that no
call may block -- the readiness callback is what makes that workable --
and that decode_packet reports how much input it consumed, which is the
only way a codec can be driven over a transport with no message
boundaries.
A parity test compiles a C probe and compares sizeof, offsetof and every
constant against the Rust definitions, so the two declarations cannot
drift unnoticed.