mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-05 08:01:26 +00:00
A plugin outbound can now give a url instead of a path. With the new plugin-fetch feature, a start downloads what the cache is missing into <cache>/<sha256>/<file> before any outbound is built, and points the outbounds at it; a reload, and testing an outbound, resolve from the cache only and refuse what they would have to download. - https only, redirects included, and only together with a sha256 pin. - Downloads go to a temporary file, are hashed as they arrive, and are renamed into place only once the digest matches, under the url's own name, with the platform's library suffix added when it has no extension, which is what Windows needs to load it. A download past the declared size, or past 64 MiB without one, is stopped. - The cache directory comes from FetchOptions or PLUGIN_CACHE_DIR, with no default: whether a directory is safe to load code from is the embedding app's call. - prefetch() reports QUEUED/CACHED for every plugin before any download, then STARTED, PROGRESS (at most every 100 ms) and exactly one DONE or FAILED each, on the calling thread; the callback can cancel. A download that has not finished gets a PROGRESS heartbeat at least once a second, before STARTED too, so that one stuck connecting or in the handshake can be cancelled as well as one stuck mid-body. conf gains a [Plugin] section that declares each plugin once (path, url, sha256, size) and a `plugin` proxy protocol that refers to it by name, with args= or args-b64= for arguments that contain commas. Proxy parameters are now split at the first `=` only, which used to drop any value that contained one. leaf-ffi gains leaf_prefetch_plugins, so that an app can download the plugins as soon as it has the config, and show progress, and the start that follows finds everything in the cache. Events arrive as a LeafFetchEvent whose first field is its size, on the calling thread and never after the call returns. Adds ERR_PLUGIN_FETCH, ERR_CANCELLED and ERR_UNSUPPORTED, and the plugin and plugin-fetch features. It is tested by unit tests rather than end to end: the library is a Rust dylib, which does not link in a Windows debug build (LNK1189). Twenty-three fetch/ e2e cases download from a per-case https server whose routes can announce a wrong length, omit it, fail, redirect, or hold a body at a gate until the case opens it. Every case checks its events against one statement of the progress contract, and every failure, cancel and timeout case checks that the cache is left empty. One checks that testing an outbound reads the cache, including a file put there by hand, and never downloads. The READMEs describe plugins in conf files and downloading them, and plugin-test and CI run the new unit tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.6 KiB
Makefile
68 lines
2.6 KiB
Makefile
.PHONY: cli cli-dev test e2e soak plugin-test plugin-test-san proto-gen
|
|
|
|
CFG_COMMIT_HASH := $(shell git rev-parse HEAD | cut -c 1-7)
|
|
export CFG_COMMIT_HASH := $(CFG_COMMIT_HASH)
|
|
CFG_COMMIT_DATE := $(shell git log --format="%ci" -n 1)
|
|
export CFG_COMMIT_DATE := $(CFG_COMMIT_DATE)
|
|
|
|
cli:
|
|
cargo build -p leaf-cli --release
|
|
|
|
cli-dev:
|
|
cargo build -p leaf-cli
|
|
|
|
test:
|
|
cargo test -p leaf -- --nocapture
|
|
|
|
# End-to-end plugin tests. Builds the plugins it needs on its own; pass
|
|
# arguments through, e.g. `make e2e E2E_ARGS="--tag go"`.
|
|
#
|
|
# The soak lane is left out: it is minutes per case and answers a question
|
|
# about the long run, which is `make soak` below.
|
|
e2e:
|
|
cargo test -p leaf-e2e --test e2e -- --strict --no-tag soak $(E2E_ARGS)
|
|
|
|
# The long lane: soaks and every cost meter, including the two that are too
|
|
# slow for a pull request. Each meter leaves its numbers in
|
|
# `target/<profile>/e2e-artifacts/<case>/meters.json`.
|
|
soak:
|
|
cargo test -p leaf-e2e --test e2e -- --strict --tag soak --tag perf $(E2E_ARGS)
|
|
|
|
# Everything plugin-related that is not an end-to-end run: the host's own tests
|
|
# for the loader and the wrappers, and each plugin's unit tests, one language at
|
|
# a time. These cover what an end-to-end run cannot reach: a descriptor that
|
|
# lies about its size, a handshake arriving a byte at a time, every way a server
|
|
# can refuse, and the buffer bookkeeping under all of it.
|
|
CC ?= cc
|
|
ABI_INCLUDE := leaf-plugin-abi/include
|
|
|
|
plugin-test:
|
|
cargo test -p leaf --features plugin --lib
|
|
cargo test -p leaf --features plugin-fetch --lib
|
|
cargo test -p leaf-ffi --lib --features plugin-fetch
|
|
cargo test -p leaf-plugin-abi
|
|
cargo test -p tls-cabi-rs -p shadowsocks-cabi-rs
|
|
cd leaf-plugins/leaf-abi-go && go test -race ./...
|
|
cd leaf-plugins/tls-cabi-go && go test ./...
|
|
cd leaf-plugins/trojan-cabi-go && go test ./...
|
|
mkdir -p target
|
|
$(CC) -std=c11 -O1 -g -Wall -Wextra -Werror -fstack-protector-strong \
|
|
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -I$(ABI_INCLUDE) \
|
|
-o target/socks5_cabi_c_test leaf-plugins/socks5-cabi-c/socks5_test.c
|
|
./target/socks5_cabi_c_test
|
|
cd leaf-plugins/socks5-cabi-zig && zig build test
|
|
|
|
# The C plugin's own tests under the sanitizers. Kept separate from
|
|
# `plugin-test` because not every toolchain ships the runtimes, and this is the
|
|
# lane that answers the question `-Wall` cannot: what the parser does with a
|
|
# server that lies about its lengths.
|
|
plugin-test-san:
|
|
mkdir -p target
|
|
$(CC) -std=c11 -O1 -g -Wall -Wextra -Werror -fsanitize=address,undefined \
|
|
-fno-omit-frame-pointer -I$(ABI_INCLUDE) \
|
|
-o target/socks5_cabi_c_test_san leaf-plugins/socks5-cabi-c/socks5_test.c
|
|
./target/socks5_cabi_c_test_san
|
|
|
|
proto-gen:
|
|
./scripts/regenerate_proto_files.sh
|