mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-06 04:29:52 +00:00
d55e63b88e
Overhaul the WASI guest data plane for throughput and add the host capabilities it relies on. The externally driven Tokio runtime now runs its timer pre-turn only when a tracked deadline has expired, and all WASI-reachable timers (STUN, port mapping, WebClient, UDP flow cleanup) go through the portable time facade so conditional timer driving cannot starve them. Data plane: - Move read/write deadlines onto TCP and UDP resources with one ABI setter per direction, reuse a single expiration timer per resource, and drop timeout arguments from the four hot data-plane submissions (ABI v3). Checked absolute instants treat unrepresentable finite timeouts as unbounded instead of panicking. - Batch host traffic: vectored TCP frame writes combine queued slices into one host operation, and reads request a bounded 64 KiB while retaining excess bytes in the stream buffer. - Complete TCP writes inside the guest with cancellation-safe writes, reporting the completed prefix before honoring cancellation or timeout so hosts never replay bytes. - Repoll smoltcp egress immediately on zero poll delay, enlarge virtual UDP receive queues to 128 KiB payload with 128 metadata slots, and bound UDP session receive buffers to 8 KiB plus one byte while keeping oversized-datagram detection. Host integration: - Add optional algorithm-neutral AEAD seal/open imports with the ring backend as fallback, and pin the ring AES-128-GCM wire vector so the Go host stays interoperable. - Forward instance events to hosts through one best-effort, synchronous, non-blocking import. - Add a repository-owned build entry point for the Go host artifact: Binaryen 131 at -O4 with cached, SHA-256-verified official archives.
135 lines
4.6 KiB
Bash
Executable File
135 lines
4.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
readonly binaryen_version=131
|
|
readonly binaryen_release="version_${binaryen_version}"
|
|
readonly script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
readonly repository_root=$(cd -- "${script_dir}/.." && pwd)
|
|
cd "$repository_root"
|
|
readonly target_dir="${CARGO_TARGET_DIR:-target}"
|
|
readonly raw_artifact="${target_dir}/wasm32-wasip1/release/easytier_core.wasm"
|
|
readonly artifact="${target_dir}/wasm32-wasip1/release/easytier_core_go_host.wasm"
|
|
readonly core_features="proxy-smoltcp-stack,ring-crypto,wasi-crypto-offload"
|
|
|
|
sha256_file() {
|
|
if command -v sha256sum >/dev/null; then
|
|
sha256sum "$1" | awk '{print $1}'
|
|
elif command -v shasum >/dev/null; then
|
|
shasum -a 256 "$1" | awk '{print $1}'
|
|
else
|
|
echo "sha256sum or shasum is required" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
resolve_binaryen_asset() {
|
|
local operating_system machine
|
|
operating_system=$(uname -s)
|
|
machine=$(uname -m)
|
|
|
|
case "$machine" in
|
|
x86_64 | amd64) machine=x86_64 ;;
|
|
aarch64 | arm64) machine=arm64 ;;
|
|
*)
|
|
echo "unsupported Binaryen host architecture: ${machine}" >&2
|
|
return 1
|
|
;;
|
|
esac
|
|
|
|
case "$operating_system" in
|
|
Linux)
|
|
if [[ "$machine" == arm64 ]]; then
|
|
binaryen_platform=aarch64-linux
|
|
binaryen_sha256=ba991f677edd9a21d2bc96c0144bc8ac5b112d4d98a3eb266e075e22e557df2a
|
|
else
|
|
binaryen_platform=x86_64-linux
|
|
binaryen_sha256=b5bf1f0eaf17c63ee588ff7a5954dc8f6ce2c26989051c66f24dfe9ece3e46db
|
|
fi
|
|
;;
|
|
Darwin)
|
|
binaryen_platform="${machine}-macos"
|
|
if [[ "$machine" == arm64 ]]; then
|
|
binaryen_sha256=e441b48dc22163d209b4f05e44dc7210909b01237642b6c9ae48fd710a3ef83e
|
|
else
|
|
binaryen_sha256=d209fadd8a894bdaf3bd3612a23c32a0af184d2f4a979b8c789e6e4f6a4de883
|
|
fi
|
|
;;
|
|
MINGW* | MSYS* | CYGWIN*)
|
|
binaryen_platform="${machine}-windows"
|
|
binaryen_executable=.exe
|
|
if [[ "$machine" == arm64 ]]; then
|
|
binaryen_sha256=e3eaed3d43bcbba867895e55f5e3e9fcfebf776bc4ed6ee59cae071f083cedb9
|
|
else
|
|
binaryen_sha256=2f4edac1703a2f695254d6ff52ede03481e67db1f094915763d863158c17d9bc
|
|
fi
|
|
;;
|
|
*)
|
|
echo "unsupported Binaryen host operating system: ${operating_system}" >&2
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
download_wasm_opt() {
|
|
local archive archive_name archive_url cache_dir digest temporary
|
|
resolve_binaryen_asset
|
|
archive_name="binaryen-${binaryen_release}-${binaryen_platform}.tar.gz"
|
|
archive_url="https://github.com/WebAssembly/binaryen/releases/download/${binaryen_release}/${archive_name}"
|
|
cache_dir="${target_dir}/binaryen/${binaryen_release}-${binaryen_platform}"
|
|
archive="${cache_dir}/${archive_name}"
|
|
wasm_opt="${cache_dir}/binaryen-${binaryen_release}/bin/wasm-opt${binaryen_executable:-}"
|
|
if [[ -x "$wasm_opt" ]]; then
|
|
return
|
|
fi
|
|
|
|
mkdir -p "$cache_dir"
|
|
if [[ -f "$archive" ]]; then
|
|
digest=$(sha256_file "$archive")
|
|
fi
|
|
if [[ ${digest:-} != "$binaryen_sha256" ]]; then
|
|
command -v curl >/dev/null || {
|
|
echo "curl is required to download Binaryen" >&2
|
|
return 1
|
|
}
|
|
temporary="${archive}.$$"
|
|
trap 'rm -f "${temporary:-}" "${optimized:-}"' EXIT
|
|
curl --fail --location --output "$temporary" "$archive_url"
|
|
digest=$(sha256_file "$temporary")
|
|
if [[ "$digest" != "$binaryen_sha256" ]]; then
|
|
echo "Binaryen archive SHA-256 mismatch: ${digest}" >&2
|
|
return 1
|
|
fi
|
|
mv "$temporary" "$archive"
|
|
fi
|
|
tar -xzf "$archive" -C "$cache_dir"
|
|
if [[ ! -x "$wasm_opt" ]]; then
|
|
echo "wasm-opt is missing from Binaryen archive" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
wasm_opt=${WASM_OPT:-}
|
|
if [[ -z "$wasm_opt" ]]; then
|
|
download_wasm_opt
|
|
fi
|
|
version=$("$wasm_opt" --version)
|
|
if [[ "$version" != *"version ${binaryen_version} "* ]]; then
|
|
echo "wasm-opt ${binaryen_version} is required, got: ${version}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cargo build --release --target wasm32-wasip1 -p easytier-core \
|
|
--features "$core_features"
|
|
|
|
optimized="${artifact}.wasm-opt.$$"
|
|
trap 'rm -f "${temporary:-}" "${optimized:-}"' EXIT
|
|
"$wasm_opt" -O4 \
|
|
--enable-bulk-memory \
|
|
--enable-bulk-memory-opt \
|
|
--enable-nontrapping-float-to-int \
|
|
"$raw_artifact" \
|
|
-o "$optimized"
|
|
mv "$optimized" "$artifact"
|
|
echo "built ${artifact} with ${version}"
|