mirror of
https://github.com/daeuniverse/honk.git
synced 2026-12-06 00:01:26 +00:00
feat(native-ui): embed doona lite as ui embedded-lite (#363)
This commit is contained in:
27 files changed
+331
-272
No files matched your search
@@ -8,7 +8,7 @@ The proxy engine (library `honk_core` + `honk-core` binary). Cargo features:
|
||||
- `ebpf` — aya real backend + `honk-nfqueue`, requires Linux kernel 6.12+; otherwise `MockEbpfBackend`. NFQUEUE activation follows `configuration.md`.
|
||||
- `clash-api` — Clash-compatible REST/WS API (pulls in optional axum/tower-http).
|
||||
- `native-api` — independent, opt-in native HTTP observations/control with a default-off listener; build with `--features native-api` (or `native-ui`); the full and `-native-api` release artifacts include it. It can run with mock or real eBPF and without Clash; real-kernel CI enables it for lifecycle regression coverage.
|
||||
- `mimalloc` — shipped binary allocates through mimalloc (see Technology stack in `AGENTS.md`); build with `--no-default-features --features "clash-api,ebpf,rprx,native-ui"` for the release capabilities with stock malloc. `native-ui` embeds the pinned doona build and fails without an absolute `HONK_DOONA_DIR` (`export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`); use `native-api` instead only when embedded hosting (`ui: embedded`) is not needed.
|
||||
- `mimalloc` — shipped binary allocates through mimalloc (see Technology stack in `AGENTS.md`); build with `--no-default-features --features "clash-api,ebpf,rprx,native-ui"` for the release capabilities with stock malloc. `native-ui` embeds both pinned doona editions and requires the absolute standard directory `HONK_DOONA_DIR` plus its `-lite` sibling (`export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`); use `native-api` instead only when embedded hosting (`ui: embedded` or `ui: embedded-lite`, the lighter doona lite preview edition; both need `native-ui`) is not needed.
|
||||
- `rprx` — forwards to `honk-outbound/rprx`: registers VLESS (VLESS Encryption and xtls-rprx-vision) and VMess handlers; without it VLESS/VMess nodes parse fine but fail at dial with "No handler for protocol".
|
||||
|
||||
Score is always compiled, without a Cargo feature; omitted policy selects Selector.
|
||||
|
||||
@@ -8,7 +8,7 @@ Every code pull request runs the userspace routing goldens (`routing::golden::*`
|
||||
|
||||
The `features` lane also runs the outbound `feature_boundary` integration target and the `honk-tool` suite with `cargo test --no-default-features`, each in a separate Cargo invocation so workspace feature unification cannot hide `rprx`-off cases. Exact nonempty test-list checks require both no-backend regressions before execution; this lane uses plain Cargo rather than nextest.
|
||||
|
||||
Workspace lint and nextest explicitly enable `honk-core/native-ui` (which includes `native-api`) so ordinary code CI covers the opt-in native API and embedded UI alongside the default-on Clash API feature; workspace lint also enables `honk-core/udp-bench` so the `udp_io` benchmark and its real-I/O harness stay compiled and linted, and the `features` lane checks that bench with default features off. Both API listeners still require configuration. The independent `features` lane checks native-only, native+Clash and native-ui builds, requires nonempty authentication/coexistence/embedded-UI selections, and executes native-only HTTP regressions, cross-token isolation and embedded-UI HTTP coverage separately. Native-api-only coverage retains embedded-UI rejection. Release allocator variants share explicit `clash-api,ebpf,rprx,native-ui` capabilities (`native-ui` includes `native-api`) and differ only by `mimalloc`. Every job that enables `native-ui` first runs `ci/fetch-doona.sh`, which downloads the doona release pinned in `.github/ci/pins.env`, checks its SHA-256 and exports the directory as `HONK_DOONA_DIR`; the repository vendors no doona files.
|
||||
Workspace lint and nextest explicitly enable `honk-core/native-ui` (which includes `native-api`) so ordinary code CI covers the opt-in native API and embedded UI alongside the default-on Clash API feature; workspace lint also enables `honk-core/udp-bench` so the `udp_io` benchmark and its real-I/O harness stay compiled and linted, and the `features` lane checks that bench with default features off. Both API listeners still require configuration. The independent `features` lane checks native-only, native+Clash and native-ui builds, requires nonempty authentication/coexistence/embedded-UI selections, and executes native-only HTTP regressions, cross-token isolation and embedded-UI HTTP coverage separately. Native-api-only coverage retains embedded-UI rejection. Release allocator variants share explicit `clash-api,ebpf,rprx,native-ui` capabilities (`native-ui` includes `native-api`) and differ only by `mimalloc`. Every job that enables `native-ui` first runs `ci/fetch-doona.sh`, which downloads both doona editions pinned in `.github/ci/pins.env`, checks their SHA-256 values and exports the standard directory as `HONK_DOONA_DIR`; lite is its `-lite` sibling; the repository vendors no doona files.
|
||||
|
||||
The `parser` lane compares config corpus inputs against the pinned dae Go oracle and replays saved fuzz inputs on stable Rust. Its filter covers `honk-config`, `tools/dae-parse`, `fuzz`, corpus source documents and shared build inputs. Dialect-only PRs select parser and docs without selecting workspace code lanes; `ci:full`, failed change detection, pushes and manual CI runs also select parser. Its timeout is eight minutes, and `ci-report-parser` carries conformance/replay counts and the first failing case/path.
|
||||
|
||||
|
||||
+4
-3
@@ -30,6 +30,7 @@ KERNEL_RECENT_MODULES_SHA256=04326490265b87b3ba5d617beea6b61a4322072bbeb0eef0318
|
||||
KERNEL_RECENT_RELEASE=7.2.5-070205-generic
|
||||
|
||||
# doona release embedded by the native-ui feature; ci/fetch-doona.sh reads it.
|
||||
DOONA_VERSION=0.1.0-rc.1
|
||||
DOONA_REVISION=f896a2176460daa0997497cd964d84c697e717b2
|
||||
DOONA_SHA256=0e3c36d7c9173a5c31c704671def610ca7e6d8e7b00ceda1d7d32e564c85a5e3
|
||||
DOONA_VERSION=0.1.0-rc.3
|
||||
DOONA_REVISION=931be7f19c481c8d2ce01509faa0f9050ce175bb
|
||||
DOONA_SHA256=24fe93a94439ff4865db284a98d3498e671b158db25e8ab2e688d40f608d5b32
|
||||
DOONA_LITE_SHA256=ce353aec71638cf128b1282e4312b5ea3e33454234066ef7730f652643984dad
|
||||
@@ -11,7 +11,7 @@ for path in "$dist"/*.tar.gz; do
|
||||
file=${path##*/}
|
||||
case $file in
|
||||
honk-core-*) ;;
|
||||
doona-source-*) others+=("| \`$file\` | Corresponding source of the embedded doona UI (GPL-3.0 section 6) |"); continue ;;
|
||||
doona-source-*) others+=("| \`$file\` | Corresponding source of both embedded doona UI editions (GPL-3.0 section 6) |"); continue ;;
|
||||
*) printf '::error::Unknown release archive: %s\n' "$file" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
@@ -43,7 +43,7 @@ cat <<'EOF'
|
||||
Each build is named `{allocator}-{API}-{arch}-{libc}`:
|
||||
|
||||
- `mimalloc` favours throughput; `stockalloc` uses the system allocator and keeps the memory peak lower on small devices.
|
||||
- `fullapi` has the Clash API, the native API and the embedded doona UI; `clashapi` has the Clash API only; `nativeapi` has the native API only, without the UI.
|
||||
- `fullapi` has the Clash API, the native API and both embedded doona UI editions; `ui: embedded-lite` selects the lighter doona lite edition (preview). `clashapi` has the Clash API only; `nativeapi` has the native API only, without the UI.
|
||||
- `musl` builds are static and suit gateways.
|
||||
|
||||
Check a download with `sha256sum -c --ignore-missing SHA256SUMS`, and its origin with `gh attestation verify <file> -R daeuniverse/honk`.
|
||||
|
||||
@@ -23,7 +23,6 @@ expect_line() {
|
||||
expect_line '| `honk-core-v1.2.3-x86_64-unknown-linux-gnu-full.tar.gz` | `mimalloc-fullapi-x86_64-gnu` |'
|
||||
expect_line '| `honk-core-v1.2.3-aarch64-unknown-linux-musl-stock-native-api.tar.gz` | `stockalloc-nativeapi-aarch64-musl` |'
|
||||
expect_line '| `honk-core-debug-x86_64-unknown-linux-musl-clash-api.tar.gz` | `mimalloc-clashapi-x86_64-musl` |'
|
||||
expect_line '| `doona-source-0.1.0.tar.gz` | Corresponding source of the embedded doona UI (GPL-3.0 section 6) |'
|
||||
|
||||
# A name the table cannot classify fails the release instead of shipping an unexplained file.
|
||||
touch "$work/dist/honk-core-v1.2.3-riscv64-unknown-linux-musl-full.tar.gz"
|
||||
|
||||
@@ -262,17 +262,19 @@ jobs:
|
||||
mkdir -p "dist/$name"
|
||||
cp "target/${{ matrix.target }}/release/honk-core" "dist/$name/"
|
||||
cp LICENSE README.md "dist/$name/"
|
||||
# The embedded doona UI keeps its notices and the licences of the icons
|
||||
# and fonts it bundles; lean variants do not embed it and carry no doona
|
||||
# directory. Both projects are GPL-3.0-only, so the top-level LICENSE
|
||||
# covers doona too, and the build stops if doona's text ever differs.
|
||||
# Both editions keep their own notices. Their GPL-3.0-only license must
|
||||
# match the top-level LICENSE; lean variants embed neither edition.
|
||||
if [[ "${{ matrix.variant }}" == full ]]; then
|
||||
if ! cmp -s LICENSE "$HONK_DOONA_DIR/LICENSE"; then
|
||||
echo "::error::doona's LICENSE differs from honk's; ship it under doona/ again"
|
||||
exit 1
|
||||
fi
|
||||
mkdir "dist/$name/doona"
|
||||
cp -r "$HONK_DOONA_DIR"/{LICENSES,NOTICE,THIRD-PARTY-NOTICES.txt} "dist/$name/doona/"
|
||||
for edition in doona doona-lite; do
|
||||
ui_dir="$HONK_DOONA_DIR"
|
||||
[[ "$edition" != doona-lite ]] || ui_dir="${HONK_DOONA_DIR%/}-lite"
|
||||
if ! cmp -s LICENSE "$ui_dir/LICENSE"; then
|
||||
echo "::error::$edition's LICENSE differs from honk's; ship it under $edition/ again"
|
||||
exit 1
|
||||
fi
|
||||
mkdir "dist/$name/$edition"
|
||||
cp -r "$ui_dir"/{LICENSES,NOTICE,THIRD-PARTY-NOTICES.txt} "dist/$name/$edition/"
|
||||
done
|
||||
fi
|
||||
tar -czf "$name.tar.gz" -C dist "$name"
|
||||
|
||||
@@ -326,8 +328,7 @@ jobs:
|
||||
bash release-source/.github/ci/check-release-artifacts.sh "$GITHUB_REF_NAME"
|
||||
fi
|
||||
|
||||
# GPL-3.0 section 6: the binaries embed doona, so its corresponding
|
||||
# source is published next to them.
|
||||
# GPL-3.0 section 6: both embedded editions share this corresponding source.
|
||||
- name: Add doona corresponding source
|
||||
run: bash release-source/ci/fetch-doona.sh --source dist
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ Notable absences (referenced by older docs but **not in this tree**): `Makefile`
|
||||
Clash `/logs` (`clash_api/logs.rs`) skips formatting without subscribers; its unfiltered tracing layer would otherwise allocate a `String` per sub-level datapath event. Default logs silence `quinn::endpoint` (`logging.rs::QUIET_TARGET`): its driver-death ERROR accompanies carrier loss under probe/warm transports (e.g. SYNACK-watchdog kills) and duplicates the failure honk reports with its own context, so it is lifecycle noise. A completed nonzero-timeout packet-backed endpoint close stops Quinn drivers before adapter workers and emits none; zero-timeout close and parent-owner teardown keep their existing order. Valid `RUST_LOG` overrides console/file filtering until a native `log.level` PATCH, which the next activation reverts; Clash `/logs` and native `/api/v1/logs` always exclude this target.
|
||||
- **eBPF:** userspace [aya](https://github.com/aya-rs/aya) 0.14 (optional `ebpf` feature in `honk-core`); kernel side `aya-ebpf` 0.2 targeting `bpfel-unknown-none` (nightly + `-Zbuild-std=core` + `bpf-linker`).
|
||||
- **NFQUEUE:** `honk-nfqueue` uses raw `NETLINK_NETFILTER` for one fixed queue and its nftables transaction; no libnetfilter_queue/libmnl/libnftnl or firewall subprocess.
|
||||
- **HTTP APIs:** axum 0.8 + tower-http 0.7. Default-on `clash-api` enables WebSockets; independent opt-in `native-api` (build with `--features native-api` or `native-ui`; release builds include it) owns Hyper HTTP/1.1 and observation, config, probe, DNS, lifecycle and source-owned management, with its listener disabled until configured. Native limits: 64 connections overall, [16 per peer IP](doc/en/reference/api.md#native-api), 5s headers, 30s read-idle deadline only while no request is in flight (end of body until response resolves), 30s stalled-write deadline, 5s joined HTTP shutdown; one 1s sampler. Accept errors log and retry (100ms backoff on EMFILE/ENFILE/ENOBUFS/ENOMEM); a failed connection task is logged, not fatal. Flow recorder 1024/64 steps/8 MiB including snapshots, terminal 300s, evicting the oldest ended record before any live one; flow snapshots 8/30s. Node snapshots 8/30s/4 MiB. SSE 512 events/60s/16 clients/64 queue/15s heartbeat; events and logs both resume ready → replay → live. Native catalog group IDs are process-stable; config group UUIDs and `created_at` survive same-name reload, not rename. Per-network Selector and automatic-policy pin/clear, source-owned Group PATCH, synchronous main-source node/provider create/delete and verified-geodata operations are enabled; native runtime_mode and full kernel transparency remain gated. Default-off `native-ui` embeds pinned real doona assets without fonts: packaging obtains the distribution pinned in `.github/ci/pins.env` through `ci/fetch-doona.sh`, and `build.rs` embeds `HONK_DOONA_DIR`, including its notices; no vendored asset tree or runtime fetch. `alive/observations.rs` retains qualified actual probe facts independently of legacy routing liveness; never infer fresh native health from restored/synthetic/derived collections. Config/auth: `.agents/rules/configuration.md`, `.agents/rules/security.md`.
|
||||
- **HTTP APIs:** axum 0.8 + tower-http 0.7. Default-on `clash-api` enables WebSockets; independent opt-in `native-api` (build with `--features native-api` or `native-ui`; release builds include it) owns Hyper HTTP/1.1 and observation, config, probe, DNS, lifecycle and source-owned management, with its listener disabled until configured. Native limits: 64 connections overall, [16 per peer IP](doc/en/reference/api.md#native-api), 5s headers, 30s read-idle deadline only while no request is in flight (end of body until response resolves), 30s stalled-write deadline, 5s joined HTTP shutdown; one 1s sampler. Accept errors log and retry (100ms backoff on EMFILE/ENFILE/ENOBUFS/ENOMEM); a failed connection task is logged, not fatal. Flow recorder 1024/64 steps/8 MiB including snapshots, terminal 300s, evicting the oldest ended record before any live one; flow snapshots 8/30s. Node snapshots 8/30s/4 MiB. SSE 512 events/60s/16 clients/64 queue/15s heartbeat; events and logs both resume ready → replay → live. Native catalog group IDs are process-stable; config group UUIDs and `created_at` survive same-name reload, not rename. Per-network Selector and automatic-policy pin/clear, source-owned Group PATCH, synchronous main-source node/provider create/delete and verified-geodata operations are enabled; native runtime_mode and full kernel transparency remain gated. Default-off `native-ui` embeds pinned real doona standard and lite assets without fonts: packaging obtains both distributions pinned in `.github/ci/pins.env` through `ci/fetch-doona.sh`, and `build.rs` embeds `HONK_DOONA_DIR` and its `-lite` sibling, including each edition's notices; no vendored asset tree or runtime fetch. `alive/observations.rs` retains qualified actual probe facts independently of legacy routing liveness; never infer fresh native health from restored/synthetic/derived collections. Config/auth: `.agents/rules/configuration.md`, `.agents/rules/security.md`.
|
||||
`native_api/server.rs` owns HTTP/sampler shutdown; `auth.rs` owns one tracked blocking credential job and sessions, with storage/request children. Close auth admission before the five-second HTTP grace, then join real KDF/SQLite work even after request cancellation. Signed ready checkpoints remain distinct from evicted event cursors. Catalog snapshots, DNS responses and DNS log pages mask listener-secret display values before bounded serialization, without changing IDs or cursor bindings.
|
||||
- **QUIC:** quinn 0.11 (TUIC/Juicity/Hysteria2 outbounds, DoQ/DoH3 DNS); congestion `bbr` builds the fork's BBRv3 or quinn's original BBR per `HONK_QUIC_BBR` (`quic.rs::congestion_factory`), and Brutal drives the fork's rate pacer through `pacer_rate`; `h3`/`h3-quinn` for DoH3 only — Hysteria2 ships its own minimal HTTP/3+QPACK layer. Core opts into h3's third-party-backend error visibility so DNS can distinguish typed endpoint loss from deterministic H3 response errors without parsing text. Keep that version-sensitive inspection private in `dns/transport/quic.rs`; upgrades must retain its failure-scope regression.
|
||||
- **TLS:** [boring](https://github.com/cloudflare/boring) 5.2.0 + tokio-boring 5.2.0 for proxy/DNS TCP TLS and QUIC via custom `quinn_proto::crypto` in `honk-outbound/src/quic/boring.rs`; webpki-root-certs CA roots. rustls supplies loopback wire interop tests and preserves the existing platform-verifier policy for HTTP downloads only. boring-sys builds BoringSSL from source with `cmake`, C compiler, `libclang` (bindgen). Pin all three Boring crates to 5.2.0; patch boring-sys to `https://github.com/Glassyiris/boring-sys`, revision `3beb573b65ecaa69b7eefe3c2fecd074b97facd2`, branch `boring-sys-5.2`. The fork adds REALITY-required `SSL_set1_client_x25519_private_key` and `SSL_set_client_hello_fixup_cb`. Rebase it before upgrading the stack.
|
||||
|
||||
@@ -35,7 +35,7 @@ The [documentation index](doc/README.md) links all bilingual guides, references,
|
||||
|
||||
## Opt-in native observation API
|
||||
|
||||
Build with `--features native-api` (the full and `-native-api` release artifacts include it) and configure `experimental.native_api` for independent observations and controls on `127.0.0.1:9527`: bounded flows/logs/DNS history, probes, provider status/refresh, per-network Selector control and exact connection closure. Captured `.dae` sources remain authoritative, with opt-in source/Group PATCH transactions, synchronous main-file node/provider creation and removal, and verified-geodata operations; existing entries are edited through source PUT. `--store db` records accepted sources as revisions in a state database instead. A bearer secret or password login is required unless anonymous loopback is explicitly enabled. Serve a trusted directory, or build `--features native-ui` and set `ui: embedded` for the pinned doona build without runtime downloads. Native runtime_mode and full kernel transparency remain unavailable. See [native settings](doc/en/reference/experimental.md#native_api) and the [API contract](doc/en/reference/api.md#native-api).
|
||||
Build with `--features native-api` (the full and `-native-api` release artifacts include it) and configure `experimental.native_api` for independent observations and controls on `127.0.0.1:9527`: bounded flows/logs/DNS history, probes, provider status/refresh, per-network Selector control and exact connection closure. Captured `.dae` sources remain authoritative, with opt-in source/Group PATCH transactions, synchronous main-file node/provider creation and removal, and verified-geodata operations; existing entries are edited through source PUT. `--store db` records accepted sources as revisions in a state database instead. A bearer secret or password login is required unless anonymous loopback is explicitly enabled. Serve a trusted directory, or build `--features native-ui` and set `ui: embedded` for the pinned doona build without runtime downloads. `ui: embedded-lite` selects the lighter doona lite edition (preview), with the same `native-ui` requirement. Native runtime_mode and full kernel transparency remain unavailable. See [native settings](doc/en/reference/experimental.md#native_api) and the [API contract](doc/en/reference/api.md#native-api).
|
||||
|
||||
The web interface for the native API is [doona](https://github.com/Zakkaus/doona) ([documentation](https://doona.daeuniverse.org/en/), [demo](https://demo.daeuniverse.org/)); doona lite is a lighter preview edition.
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ honk 是用 Rust 编写的实验性 Linux 透明代理引擎。其 eBPF 数据
|
||||
|
||||
## 可选原生观测 API
|
||||
|
||||
以 `--features native-api` 构建(full 与 `-native-api` 发布产物已包含)并配置 `experimental.native_api`,可在 `127.0.0.1:9527` 独立观测用户态连接与记录流、节点与组健康、出站计数、RSS/cgroup、历史、事件、结构化安全日志、DNS 与 provider 状态。支持有界探测、路由模拟、精确连接关闭与缓存失效、provider refresh、分网络 Selector 控制与临时设置。除显式启用的匿名 loopback 访问外,均要求 bearer secret 或密码登录。可托管可信目录,或以 `--features native-ui` 和 `ui: embedded` 使用固定版本的 doona,运行时不下载 UI。
|
||||
以 `--features native-api` 构建(full 与 `-native-api` 发布产物已包含)并配置 `experimental.native_api`,可在 `127.0.0.1:9527` 独立观测用户态连接与记录流、节点与组健康、出站计数、RSS/cgroup、历史、事件、结构化安全日志、DNS 与 provider 状态。支持有界探测、路由模拟、精确连接关闭与缓存失效、provider refresh、分网络 Selector 控制与临时设置。除显式启用的匿名 loopback 访问外,均要求 bearer secret 或密码登录。可托管可信目录,或以 `--features native-ui` 和 `ui: embedded` 使用固定版本的 doona,运行时不下载 UI。`ui: embedded-lite` 选择更轻量的 doona lite 预览版,同样需要 `native-ui`。
|
||||
|
||||
`.dae` 仍是唯一配置权威。启动时捕获的源支持元数据读取、离线校验、授权源 PUT 和受限组 PATCH。主文件节点/provider 的创建与删除在实际激活后才返回成功,geodata 更新 operation 激活已验证的内容。编辑已有条目继续使用源 PUT;`--store db` 将已接受的源记录为状态数据库中的 revision。凭据源只读,返回正文时遮蔽 listener secret 值。启用原生 API 时,与 Clash 共用非持久化模式;成功的显式激活(含 no-op)重置 Rule 与设置,provider/network refresh 保留它们。原生 runtime mode、暂停/恢复与完整内核 flow 观测仍未开放。详见[原生 API 参考](doc/zh/reference/api.md#原生-api)。
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Added
|
||||
|
||||
- `ui: 'embedded-lite'` serves doona lite from the binary, and full builds embed doona 0.1.0-rc.3 with both editions.
|
||||
+28
-22
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fetch the doona release pinned in .github/ci/pins.env for the native-ui feature.
|
||||
#
|
||||
# ci/fetch-doona.sh [DIR] extract the program files into DIR (default
|
||||
# target/doona-<version>) and print its absolute
|
||||
# path, for HONK_DOONA_DIR
|
||||
# ci/fetch-doona.sh [DIR] extract standard into DIR (default
|
||||
# target/doona-<version>), lite into DIR-lite;
|
||||
# print only the absolute standard path for HONK_DOONA_DIR
|
||||
# ci/fetch-doona.sh --source OUTDIR write OUTDIR/doona-source-<version>.tar.gz,
|
||||
# the corresponding source of that release
|
||||
# the corresponding source of both editions
|
||||
set -euo pipefail
|
||||
|
||||
root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
@@ -32,24 +32,30 @@ if [[ "${1:-}" == "--source" ]]; then
|
||||
fi
|
||||
|
||||
dir=${1:-$root/target/doona-$DOONA_VERSION}
|
||||
curl -fsSL --retry 3 -o "$tmp/doona.tar.gz" \
|
||||
"$repo/releases/download/v$DOONA_VERSION/doona-$DOONA_VERSION.tar.gz"
|
||||
echo "$DOONA_SHA256 $tmp/doona.tar.gz" | sha256sum -c --quiet -
|
||||
mkdir "$tmp/doona"
|
||||
tar -xzf "$tmp/doona.tar.gz" -C "$tmp/doona"
|
||||
# Fonts ship in the separate doona-fonts package and are not embedded.
|
||||
rm -rf "$tmp/doona/fonts"
|
||||
# The embedded UI and each release tarball must carry every notice it needs.
|
||||
missing=()
|
||||
for file in LICENSE NOTICE THIRD-PARTY-NOTICES.txt \
|
||||
$(grep -o 'LICENSES/[A-Za-z0-9.+-]*\.txt' "$tmp/doona/NOTICE" 2>/dev/null | sort -u); do
|
||||
[[ -f "$tmp/doona/$file" ]] || missing+=("$file")
|
||||
dir=$(realpath -m "$dir")
|
||||
for edition in doona doona-lite; do
|
||||
checksum=$DOONA_SHA256
|
||||
[[ "$edition" != doona-lite ]] || checksum=$DOONA_LITE_SHA256
|
||||
curl -fsSL --retry 3 -o "$tmp/$edition.tar.gz" \
|
||||
"$repo/releases/download/v$DOONA_VERSION/$edition-$DOONA_VERSION.tar.gz"
|
||||
echo "$checksum $tmp/$edition.tar.gz" | sha256sum -c --quiet -
|
||||
mkdir "$tmp/$edition"
|
||||
tar -xzf "$tmp/$edition.tar.gz" -C "$tmp/$edition"
|
||||
# Fonts ship in the separate doona-fonts package and are not embedded.
|
||||
rm -rf "$tmp/$edition/fonts"
|
||||
# Each embedded edition and release tarball must carry every notice it needs.
|
||||
missing=()
|
||||
for file in LICENSE NOTICE THIRD-PARTY-NOTICES.txt \
|
||||
$(grep -o 'LICENSES/[A-Za-z0-9.+-]*\.txt' "$tmp/$edition/NOTICE" 2>/dev/null | sort -u); do
|
||||
[[ -f "$tmp/$edition/$file" ]] || missing+=("$file")
|
||||
done
|
||||
if (( ${#missing[@]} )); then
|
||||
echo "$edition $DOONA_VERSION archive lacks required notices: ${missing[*]}" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if (( ${#missing[@]} )); then
|
||||
echo "doona $DOONA_VERSION archive lacks required notices: ${missing[*]}" >&2
|
||||
exit 1
|
||||
fi
|
||||
rm -rf "$dir"
|
||||
mkdir -p "$(dirname "$dir")"
|
||||
rm -rf "$dir" "$dir-lite"
|
||||
mv "$tmp/doona" "$dir"
|
||||
cd "$dir" && pwd
|
||||
mv "$tmp/doona-lite" "$dir-lite"
|
||||
printf '%s\n' "$dir"
|
||||
@@ -120,7 +120,7 @@ ebpf = ["aya", "aya-obj", "aya-log", "dep:honk-nfqueue"]
|
||||
# Enable the Clash-compatible REST API (experimental.clash_api)
|
||||
clash-api = ["dep:axum", "axum/ws", "dep:tower-http", "dep:zip"]
|
||||
native-api = ["dep:axum", "dep:tower", "dep:tower-http", "dep:subtle", "dep:hmac", "dep:serde_path_to_error", "honk-outbound/flow-observation", "honk-outbound/owned-tasks"]
|
||||
# Embed the pinned doona distribution from HONK_DOONA_DIR at build time.
|
||||
# Embed pinned doona from HONK_DOONA_DIR and doona lite from its -lite sibling.
|
||||
native-ui = ["native-api", "dep:brotli", "dep:flate2"]
|
||||
# Route the shipped binary's allocations through mimalloc (see main.rs)
|
||||
mimalloc = ["dep:mimalloc", "dep:libmimalloc-sys"]
|
||||
|
||||
+32
-18
@@ -66,6 +66,29 @@ mod hashed_asset;
|
||||
|
||||
#[cfg(feature = "native-ui")]
|
||||
fn embed_native_ui() -> anyhow::Result<()> {
|
||||
use anyhow::{Context, ensure};
|
||||
|
||||
println!("cargo:rerun-if-env-changed=HONK_DOONA_DIR");
|
||||
let root = std::path::PathBuf::from(std::env::var_os("HONK_DOONA_DIR").context(
|
||||
"the native-ui feature embeds doona and doona lite from HONK_DOONA_DIR and its -lite sibling; \
|
||||
fetch the pinned release with `export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`",
|
||||
)?);
|
||||
ensure!(
|
||||
root.is_absolute(),
|
||||
"HONK_DOONA_DIR must be an absolute path: {}",
|
||||
root.display()
|
||||
);
|
||||
let mut lite_name = root
|
||||
.file_name()
|
||||
.context("HONK_DOONA_DIR must name a directory below its parent")?
|
||||
.to_os_string();
|
||||
lite_name.push("-lite");
|
||||
embed_ui_assets(&root, "native_ui")?;
|
||||
embed_ui_assets(&root.with_file_name(lite_name), "native_ui_lite")
|
||||
}
|
||||
|
||||
#[cfg(feature = "native-ui")]
|
||||
fn embed_ui_assets(root: &std::path::Path, name: &str) -> anyhow::Result<()> {
|
||||
use std::{fmt::Write, fs, path::Path};
|
||||
|
||||
use anyhow::{Context, ensure};
|
||||
@@ -98,32 +121,23 @@ fn embed_native_ui() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-env-changed=HONK_DOONA_DIR");
|
||||
let root = std::path::PathBuf::from(std::env::var_os("HONK_DOONA_DIR").context(
|
||||
"the native-ui feature embeds a doona build from HONK_DOONA_DIR; \
|
||||
fetch the pinned release with `export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`",
|
||||
)?);
|
||||
ensure!(
|
||||
root.is_absolute(),
|
||||
"HONK_DOONA_DIR must be an absolute path: {}",
|
||||
root.display()
|
||||
);
|
||||
println!("cargo:rerun-if-changed={}", root.display());
|
||||
ensure!(
|
||||
fs::symlink_metadata(&root)
|
||||
.with_context(|| format!("failed to inspect HONK_DOONA_DIR {}", root.display()))?
|
||||
fs::symlink_metadata(root)
|
||||
.with_context(|| format!("failed to inspect native UI directory {}", root.display()))?
|
||||
.is_dir(),
|
||||
"HONK_DOONA_DIR must be a directory: {}",
|
||||
"native UI path must be a directory: {}",
|
||||
root.display()
|
||||
);
|
||||
let mut files = Vec::new();
|
||||
collect(&root, &root, &mut files)?;
|
||||
collect(root, root, &mut files)?;
|
||||
files.sort_unstable();
|
||||
ensure!(
|
||||
files
|
||||
.binary_search_by(|path| path.as_str().cmp("index.html"))
|
||||
.is_ok(),
|
||||
"native UI assets must include index.html"
|
||||
"native UI assets must include index.html: {}",
|
||||
root.display()
|
||||
);
|
||||
let unhashed: Vec<_> = files
|
||||
.iter()
|
||||
@@ -136,7 +150,7 @@ fn embed_native_ui() -> anyhow::Result<()> {
|
||||
);
|
||||
|
||||
let out = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
|
||||
let compressed = out.join("native_ui");
|
||||
let compressed = out.join(name);
|
||||
if compressed.exists() {
|
||||
fs::remove_dir_all(&compressed)?;
|
||||
}
|
||||
@@ -182,7 +196,7 @@ fn embed_native_ui() -> anyhow::Result<()> {
|
||||
let file = root.join(path);
|
||||
let file = file
|
||||
.to_str()
|
||||
.context("HONK_DOONA_DIR paths must be UTF-8")?;
|
||||
.context("native UI asset paths must be UTF-8")?;
|
||||
writeln!(
|
||||
generated,
|
||||
" ({path:?}, EmbeddedAsset::Identity(include_bytes!({file:?}))),"
|
||||
@@ -190,7 +204,7 @@ fn embed_native_ui() -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
generated.push_str("]\n");
|
||||
fs::write(out.join("native_ui_assets.rs"), generated)?;
|
||||
fs::write(out.join(format!("{name}_assets.rs")), generated)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -21,18 +21,28 @@ const IMMUTABLE: &str = "public, max-age=31536000, immutable";
|
||||
pub(super) enum Ui {
|
||||
Directory(Box<(ServeDir, ServeFile)>),
|
||||
#[cfg(feature = "native-ui")]
|
||||
Embedded,
|
||||
Embedded(&'static [(&'static str, EmbeddedAsset)]),
|
||||
}
|
||||
|
||||
pub(super) async fn load(path: &str) -> anyhow::Result<Option<Ui>> {
|
||||
if path.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
if path == "embedded" {
|
||||
if matches!(path, "embedded" | "embedded-lite") {
|
||||
#[cfg(feature = "native-ui")]
|
||||
return Ok(Some(Ui::Embedded));
|
||||
{
|
||||
static STANDARD: &[(&str, EmbeddedAsset)] =
|
||||
include!(concat!(env!("OUT_DIR"), "/native_ui_assets.rs"));
|
||||
static LITE: &[(&str, EmbeddedAsset)] =
|
||||
include!(concat!(env!("OUT_DIR"), "/native_ui_lite_assets.rs"));
|
||||
return Ok(Some(Ui::Embedded(if path == "embedded-lite" {
|
||||
LITE
|
||||
} else {
|
||||
STANDARD
|
||||
})));
|
||||
}
|
||||
#[cfg(not(feature = "native-ui"))]
|
||||
anyhow::bail!("embedded native UI requires the native-ui feature");
|
||||
anyhow::bail!("{path} native UI requires the native-ui feature");
|
||||
}
|
||||
|
||||
let root = honk_config::paths::resolve_dependency_path(path);
|
||||
@@ -120,8 +130,9 @@ impl Ui {
|
||||
let (files, index) = match self {
|
||||
Self::Directory(directory) => (&directory.0, &directory.1),
|
||||
#[cfg(feature = "native-ui")]
|
||||
Self::Embedded => {
|
||||
Self::Embedded(files) => {
|
||||
return embedded_response(
|
||||
files,
|
||||
&decoded,
|
||||
navigation,
|
||||
request.method() == Method::HEAD,
|
||||
@@ -227,7 +238,7 @@ fn cache_control(hashed: bool, status: StatusCode) -> &'static str {
|
||||
}
|
||||
|
||||
#[cfg(feature = "native-ui")]
|
||||
enum EmbeddedAsset {
|
||||
pub(super) enum EmbeddedAsset {
|
||||
/// Formats that do not compress, embedded as stored.
|
||||
Identity(&'static [u8]),
|
||||
/// Text embedded only in compressed form; `len` is the decoded size.
|
||||
@@ -298,14 +309,17 @@ fn negotiate(headers: &axum::http::HeaderMap) -> Encoding {
|
||||
}
|
||||
|
||||
#[cfg(feature = "native-ui")]
|
||||
fn embedded_response(path: &str, navigation: bool, head: bool, encoding: Encoding) -> Response {
|
||||
fn embedded_response(
|
||||
files: &'static [(&'static str, EmbeddedAsset)],
|
||||
path: &str,
|
||||
navigation: bool,
|
||||
head: bool,
|
||||
encoding: Encoding,
|
||||
) -> Response {
|
||||
use std::io::Read;
|
||||
|
||||
static FILES: &[(&str, EmbeddedAsset)] =
|
||||
include!(concat!(env!("OUT_DIR"), "/native_ui_assets.rs"));
|
||||
|
||||
let path = if path.is_empty() { "index.html" } else { path };
|
||||
let Ok(index) = FILES.binary_search_by(|(name, _)| name.cmp(&path)) else {
|
||||
let Ok(index) = files.binary_search_by(|(name, _)| name.cmp(&path)) else {
|
||||
return if navigation {
|
||||
// The hash router's relative assets and service worker require /ui/.
|
||||
Redirect::temporary("/ui/").into_response()
|
||||
@@ -313,7 +327,7 @@ fn embedded_response(path: &str, navigation: bool, head: bool, encoding: Encodin
|
||||
StatusCode::NOT_FOUND.into_response()
|
||||
};
|
||||
};
|
||||
let (path, ref asset) = FILES[index];
|
||||
let (path, ref asset) = files[index];
|
||||
let content_type = match path.rsplit('.').next().unwrap_or_default() {
|
||||
"html" => "text/html",
|
||||
"js" => "text/javascript",
|
||||
|
||||
@@ -186,196 +186,215 @@ async fn ui_serves_only_its_directory_with_navigation_and_static_cache_policy()
|
||||
async fn embedded_ui_preserves_assets_head_and_safe_navigation() {
|
||||
use std::io::Read;
|
||||
|
||||
let app = TestApp::new(|config| config.experimental.native_api.ui = "embedded".into()).await;
|
||||
for path in ["/", "/ui", "/ui/a/", "/ui/a/b"] {
|
||||
for method in [Method::GET, Method::HEAD] {
|
||||
let response = app
|
||||
.client
|
||||
.request(method, app.url(path))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::TEMPORARY_REDIRECT, "{path}");
|
||||
assert_eq!(response.headers()["location"], "/ui/");
|
||||
}
|
||||
}
|
||||
|
||||
let navigation = app.client.get(app.url("/ui/a/b")).send().await.unwrap();
|
||||
let entry_url = navigation
|
||||
.url()
|
||||
.join(navigation.headers()["location"].to_str().unwrap())
|
||||
.unwrap();
|
||||
let response = app.client.get(entry_url).send().await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.url().path(), "/ui/");
|
||||
assert_eq!(response.headers()["content-type"], "text/html");
|
||||
let entry_url = response.url().clone();
|
||||
let index = response.text().await.unwrap();
|
||||
assert_eq!(
|
||||
index,
|
||||
include_str!(concat!(env!("HONK_DOONA_DIR"), "/index.html"))
|
||||
);
|
||||
let standard = std::path::Path::new(env!("HONK_DOONA_DIR"));
|
||||
let mut lite_name = standard.file_name().unwrap().to_os_string();
|
||||
lite_name.push("-lite");
|
||||
let references = regex::Regex::new(r#"(?:src|href)="(\./[^"]+)""#).unwrap();
|
||||
let paths = references
|
||||
.captures_iter(&index)
|
||||
.map(|value| value[1].to_owned());
|
||||
for path in paths.chain(["./index.html".into(), "./sw.js".into()]) {
|
||||
let url = entry_url.join(&path).unwrap();
|
||||
let expected =
|
||||
std::fs::read(std::path::Path::new(env!("HONK_DOONA_DIR")).join(&path)).unwrap();
|
||||
for method in [Method::GET, Method::HEAD] {
|
||||
let response = app
|
||||
.client
|
||||
.request(method.clone(), url.clone())
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK, "{path}");
|
||||
assert_eq!(
|
||||
response.headers()["cache-control"],
|
||||
if path.starts_with("./assets/") {
|
||||
"public, max-age=31536000, immutable"
|
||||
for (ui, directory) in [
|
||||
("embedded", standard.to_path_buf()),
|
||||
("embedded-lite", standard.with_file_name(lite_name)),
|
||||
] {
|
||||
let app = TestApp::new(|config| config.experimental.native_api.ui = ui.into()).await;
|
||||
for path in ["/", "/ui", "/ui/a/", "/ui/a/b"] {
|
||||
for method in [Method::GET, Method::HEAD] {
|
||||
let response = app
|
||||
.client
|
||||
.request(method, app.url(path))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::TEMPORARY_REDIRECT, "{path}");
|
||||
assert_eq!(response.headers()["location"], "/ui/");
|
||||
}
|
||||
}
|
||||
|
||||
let navigation = app.client.get(app.url("/ui/a/b")).send().await.unwrap();
|
||||
let entry_url = navigation
|
||||
.url()
|
||||
.join(navigation.headers()["location"].to_str().unwrap())
|
||||
.unwrap();
|
||||
let response = app.client.get(entry_url).send().await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.url().path(), "/ui/");
|
||||
assert_eq!(response.headers()["content-type"], "text/html");
|
||||
let entry_url = response.url().clone();
|
||||
let index = response.text().await.unwrap();
|
||||
assert_eq!(
|
||||
index,
|
||||
std::fs::read_to_string(directory.join("index.html")).unwrap(),
|
||||
"{ui}"
|
||||
);
|
||||
let paths = references
|
||||
.captures_iter(&index)
|
||||
.map(|value| value[1].to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
assert!(
|
||||
paths.iter().any(|path| path.starts_with("./assets/")),
|
||||
"{ui}"
|
||||
);
|
||||
for path in paths
|
||||
.into_iter()
|
||||
.chain(std::iter::once("./index.html".into()))
|
||||
.chain((ui == "embedded").then(|| "./sw.js".into()))
|
||||
{
|
||||
let url = entry_url.join(&path).unwrap();
|
||||
let expected = std::fs::read(directory.join(&path)).unwrap();
|
||||
for method in [Method::GET, Method::HEAD] {
|
||||
let response = app
|
||||
.client
|
||||
.request(method.clone(), url.clone())
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK, "{path}");
|
||||
assert_eq!(
|
||||
response.headers()["cache-control"],
|
||||
if path.starts_with("./assets/") {
|
||||
"public, max-age=31536000, immutable"
|
||||
} else {
|
||||
"no-cache"
|
||||
},
|
||||
"{path}"
|
||||
);
|
||||
assert_eq!(response.headers()["x-content-type-options"], "nosniff");
|
||||
assert!(response.headers().get("x-frame-options").is_none());
|
||||
assert_eq!(
|
||||
response.headers()["content-length"]
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.parse::<usize>()
|
||||
.unwrap(),
|
||||
expected.len()
|
||||
);
|
||||
let mime = match path.rsplit('.').next().unwrap() {
|
||||
"html" => "text/html",
|
||||
"js" => "text/javascript",
|
||||
"css" => "text/css",
|
||||
"svg" => "image/svg+xml",
|
||||
"webmanifest" => "application/manifest+json",
|
||||
"png" => "image/png",
|
||||
extension => panic!("unexpected entry asset extension: {extension}"),
|
||||
};
|
||||
assert_eq!(response.headers()["content-type"], mime, "{path}");
|
||||
let body = response.bytes().await.unwrap();
|
||||
if method == Method::HEAD {
|
||||
assert!(body.is_empty(), "{path}");
|
||||
} else {
|
||||
"no-cache"
|
||||
},
|
||||
"{path}"
|
||||
);
|
||||
assert_eq!(response.headers()["x-content-type-options"], "nosniff");
|
||||
assert!(response.headers().get("x-frame-options").is_none());
|
||||
assert_eq!(
|
||||
response.headers()["content-length"]
|
||||
assert_eq!(body.as_ref(), expected, "{path}");
|
||||
}
|
||||
}
|
||||
if path.ends_with(".png") {
|
||||
continue;
|
||||
}
|
||||
for encoding in ["br", "gzip"] {
|
||||
let response = app
|
||||
.client
|
||||
.get(url.clone())
|
||||
.header("accept-encoding", format!("identity;q=0.5, {encoding}"))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK, "{path}");
|
||||
let Some(content_encoding) = response.headers().get("content-encoding") else {
|
||||
// The build stores a file as is when compression does not shrink it.
|
||||
assert!(expected.len() < 1024, "{path}");
|
||||
assert_eq!(response.headers()["vary"], "Origin", "{path}");
|
||||
assert_eq!(response.bytes().await.unwrap().as_ref(), expected, "{path}");
|
||||
continue;
|
||||
};
|
||||
assert_eq!(content_encoding, encoding, "{path}");
|
||||
assert_eq!(response.headers()["vary"], "accept-encoding", "{path}");
|
||||
let length = response.headers()["content-length"]
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.parse::<usize>()
|
||||
.unwrap(),
|
||||
expected.len()
|
||||
);
|
||||
let mime = match path.rsplit('.').next().unwrap() {
|
||||
"html" => "text/html",
|
||||
"js" => "text/javascript",
|
||||
"css" => "text/css",
|
||||
"svg" => "image/svg+xml",
|
||||
"webmanifest" => "application/manifest+json",
|
||||
"png" => "image/png",
|
||||
extension => panic!("unexpected entry asset extension: {extension}"),
|
||||
};
|
||||
assert_eq!(response.headers()["content-type"], mime, "{path}");
|
||||
let body = response.bytes().await.unwrap();
|
||||
if method == Method::HEAD {
|
||||
assert!(body.is_empty(), "{path}");
|
||||
} else {
|
||||
assert_eq!(body.as_ref(), expected, "{path}");
|
||||
.unwrap();
|
||||
let body = response.bytes().await.unwrap();
|
||||
assert_eq!(body.len(), length, "{path}");
|
||||
assert!(body.len() < expected.len(), "{path}");
|
||||
let mut decoded = Vec::new();
|
||||
if encoding == "br" {
|
||||
brotli::Decompressor::new(body.as_ref(), 4096)
|
||||
.read_to_end(&mut decoded)
|
||||
.unwrap();
|
||||
} else {
|
||||
flate2::read::GzDecoder::new(body.as_ref())
|
||||
.read_to_end(&mut decoded)
|
||||
.unwrap();
|
||||
}
|
||||
assert_eq!(decoded, expected, "{path}");
|
||||
}
|
||||
}
|
||||
if path.ends_with(".png") {
|
||||
continue;
|
||||
}
|
||||
for encoding in ["br", "gzip"] {
|
||||
if ui == "embedded" {
|
||||
let webp = std::fs::read_dir(directory.join("assets"))
|
||||
.unwrap()
|
||||
.map(|entry| entry.unwrap().file_name().into_string().unwrap())
|
||||
.find(|name| name.ends_with(".webp"))
|
||||
.unwrap();
|
||||
let response = app
|
||||
.client
|
||||
.get(url.clone())
|
||||
.header("accept-encoding", format!("identity;q=0.5, {encoding}"))
|
||||
.get(entry_url.join(&format!("./assets/{webp}")).unwrap())
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK, "{path}");
|
||||
let Some(content_encoding) = response.headers().get("content-encoding") else {
|
||||
// The build stores a file as is when compression does not shrink it.
|
||||
assert!(expected.len() < 1024, "{path}");
|
||||
assert_eq!(response.headers()["vary"], "Origin", "{path}");
|
||||
assert_eq!(response.bytes().await.unwrap().as_ref(), expected, "{path}");
|
||||
continue;
|
||||
};
|
||||
assert_eq!(content_encoding, encoding, "{path}");
|
||||
assert_eq!(response.headers()["vary"], "accept-encoding", "{path}");
|
||||
let length = response.headers()["content-length"]
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.parse::<usize>()
|
||||
.unwrap();
|
||||
let body = response.bytes().await.unwrap();
|
||||
assert_eq!(body.len(), length, "{path}");
|
||||
assert!(body.len() < expected.len(), "{path}");
|
||||
let mut decoded = Vec::new();
|
||||
if encoding == "br" {
|
||||
brotli::Decompressor::new(body.as_ref(), 4096)
|
||||
.read_to_end(&mut decoded)
|
||||
.unwrap();
|
||||
} else {
|
||||
flate2::read::GzDecoder::new(body.as_ref())
|
||||
.read_to_end(&mut decoded)
|
||||
.unwrap();
|
||||
}
|
||||
assert_eq!(decoded, expected, "{path}");
|
||||
assert_eq!(response.status(), StatusCode::OK, "{webp}");
|
||||
assert_eq!(response.headers()["content-type"], "image/webp", "{webp}");
|
||||
}
|
||||
for path in [
|
||||
"/ui/missing.js",
|
||||
"/ui/assets/missing",
|
||||
"/ui/fonts/missing",
|
||||
"/ui/icons/missing",
|
||||
"/ui/missing.webmanifest",
|
||||
"/ui/provenance/source.tar.gz",
|
||||
] {
|
||||
let response = app.client.get(app.url(path)).send().await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::NOT_FOUND, "{path}");
|
||||
assert_ne!(response.text().await.unwrap(), index);
|
||||
}
|
||||
for path in [
|
||||
"/ui/../private",
|
||||
"/ui/%2e%2e/private",
|
||||
"/ui/%2E%2E%2Fprivate",
|
||||
"/ui/%2e%2e%5cprivate",
|
||||
"/ui/%00",
|
||||
"/ui/%FF",
|
||||
"/ui/%zz",
|
||||
] {
|
||||
let response = raw_request(&app, path, "", b"").await;
|
||||
assert!(
|
||||
(400..500).contains(&response.status),
|
||||
"{path}: {}",
|
||||
response.status
|
||||
);
|
||||
assert_ne!(response.body, index.as_bytes());
|
||||
}
|
||||
for (header, value) in [
|
||||
("host", "attacker.example"),
|
||||
("origin", "https://attacker.example"),
|
||||
] {
|
||||
let response = app
|
||||
.client
|
||||
.get(app.url("/ui/"))
|
||||
.header(header, value)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
// Serving the UI does not exempt the API: a protected route still needs its bearer.
|
||||
error_response(
|
||||
app.client
|
||||
.get(app.url("/api/v1/version"))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
StatusCode::UNAUTHORIZED,
|
||||
"authentication_required",
|
||||
)
|
||||
.await;
|
||||
app.shutdown().await;
|
||||
}
|
||||
let webp = std::fs::read_dir(std::path::Path::new(env!("HONK_DOONA_DIR")).join("assets"))
|
||||
.unwrap()
|
||||
.map(|entry| entry.unwrap().file_name().into_string().unwrap())
|
||||
.find(|name| name.ends_with(".webp"))
|
||||
.unwrap();
|
||||
let response = app
|
||||
.client
|
||||
.get(entry_url.join(&format!("./assets/{webp}")).unwrap())
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK, "{webp}");
|
||||
assert_eq!(response.headers()["content-type"], "image/webp", "{webp}");
|
||||
for path in [
|
||||
"/ui/missing.js",
|
||||
"/ui/assets/missing",
|
||||
"/ui/fonts/missing",
|
||||
"/ui/icons/missing",
|
||||
"/ui/missing.webmanifest",
|
||||
"/ui/provenance/source.tar.gz",
|
||||
] {
|
||||
let response = app.client.get(app.url(path)).send().await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::NOT_FOUND, "{path}");
|
||||
assert_ne!(response.text().await.unwrap(), index);
|
||||
}
|
||||
for path in [
|
||||
"/ui/../private",
|
||||
"/ui/%2e%2e/private",
|
||||
"/ui/%2E%2E%2Fprivate",
|
||||
"/ui/%2e%2e%5cprivate",
|
||||
"/ui/%00",
|
||||
"/ui/%FF",
|
||||
"/ui/%zz",
|
||||
] {
|
||||
let response = raw_request(&app, path, "", b"").await;
|
||||
assert!(
|
||||
(400..500).contains(&response.status),
|
||||
"{path}: {}",
|
||||
response.status
|
||||
);
|
||||
assert_ne!(response.body, index.as_bytes());
|
||||
}
|
||||
for (header, value) in [
|
||||
("host", "attacker.example"),
|
||||
("origin", "https://attacker.example"),
|
||||
] {
|
||||
let response = app
|
||||
.client
|
||||
.get(app.url("/ui/"))
|
||||
.header(header, value)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
// Serving the UI does not exempt the API: a protected route still needs its bearer.
|
||||
error_response(
|
||||
app.client
|
||||
.get(app.url("/api/v1/version"))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
StatusCode::UNAUTHORIZED,
|
||||
"authentication_required",
|
||||
)
|
||||
.await;
|
||||
app.shutdown().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -385,6 +404,8 @@ async fn ui_without_available_assets_rejects_startup() {
|
||||
directory.path().to_str().unwrap(),
|
||||
#[cfg(not(feature = "native-ui"))]
|
||||
"embedded",
|
||||
#[cfg(not(feature = "native-ui"))]
|
||||
"embedded-lite",
|
||||
] {
|
||||
let mut config = Config::default();
|
||||
config.global.nfqueue_enable = false;
|
||||
|
||||
@@ -278,7 +278,7 @@ See the [subscription reference](./reference/subscription.md).
|
||||
|
||||
## Enabling the Clash API, cache file, and held-first-packet UDP
|
||||
|
||||
**Native API.** `native-api` is opt-in: build with `--features native-api` (or `native-ui`); the full and `-native-api` release artifacts include it. The listener requires `experimental.native_api.enabled: true` and one of a bearer `secret`, `password_auth: true`, or `allow_anonymous_loopback: true` on a loopback `listen`. honk sets no minimum `secret` length; use a long random value. The default address is `127.0.0.1:9527`; explicitly anonymous loopback is for local development only. All effective native fields require restart. An optional `ui` directory needs readable `index.html`; alternatively `--features native-ui` enables `ui: embedded` with pinned real doona. Neither mode downloads/builds the UI at runtime. Traffic/memory histories default on and retain at most 600 points/600 seconds. See [native settings](./reference/experimental.md#native_api) and the [API contract](./reference/api.md#native-api).
|
||||
**Native API.** `native-api` is opt-in: build with `--features native-api` (or `native-ui`); the full and `-native-api` release artifacts include it. The listener requires `experimental.native_api.enabled: true` and one of a bearer `secret`, `password_auth: true`, or `allow_anonymous_loopback: true` on a loopback `listen`. honk sets no minimum `secret` length; use a long random value. The default address is `127.0.0.1:9527`; explicitly anonymous loopback is for local development only. All effective native fields require restart. An optional `ui` directory needs readable `index.html`; alternatively `--features native-ui` enables `ui: embedded` with pinned real doona. `ui: embedded-lite` selects the lighter doona lite edition (preview) and also requires `native-ui`. None of these modes downloads/builds the UI at runtime. Traffic/memory histories default on and retain at most 600 points/600 seconds. See [native settings](./reference/experimental.md#native_api) and the [API contract](./reference/api.md#native-api).
|
||||
|
||||
For a captured `.dae` startup, source metadata, offline validation and real reload operations share the existing engine. Configuration reads return accepted content with only listener-secret values masked, including duplicate/overridden values and their other occurrences; credential-bearing sources remain read-only with original-byte hashes. Source `path` remains relative and `absolute_path` adds the canonical absolute path. Admitted anonymous loopback requests read the same data as bearer-authenticated requests. `config_write` defaults false and requires a nonempty secret or `password_auth`. Main-source node/provider creation and deletion, authorized whole-source PUT and restricted Group PATCH reuse this authority; all accepted noncredential includes qualify for source edits when `config_write` is enabled, but not dedicated entry deletion. Configured geodata updates use verified immutable bytes and the same reload owner. Written bytes are not automatically rolled back after activation failure. Avoid concurrent external edits; see [configuration safety](./reference/api.md#accepted-configuration-and-reload-operations) and [entry and geodata management](./reference/api.md#managed-entries-and-geodata).
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ flowchart TB
|
||||
| `ebpf` | no | Pulls in `aya`, `aya-obj`, `aya-log`, and optional `honk-nfqueue`; `build.rs` embeds the static `honk-ebpf` object, and userspace compiles policy extensions at runtime. Requires Linux kernel 6.12+ at runtime. |
|
||||
| `clash-api` | yes | Pulls in optional `axum` and `tower-http` for the Clash-compatible REST/WebSocket service. |
|
||||
| `native-api` | no | Independent HTTP/1.1 native observations, opt-in accepted-source administration and local-directory UI, with owned bounded connections, strict bearer/Host/Origin checks, and no dependency on Clash. |
|
||||
| `native-ui` | no | Includes `native-api` and embeds assets from the pinned doona distribution for `ui: embedded`; no runtime extraction, download or frontend build. |
|
||||
| `native-ui` | no | Includes `native-api` and embeds assets from the pinned doona distribution for `ui: embedded`; `ui: embedded-lite` selects the lighter doona lite edition (preview) with the same feature requirement. No runtime extraction, download or frontend build. |
|
||||
| `mimalloc` | yes | Pulls in `mimalloc` and `libmimalloc-sys` and installs mimalloc as the `honk-core` binary allocator. On Linux, startup disables transparent huge pages for the process before starting Tokio, and sets mimalloc's purge delay to 100 ms unless `MIMALLOC_PURGE_DELAY` says otherwise. |
|
||||
| `rprx` | yes | Enables `honk-outbound/rprx`, which registers the VLESS and VMess handlers, including the supported VLESS Encryption and `xtls-rprx-vision` paths. |
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ Download the package matching the device architecture from [GitHub Releases](htt
|
||||
|
||||
The musl packages are static binaries intended for gateways. Packages without the `-stock` suffix use mimalloc for throughput (label `mimalloc`); `-stock` packages use the system allocator and suit small devices where the RSS high-water mark matters more (label `stockalloc`). The Downloads section of each release lists every archive with its `{allocator}-{API}-{arch}-{libc}` label.
|
||||
|
||||
The lean variants fail closed: enabling `experimental.native_api` on `-clash-api`, or `ui: embedded` without `native-ui`, fails startup. `--store db` and native configuration administration require `native-api`.
|
||||
The lean variants fail closed: enabling `experimental.native_api` on `-clash-api`, or `ui: embedded` or `ui: embedded-lite` without `native-ui`, fails startup. `--store db` and native configuration administration require `native-api`. `embedded-lite` selects the lighter doona lite edition (preview).
|
||||
|
||||
```shell
|
||||
pkg=honk-core-<version>-<target>-full # or -stock-full, -clash-api, -stock-native-api, as downloaded
|
||||
|
||||
@@ -86,7 +86,7 @@ HTTP transport boundary: Hyper can reject malformed or hard-limit HTTP with 400/
|
||||
|
||||
Application target/header budgets apply to Hyper's parsed, normalized representation, not the original wire bytes. Hyper may remove a request-target fragment or coalesce equal `Content-Length` fields before application counting; oversized original text in those forms can therefore reach a normal response instead of 413. Raw input remains subject to Hyper's transport handling. This is an accepted boundary difference, not a second HTTP parser or a raw-wire size guarantee; body limits still cover all delivered body bytes.
|
||||
|
||||
With `ui` configured, `/` and `/ui` redirect to `/ui/`. Directory hosting retains extensionless SPA fallback; missing static assets, fonts/icons, manifest or service worker return 404, never HTML. Build with `--features native-ui` (the full release builds do) and set `ui: embedded` to serve the pinned real doona distribution without filesystem extraction or network access. Its hash router uses `/ui/#/...`; other safe embedded navigation paths redirect to `/ui/` so relative assets and the service worker resolve correctly. The embedded UI is stored precompressed and served as brotli or gzip when the browser accepts it; directory hosting serves the administrator's `.br`/`.gz` siblings the same way. Content-hashed files under `assets/` are cached as immutable for a year; other static responses use `no-cache`. Static responses use `nosniff` and carry no framing header, so dashboards such as LuCI can embed the UI; a deployment that needs clickjacking protection adds `X-Frame-Options` or `Content-Security-Policy: frame-ancestors` at its reverse proxy. Assets remain public behind Host/Origin admission. Discovery and password setup/login use the public exceptions above; other API requests require a bearer. No credentials are injected into the UI.
|
||||
With `ui` configured, `/` and `/ui` redirect to `/ui/`. Directory hosting retains extensionless SPA fallback; missing static assets, fonts/icons, manifest or service worker return 404, never HTML. Build with `--features native-ui` (the full release builds do) and set `ui: embedded` to serve the pinned real doona distribution without filesystem extraction or network access. `ui: embedded-lite` selects the lighter doona lite edition (preview), also requiring `native-ui`. Both editions connect to the native API on the page origin. The hash router uses `/ui/#/...`; other safe embedded navigation paths redirect to `/ui/` so relative assets and the service worker resolve correctly. The embedded UI is stored precompressed and served as brotli or gzip when the browser accepts it; directory hosting serves the administrator's `.br`/`.gz` siblings the same way. Content-hashed files under `assets/` are cached as immutable for a year; other static responses use `no-cache`. Static responses use `nosniff` and carry no framing header, so dashboards such as LuCI can embed the UI; a deployment that needs clickjacking protection adds `X-Frame-Options` or `Content-Security-Policy: frame-ancestors` at its reverse proxy. Assets remain public behind Host/Origin admission. Discovery and password setup/login use the public exceptions above; other API requests require a bearer. No credentials are injected into the UI.
|
||||
|
||||
### Authentication discovery and password sessions
|
||||
|
||||
@@ -339,9 +339,9 @@ Automatic updates are on by default, every 24 hours; `auto_update.enabled: false
|
||||
|
||||
### Embedded doona provenance
|
||||
|
||||
Default-off `native-ui` implies `native-api` and embeds the doona build that Cargo reads at compile time from the absolute directory in `HONK_DOONA_DIR`; without it the build fails. `ci/fetch-doona.sh` downloads the release pinned in `.github/ci/pins.env` (currently doona `0.1.0-rc.1`, commit `f896a2176460daa0997497cd964d84c697e717b2`), checks its SHA-256 and that it carries `THIRD-PARTY-NOTICES.txt` and every `LICENSES/` file its `NOTICE` names, drops any fonts and prints the directory: `export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`. `just lint` and `just test-ci` run it when the variable is unset. Full release builds include the embedded UI; the lean `-clash-api` and `-native-api` artifacts do not. The binary embeds the notices shipped in doona's program archive, and every full release tarball carries them under `doona/`. The Noto Sans TC and SC fonts are not embedded. doona's CSS declares those fonts with `font-display: optional`, so the browser falls back to system fonts when the font requests return 404. To use Noto Sans, extract `doona-<version>.tar.gz` and `doona-fonts-<version>.tar.gz` from the [doona release](https://github.com/Zakkaus/doona/releases) into one directory and point `ui` at it, or install the `doona` and `doona-fonts` packages and set `ui: /usr/share/doona`. The corresponding GPL-3.0-only source is the doona tag [`v0.1.0-rc.1`](https://github.com/Zakkaus/doona/tree/v0.1.0-rc.1). The release workflow attaches `doona-source-0.1.0-rc.1.tar.gz` to the tag release and to the rolling Debug release; `ci/fetch-doona.sh --source` checks that the tag still points at the pinned commit and generates it with `git archive --format=tar --prefix=doona/ v0.1.0-rc.1 | gzip -n` (GNU gzip). Whoever redistributes a `native-ui` binary must provide that source archive and the notices with it (GPL-3.0 section 6).
|
||||
Default-off `native-ui` implies `native-api` and embeds standard doona from the absolute directory in `HONK_DOONA_DIR` and doona lite from its sibling `${HONK_DOONA_DIR}-lite` (trailing slashes ignored); both directories must contain `index.html`. This is the only required environment variable. `ci/fetch-doona.sh` downloads both program archives from the release pinned in `.github/ci/pins.env` (currently doona `0.1.0-rc.2`, commit `426597a5c9294625c8e95a2eb6f3858d7b5f033a`), checks each archive against `DOONA_SHA256` / `DOONA_LITE_SHA256` and that each carries `THIRD-PARTY-NOTICES.txt` and every `LICENSES/` file its `NOTICE` names, drops any fonts, extracts standard into the requested directory and lite into its `-lite` sibling, and prints only the standard directory: `export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`. `just lint` and `just test-ci` run it when the variable is unset. Full release builds include the embedded UI; the lean `-clash-api` and `-native-api` artifacts do not. The binary embeds each edition's own notices, and every full release tarball carries them under `doona/` and `doona-lite/`, respectively. Lite uses system fonts. The Noto Sans TC and SC fonts are not embedded. doona's CSS declares those fonts with `font-display: optional`, so the browser falls back to system fonts when the font requests return 404. To use Noto Sans, extract `doona-<version>.tar.gz` and `doona-fonts-<version>.tar.gz` from the [doona release](https://github.com/Zakkaus/doona/releases) into one directory and point `ui` at it, or install the `doona` and `doona-fonts` packages and set `ui: /usr/share/doona`. Both editions share the corresponding GPL-3.0-only source at the doona tag [`v0.1.0-rc.2`](https://github.com/Zakkaus/doona/tree/v0.1.0-rc.2). The release workflow attaches `doona-source-0.1.0-rc.2.tar.gz` to the tag release and to the rolling Debug release; `ci/fetch-doona.sh --source` checks that the tag still points at the pinned commit and generates it with `git archive --format=tar --prefix=doona/ v0.1.0-rc.2 | gzip -n` (GNU gzip). Whoever redistributes a `native-ui` binary must provide that source archive and the notices with it (GPL-3.0 section 6).
|
||||
|
||||
To reproduce the assets, extract the source archive into its own directory, use Node 22+ and `pnpm@11.15.1`, then run `pnpm install --frozen-lockfile`, `pnpm build` and `SOURCE_DATE_EPOCH=1791741741 pnpm package`. The epoch is the pinned upstream commit's timestamp; the source archive has no Git history. Use GNU tar and GNU gzip on `PATH` (verified with tar 1.35 and gzip 1.15); another gzip implementation can produce different archive hashes from identical tar bytes. Cargo builds embed only the files in `HONK_DOONA_DIR` and never build or download the frontend. That source's checker is `tools/conformance.mjs`; its live walk is read-only and skips controls, diagnostics and missing observed IDs. Check base and management contracts, and exercise browser actions separately: schema passes alone are not full UI, kernel or platform acceptance.
|
||||
To reproduce the assets, extract the source archive into its own directory, use Node 22+ and `pnpm@11.15.1`, then run `pnpm install --frozen-lockfile`, `pnpm build`, `pnpm -C apps/lite build` and `SOURCE_DATE_EPOCH=1793072394 pnpm package`. The epoch is the pinned upstream commit's timestamp; the source archive has no Git history. Install brotli and use GNU tar and GNU gzip on `PATH` (verified with tar 1.35 and gzip 1.15); another gzip implementation can produce different archive hashes from identical tar bytes. Cargo builds embed only the files in `HONK_DOONA_DIR` and its `-lite` sibling and never build or download the frontend. That source's checker is `tools/conformance.mjs`; its live walk is read-only and skips controls, diagnostics and missing observed IDs. Check base and management contracts, and exercise browser actions separately: schema passes alone are not full UI, kernel or platform acceptance.
|
||||
|
||||
### Native logs and runtime settings
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ Requires the opt-in `native-api` Cargo feature (build with `--features native-ap
|
||||
| `allow_anonymous_loopback` | `false` | Permit credential-free requests only when `secret` is empty, `password_auth` is false and the actual listening IP is loopback. |
|
||||
| `allow_origins` | empty list | Additional explicit HTTP(S) origins, without paths, credentials, query, fragment, `null`, or wildcards. |
|
||||
| `allowed_hosts` | empty list | Additional explicit HTTP Host authorities, without URL schemes, paths, credentials, or wildcards. Omitted port means 80, not the listener's port. |
|
||||
| `ui` | `""` | Empty disables hosting; otherwise a trusted local directory with readable `index.html`, or `embedded` with the default-off `native-ui` feature. No startup download, extraction or frontend build. |
|
||||
| `ui` | `""` | Empty disables hosting; otherwise a trusted local directory with readable `index.html`, or `embedded` / `embedded-lite` with the default-off `native-ui` feature. `embedded-lite` is the lighter doona lite edition (preview). No startup download, extraction or frontend build. |
|
||||
| `record_flows` | `true` | Permit bounded userspace flow recording under flow diagnostic demand or an explicit runtime pin. `false` prohibits recording, including runtime pins; configuration changes require restart. |
|
||||
| `record_traffic` | `true` | Keep up to 600 traffic samples for 600 seconds, even without clients. `false` disables history and releases its buffer on restart; current counters remain available. |
|
||||
| `record_memory` | `true` | Keep up to 600 memory samples for 600 seconds, even without clients. `false` disables history and releases its buffer on restart; current readings remain available. |
|
||||
@@ -63,7 +63,7 @@ Lists use individually quoted comma-separated entries, such as `allow_origins: '
|
||||
|
||||
Relative UI paths follow the existing dependency search: an existing path under `global.data_dir`, then `/var/share/honk`, then the working directory; a missing dependency resolves under `global.data_dir` and startup fails. The administrator owns the directory and any symlink targets. See the [native API contract](./api.md#native-api).
|
||||
|
||||
For a single binary, use a full release build or `HONK_DOONA_DIR=$(ci/fetch-doona.sh) cargo build -p honk-core --features native-ui`, and set `ui: embedded`; `native-ui` includes `native-api` without requiring Clash. Without `native-ui`, enabled embedded hosting fails startup. The assets receive no injected credentials; clients use public discovery to select static-token entry or password setup/login. Asset/source identities, corresponding-source distribution and the management contract are documented in the [API reference](./api.md#embedded-doona-provenance).
|
||||
For a single binary, use a full release build or `HONK_DOONA_DIR=$(ci/fetch-doona.sh) cargo build -p honk-core --features native-ui`, and set `ui: embedded` or `ui: embedded-lite`; `native-ui` includes `native-api` without requiring Clash. Without `native-ui`, enabled embedded hosting fails startup. The assets receive no injected credentials; clients use public discovery to select static-token entry or password setup/login. Asset/source identities, corresponding-source distribution and the management contract are documented in the [API reference](./api.md#embedded-doona-provenance).
|
||||
|
||||
File-configured geodata sources are administrator-controlled, restart-required and cannot be changed through source writes. With a state db, downloads can also use authenticated URL overrides or built-in sources. Userinfo, fragments, redirects and content encoding are rejected. Direct hostname sources require `global.bootstrap_resolver`; no system-DNS fallback is used. `assets.geodata.route` or the stored route can send downloads through the routing rules or a group instead, and a route that cannot carry a request never falls back to direct. Updates use the applicable configured, stored or built-in sources. The [management contract](./api.md#managed-entries-and-geodata) distinguishes network limits, verified-byte activation and partial durable replacement from rollback.
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ experimental {
|
||||
enabled: true
|
||||
listen: '127.0.0.1:9527'
|
||||
secret: '<random value of at least 16 bytes>'
|
||||
ui: 'embedded' # or a trusted local directory; empty disables hosting
|
||||
ui: 'embedded' # or embedded-lite / a trusted local directory; empty disables hosting
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -74,7 +74,7 @@ experimental {
|
||||
| `password_auth` | `false` | Administrator password login; requires an empty `secret`. |
|
||||
| `allow_anonymous_loopback` | `false` | Credential-free loopback access; mutually exclusive with `password_auth`. |
|
||||
| `allow_origins`, `allowed_hosts` | empty | Extra HTTP(S) origins and Host authorities, individually quoted and comma-separated. |
|
||||
| `ui` | `""` | `embedded` (needs `native-ui`) or a local directory containing `index.html`. |
|
||||
| `ui` | `""` | `embedded` or `embedded-lite` (both need `native-ui`; lite is the lighter doona lite edition, preview) or a local directory containing `index.html`. |
|
||||
| `record_flows`, `record_logs`, `record_dns_log` | `true` | `false` prohibits the corresponding diagnostic capture; restart to change. |
|
||||
| `record_traffic`, `record_memory` | `true` | Keep 600 samples over 600 seconds; `false` releases the buffer. |
|
||||
| `config_write` | `false` | Allow whole-source replacement and reload through the API; needs token or password mode. |
|
||||
|
||||
@@ -60,7 +60,7 @@ experimental {
|
||||
enabled: true
|
||||
listen: '127.0.0.1:9527'
|
||||
secret: '<至少 16 字节的随机值>'
|
||||
ui: 'embedded' # 或受信任的本地目录;空 = 不托管 UI
|
||||
ui: 'embedded' # 或 embedded-lite / 受信任的本地目录;空 = 不托管 UI
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -73,7 +73,7 @@ experimental {
|
||||
| `password_auth` | `false` | 管理员密码登录;要求 `secret` 为空。 |
|
||||
| `allow_anonymous_loopback` | `false` | 仅回环、无凭证访问;与 `password_auth` 互斥。 |
|
||||
| `allow_origins`、`allowed_hosts` | 空 | 额外允许的 HTTP(S) 源与 Host,逐项加引号、逗号分隔。 |
|
||||
| `ui` | `""` | `embedded`(需 `native-ui`)或含 `index.html` 的本地目录。 |
|
||||
| `ui` | `""` | `embedded` 或 `embedded-lite`(均需 `native-ui`;lite 是更轻量的 doona lite 预览版)或含 `index.html` 的本地目录。 |
|
||||
| `record_flows`、`record_logs`、`record_dns_log` | `true` | 置 `false` 禁止相应诊断录制,需重启生效。 |
|
||||
| `record_traffic`、`record_memory` | `true` | 保留 600 秒内最多 600 个样本;`false` 释放缓冲。 |
|
||||
| `config_write` | `false` | 允许通过 API 整源改写并重载;需 token 或密码模式。 |
|
||||
|
||||
@@ -282,7 +282,7 @@ dns {
|
||||
|
||||
## 启用 Clash API、缓存文件与首包保留 UDP
|
||||
|
||||
**原生 API。** `native-api` 需显式编译:以 `--features native-api`(或 `native-ui`)构建;full 与 `-native-api` 发布产物包含它。listener 须配置 `experimental.native_api.enabled: true`,并满足以下条件之一:配置 bearer `secret`、设置 `password_auth: true`,或在 loopback `listen` 上设置 `allow_anonymous_loopback: true`。honk 不限制 `secret` 的最短长度,应使用足够长的随机值。默认监听地址为 `127.0.0.1:9527`,匿名 loopback 访问仅供本地开发。所有生效的原生字段均需重启。用户态观测、事件与有界历史独立于 Clash;流量/内存历史默认保留最多 600 点/600 秒。可选 `ui` 目录需已有可读 `index.html`,也可用 `--features native-ui` 与 `ui: embedded` 内嵌固定版本的 doona;运行时不下载或构建 UI。
|
||||
**原生 API。** `native-api` 需显式编译:以 `--features native-api`(或 `native-ui`)构建;full 与 `-native-api` 发布产物包含它。listener 须配置 `experimental.native_api.enabled: true`,并满足以下条件之一:配置 bearer `secret`、设置 `password_auth: true`,或在 loopback `listen` 上设置 `allow_anonymous_loopback: true`。honk 不限制 `secret` 的最短长度,应使用足够长的随机值。默认监听地址为 `127.0.0.1:9527`,匿名 loopback 访问仅供本地开发。所有生效的原生字段均需重启。用户态观测、事件与有界历史独立于 Clash;流量/内存历史默认保留最多 600 点/600 秒。可选 `ui` 目录需已有可读 `index.html`,也可用 `--features native-ui` 与 `ui: embedded` 内嵌固定版本的 doona;运行时不下载或构建 UI。`ui: embedded-lite` 选择更轻量的 doona lite 预览版,同样需要 `native-ui`。
|
||||
|
||||
`.dae` 仍是唯一配置权威。启动时捕获来源、离线校验和 reload 共用引擎。配置读取返回已接受正文,仅遮蔽监听凭据值,包括重复、被覆盖的值及其在其他位置的出现。凭据源仍只读,哈希仍对应原始字节。源 `path` 保持相对路径,`absolute_path` 另行提供规范化绝对路径。获准访问的匿名 loopback 请求与 bearer 认证请求读取相同的数据。`config_write` 默认 false,要求非空 secret 或 `password_auth`。主文件节点/provider 创建删除、授权源 PUT 和受限组 PATCH 复用该权威。启用 `config_write` 后,所有已接受的非凭据 include 均可编辑源,但不授予专用条目删除权限。配置的 geodata 更新将不可变的已验证字节交给同一 reload owner。激活失败不会自动回滚已写字节,应避免并发外部编辑。详见[原生设置](./reference/experimental.md#native_api)与 [主文件条目与 geodata 契约](./reference/api.md#主文件条目与-geodata-管理)。
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ flowchart TB
|
||||
| `ebpf` | 否 | 引入 `aya`、`aya-obj`、`aya-log` 和可选 `honk-nfqueue`;`build.rs` 嵌入静态 `honk-ebpf` 对象,用户态在运行时编译 policy extension。运行时要求 Linux kernel 6.12+。 |
|
||||
| `clash-api` | 是 | 引入可选 `axum` 与 `tower-http`,提供 Clash 兼容 REST/WebSocket 服务。 |
|
||||
| `native-api` | 否 | 独立的 HTTP/1.1 原生观测、可选历史、受控源管理/reload API 与本地目录 UI;持有有界连接并负责其生命周期,严格校验 bearer/Host/Origin,不依赖 Clash。 |
|
||||
| `native-ui` | 否 | 隐含 `native-api`,为 `ui: embedded` 内嵌固定版本的 doona 发行资产;运行时不解压、不下载、不构建前端。 |
|
||||
| `native-ui` | 否 | 隐含 `native-api`,为 `ui: embedded` 内嵌固定版本的 doona 发行资产;`ui: embedded-lite` 选择更轻量的 doona lite 预览版,同样需要该特性。运行时不解压、不下载、不构建前端。 |
|
||||
| `mimalloc` | 是 | 引入 `mimalloc` 与 `libmimalloc-sys`,并将 mimalloc 安装为 `honk-core` 二进制的 allocator。在 Linux 上,程序会在启动 Tokio 前为当前进程禁用透明大页,并把 mimalloc 的 purge 延迟设为 100 ms(除非 `MIMALLOC_PURGE_DELAY` 另有设置)。 |
|
||||
| `rprx` | 是 | 启用 `honk-outbound/rprx`,注册 VLESS 与 VMess Handler,包括受支持的 VLESS Encryption 和 `xtls-rprx-vision` 路径。 |
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ bpf /sys/fs/bpf bpf defaults 0 0
|
||||
|
||||
musl 包是静态二进制,适合网关部署。无 `-stock` 后缀的包使用 mimalloc,优先考虑吞吐(标签 `mimalloc`);`-stock` 包使用系统 allocator,更适合关注内存峰值的小内存设备(标签 `stockalloc`)。每个 release 的 Downloads 一节按 `{allocator}-{API}-{arch}-{libc}` 标签列出全部归档。
|
||||
|
||||
精简变体按 fail-closed 处理:在 `-clash-api` 上启用 `experimental.native_api`,或没有 `native-ui` 却设置 `ui: embedded`,都会启动失败。`--store db` 与原生配置管理需要 `native-api`。
|
||||
精简变体按 fail-closed 处理:在 `-clash-api` 上启用 `experimental.native_api`,或没有 `native-ui` 却设置 `ui: embedded` 或 `ui: embedded-lite`,都会启动失败。`--store db` 与原生配置管理需要 `native-api`。`embedded-lite` 选择更轻量的 doona lite 预览版。
|
||||
|
||||
```shell
|
||||
pkg=honk-core-<version>-<target>-full # 或按下载的包改为 -stock-full、-clash-api、-stock-native-api 等
|
||||
|
||||
@@ -87,7 +87,7 @@ TCP 在 copy 成功读取或 splice 成功写入目标 socket 时实时入账,
|
||||
|
||||
应用 target/header 上限作用于 Hyper **解析并规范化后的表示**,不是原始 wire 字节。Hyper 可能先移除 request-target fragment,或合并相同 `Content-Length` 字段,再交给应用计量;这些形式的原始文本即使超过应用上限,也可能得到正常响应而不是 413。原始输入仍受 Hyper 传输处理约束。这是已接受的边界差异,不另写 HTTP parser,也不宣称原始 wire 大小保证;body 限制仍覆盖全部交付的 body 字节。
|
||||
|
||||
配置 `ui` 后,`/` 与 `/ui` 重定向到 `/ui/`。目录托管保留无扩展名 SPA fallback;缺失静态资产、fonts/icons、manifest 或 service worker 返回 404,不返回 HTML。以 `--features native-ui` 构建(full 发布产物已启用)并设置 `ui: embedded`,即可直接提供固定真实 doona 产物,不解压到磁盘、不联网。其 hash router 使用 `/ui/#/...`;其他合法内嵌导航路径重定向回 `/ui/`,确保相对资产与 service worker 路径正确。内嵌 UI 以预压缩形式存储,浏览器接受时以 brotli 或 gzip 传输;目录托管以同样方式提供管理员放置的 `.br`/`.gz` 同名文件。`assets/` 下带内容哈希的文件按 immutable 缓存一年,其他静态响应使用 `no-cache`。静态响应带 `nosniff`,不带 framing header,以便 LuCI 等面板嵌入 UI;需要防御 clickjacking 的部署应在反向代理添加 `X-Frame-Options` 或 `Content-Security-Policy: frame-ancestors`。公开资产仍经过 Host/Origin 校验。Discovery 与密码 setup/login 使用上述公共例外,其他 API 请求要求 bearer;不向 UI 注入凭据。
|
||||
配置 `ui` 后,`/` 与 `/ui` 重定向到 `/ui/`。目录托管保留无扩展名 SPA fallback;缺失静态资产、fonts/icons、manifest 或 service worker 返回 404,不返回 HTML。以 `--features native-ui` 构建(full 发布产物已启用)并设置 `ui: embedded`,即可直接提供固定真实 doona 产物,不解压到磁盘、不联网。`ui: embedded-lite` 选择更轻量的 doona lite 预览版,同样需要 `native-ui`。两种版本都连接页面同源的原生 API。其 hash router 使用 `/ui/#/...`;其他合法内嵌导航路径重定向回 `/ui/`,确保相对资产与 service worker 路径正确。内嵌 UI 以预压缩形式存储,浏览器接受时以 brotli 或 gzip 传输;目录托管以同样方式提供管理员放置的 `.br`/`.gz` 同名文件。`assets/` 下带内容哈希的文件按 immutable 缓存一年,其他静态响应使用 `no-cache`。静态响应带 `nosniff`,不带 framing header,以便 LuCI 等面板嵌入 UI;需要防御 clickjacking 的部署应在反向代理添加 `X-Frame-Options` 或 `Content-Security-Policy: frame-ancestors`。公开资产仍经过 Host/Origin 校验。Discovery 与密码 setup/login 使用上述公共例外,其他 API 请求要求 bearer;不向 UI 注入凭据。
|
||||
|
||||
### 认证发现与密码会话
|
||||
|
||||
@@ -356,9 +356,9 @@ DELETE 不接受 body/query:带有任一项时返回 `400 invalid_request`,b
|
||||
|
||||
### 内嵌 doona 来源
|
||||
|
||||
默认关闭的 `native-ui` 隐含 `native-api`,编译时从 `HONK_DOONA_DIR` 指定的绝对路径目录读取 doona 构建产物并内嵌;未设置该变量时构建失败。`ci/fetch-doona.sh` 下载 `.github/ci/pins.env` 固定的发布包(当前为 doona `0.1.0-rc.1`、提交 `f896a2176460daa0997497cd964d84c697e717b2`),校验 SHA-256,确认包内含 `THIRD-PARTY-NOTICES.txt` 及 `NOTICE` 引用的全部 `LICENSES/` 文件,删除字体并输出目录:`export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`。未设置该变量时,`just lint` 与 `just test-ci` 自动执行该脚本。full 发布产物包含内嵌 UI,精简的 `-clash-api`/`-native-api` 产物不包含;二进制内嵌 doona 程序包自带的 notices,每个 full 发布 tarball 也在 `doona/` 目录附带这些文件。内嵌产物不含 Noto Sans TC 与 SC 字体。doona 的 CSS 以 `font-display: optional` 声明这些字体,因此字体请求返回 404 时浏览器使用系统字体。需要 Noto Sans 时,将 [doona 发布页](https://github.com/Zakkaus/doona/releases)的 `doona-<version>.tar.gz` 与 `doona-fonts-<version>.tar.gz` 解压到同一目录并让 `ui` 指向该目录,或安装 `doona` 与 `doona-fonts` 软件包并设置 `ui: /usr/share/doona`。对应的 GPL-3.0-only 源码是 doona 标签 [`v0.1.0-rc.1`](https://github.com/Zakkaus/doona/tree/v0.1.0-rc.1)。发布流程将 `doona-source-0.1.0-rc.1.tar.gz` 附加到正式标签发布与滚动 Debug 发布;该包由 `ci/fetch-doona.sh --source` 生成:先确认标签仍指向固定提交,再执行 `git archive --format=tar --prefix=doona/ v0.1.0-rc.1 | gzip -n`(GNU gzip)。再分发 `native-ui` 二进制时,须按 GPL-3.0 第 6 条一并提供该源码包与 notices。
|
||||
默认关闭的 `native-ui` 隐含 `native-api`,编译时从 `HONK_DOONA_DIR` 指定的绝对路径目录内嵌标准版 doona,从同级 `${HONK_DOONA_DIR}-lite` 目录内嵌 doona lite(忽略末尾斜杠);两个目录都必须含 `index.html`,只需设置这一个环境变量。`ci/fetch-doona.sh` 下载 `.github/ci/pins.env` 固定的两种版本程序包(当前为 doona `0.1.0-rc.2`、提交 `426597a5c9294625c8e95a2eb6f3858d7b5f033a`),分别按 `DOONA_SHA256` / `DOONA_LITE_SHA256` 校验 SHA-256,确认各包内含 `THIRD-PARTY-NOTICES.txt` 及 `NOTICE` 引用的全部 `LICENSES/` 文件,删除字体,将标准版解压到指定目录、lite 解压到其 `-lite` 同级目录,并只输出标准版目录:`export HONK_DOONA_DIR=$(ci/fetch-doona.sh)`。未设置该变量时,`just lint` 与 `just test-ci` 自动执行该脚本。full 发布产物包含内嵌 UI,精简的 `-clash-api`/`-native-api` 产物不包含;二进制内嵌两种版本各自的 notices,每个 full 发布 tarball 分别在 `doona/` 与 `doona-lite/` 目录附带这些文件。Lite 使用系统字体。内嵌产物不含 Noto Sans TC 与 SC 字体。doona 的 CSS 以 `font-display: optional` 声明这些字体,因此字体请求返回 404 时浏览器使用系统字体。需要 Noto Sans 时,将 [doona 发布页](https://github.com/Zakkaus/doona/releases)的 `doona-<version>.tar.gz` 与 `doona-fonts-<version>.tar.gz` 解压到同一目录并让 `ui` 指向该目录,或安装 `doona` 与 `doona-fonts` 软件包并设置 `ui: /usr/share/doona`。两种版本共用的 GPL-3.0-only 源码是 doona 标签 [`v0.1.0-rc.2`](https://github.com/Zakkaus/doona/tree/v0.1.0-rc.2)。发布流程将 `doona-source-0.1.0-rc.2.tar.gz` 附加到正式标签发布与滚动 Debug 发布;该包由 `ci/fetch-doona.sh --source` 生成:先确认标签仍指向固定提交,再执行 `git archive --format=tar --prefix=doona/ v0.1.0-rc.2 | gzip -n`(GNU gzip)。再分发 `native-ui` 二进制时,须按 GPL-3.0 第 6 条一并提供该源码包与 notices。
|
||||
|
||||
复现时将源码包解压到独立目录,用 Node 22+、`pnpm@11.15.1` 执行 `pnpm install --frozen-lockfile`、`pnpm build`、`SOURCE_DATE_EPOCH=1791741741 pnpm package`。该 epoch 是固定上游提交的时间;源码包不含 Git 历史。`PATH` 中须使用 GNU tar 和 GNU gzip(已验证 tar 1.35、gzip 1.15);其他 gzip 实现即使压缩相同 tar 字节,也可能产生不同包摘要。Cargo 构建只内嵌 `HONK_DOONA_DIR` 中的文件,不构建也不下载前端。该源码的 checker 为 `tools/conformance.mjs`;live walk 只读,跳过控制、诊断和缺少已观测 ID 的资源。基础与管理契约应分别核对,浏览器操作另行验收;schema 通过不等于完整 UI、内核或部署矩阵通过。
|
||||
复现时将源码包解压到独立目录,用 Node 22+、`pnpm@11.15.1` 执行 `pnpm install --frozen-lockfile`、`pnpm build`、`pnpm -C apps/lite build`、`SOURCE_DATE_EPOCH=1793072394 pnpm package`。该 epoch 是固定上游提交的时间;源码包不含 Git 历史。须安装 brotli,`PATH` 中须使用 GNU tar 和 GNU gzip(已验证 tar 1.35、gzip 1.15);其他 gzip 实现即使压缩相同 tar 字节,也可能产生不同包摘要。Cargo 构建只内嵌 `HONK_DOONA_DIR` 及其 `-lite` 同级目录中的文件,不构建也不下载前端。该源码的 checker 为 `tools/conformance.mjs`;live walk 只读,跳过控制、诊断和缺少已观测 ID 的资源。基础与管理契约应分别核对,浏览器操作另行验收;schema 通过不等于完整 UI、内核或部署矩阵通过。
|
||||
|
||||
### 连接关闭、模式与数据面生命周期
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
| `allow_anonymous_loopback` | `false` | 仅在 `secret` 为空、`password_auth` 为 false 且实际监听 IP 为 loopback 时允许无凭证请求。 |
|
||||
| `allow_origins` | 空列表 | 额外允许的完整 HTTP(S) Origin;不含路径、凭据、query、fragment、`null` 或通配符。 |
|
||||
| `allowed_hosts` | 空列表 | 额外允许的 HTTP Host authority;不含 URL scheme、路径、凭据或通配符。省略端口表示 80,不是监听端口。 |
|
||||
| `ui` | `""` | 空值关闭托管;其他值为含可读 `index.html` 的可信本地目录,或配合默认关闭的 `native-ui` feature 使用 `embedded`。启动不下载、不解压、不构建前端。 |
|
||||
| `ui` | `""` | 空值关闭托管;其他值为含可读 `index.html` 的可信本地目录,或配合默认关闭的 `native-ui` feature 使用 `embedded` / `embedded-lite`。`embedded-lite` 是更轻量的 doona lite 预览版。启动不下载、不解压、不构建前端。 |
|
||||
| `record_flows` | `true` | 允许按 flow 诊断需求记录有界用户态 flow,或通过显式运行时设置持续记录。`false` 禁止记录,运行时设置不能覆盖;修改配置需重启。 |
|
||||
| `record_traffic` | `true` | 无客户端也记录流量 history;最多 600 点/600 秒,false 在重启后释放对应缓冲,不关闭即时计数。 |
|
||||
| `record_memory` | `true` | 无客户端也记录 RSS/cgroup history;最多 600 点/600 秒,false 在重启后释放对应缓冲,不关闭即时内存观测。 |
|
||||
@@ -65,7 +65,7 @@ experimental {
|
||||
|
||||
相对 UI 路径沿用依赖搜索顺序:`global.data_dir` 下已有路径、`/var/share/honk` 下已有路径、工作目录已有路径;均不存在时定位到 `global.data_dir` 并在启动时报错。目录及其符号链接目标均由可信管理员负责。参见[原生 API 契约](./api.md#原生-api)。
|
||||
|
||||
单文件部署可使用 full 发布产物,或执行 `HONK_DOONA_DIR=$(ci/fetch-doona.sh) cargo build -p honk-core --features native-ui`,并设置 `ui: embedded`;`native-ui` 隐含 `native-api`,不要求 Clash。没有 `native-ui` 时启用内嵌托管会启动失败。静态资源不注入凭据;客户端通过公共 discovery 选择静态 token 输入或密码 setup/login。产物/源码身份、对应源码分发和管理契约见 [API 参考](./api.md#内嵌-doona-来源)。
|
||||
单文件部署可使用 full 发布产物,或执行 `HONK_DOONA_DIR=$(ci/fetch-doona.sh) cargo build -p honk-core --features native-ui`,并设置 `ui: embedded` 或 `ui: embedded-lite`;`native-ui` 隐含 `native-api`,不要求 Clash。没有 `native-ui` 时启用内嵌托管会启动失败。静态资源不注入凭据;客户端通过公共 discovery 选择静态 token 输入或密码 setup/login。产物/源码身份、对应源码分发和管理契约见 [API 参考](./api.md#内嵌-doona-来源)。
|
||||
|
||||
配置文件中的 geodata 来源由管理员配置、需重启,不能通过源写入修改。启用状态数据库时,下载还可使用已认证的 URL 覆盖或内置来源;拒绝 userinfo、fragment、redirect 与 content encoding。直连的域名来源要求 `global.bootstrap_resolver`,不回退系统 DNS。`assets.geodata.route` 或已存储的路由可改为遵循路由规则或经过组下载;路由无法承载请求时不会回退到直连。更新使用适用的配置文件、已存储或内置来源。[主文件条目与 geodata 契约](./api.md#主文件条目与-geodata-管理)区分网络期限、已验证字节激活及部分耐久替换,不承诺回滚。
|
||||
|
||||
|
||||
Reference in new issue
Block a user