Commit Graph
2 Commits
Author SHA1 Message Date
eric 1cf7f109b3 fix(plugin): drop a datagram the engine refuses, not the session
On an unreliable transport, a decode_packet failure ended the receive
side of the session, which leaf then removed. Every reference plugin
reports a reply it rejects -- failed authentication, an address it cannot
parse -- with PLUGIN_FAILURE, and a reply that fails authentication needs
no key. So one forged packet sent to the client's socket discarded every
reply that arrived before the client next sent something.

A frame the engine refuses with PLUGIN_FAILURE on an unreliable
transport is now dropped like any other damaged packet. Any other status
-- an argument the engine cannot use, an unsupported call, an output it
still cannot fit -- says the engine itself cannot go on, and still ends
the session. So does any failure on a reliable transport, since the
stream cannot be resynchronised, and an engine that breaks the ABI's
contract. The ABI documents the exception.

The e2e case now keeps one association, sends a good reply straight behind
each bad one, and adds a forged reply. It fails on the old host.
2026-12-04 09:55:40 +08:00
eric 97ea9fabd2 feat(plugin-abi): declare the C ABI that a host and its plugins share
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.
2026-12-03 19:31:53 +08:00