Files
KKRainbow e313ba8efb fix(wasi): reduce startup RSS, align ABI v4 and wire v3 (#2588)
* feat(easytier-go): accept data plane ABI v4

The core raised DATA_PLANE_ABI_VERSION to 4 in f26c2aa1 ("feat(wasi):
run EasyTier core on Cloudflare Workers and browsers") to advertise the
new guest exports easytier_data_plane_tcp_shutdown_write_submit and
easytier_data_plane_tcp_shutdown_write_result_take, which let a host
half-close guest TCP streams.

The Go host has no caller for half-close: net.Conn exposes only Close,
which already tears down both directions, so the v3 behavior is
preserved and no new plumbing is added. Without this bump, any artifact
rebuilt from current core source is rejected at instance creation with
"unsupported EasyTier data plane ABI version 4, want 3".

* fix(easytier-go): decode socket options wire v3, rebuild core artifact

38e2a621 ("refactor(ohos): 拆分 OHRS 包并按 socket 精细保护 VPN 流量")
raised the host socket options wire format from version 2 to 3: a
need_protect byte is appended after the purpose byte in TCP connect,
UDP bind, and TCP listen options, shifting bind_device one byte later.
The Go hostABI decoders were never updated, so every socket operation
from a HEAD-built core was rejected as "invalid options" and required
listeners failed to start.

Bump the accepted wire version to 3 and skip the need_protect byte in
all three decoders. The byte requests VPN socket protection, which only
Android-style VPN hosts can honor; on every other platform sockets are
already protected, so reading and discarding it is correct.

Regenerate the embedded core artifact and protobuf bindings from HEAD
(599e4eac) so the shipped artifact matches the Go host again. The proto
regeneration also picks up schema fields added since the last embed
(e.g. prefer_peer_relay).

* perf(easytier-go): release compiler garbage after host init

wazero's optimizing compiler allocates ~100MB of throwaway state on
the Go heap while compiling the embedded core. Go's runtime does not
return that memory to the OS after the initiating GC, so the process
retained the compilation peak for its entire lifetime: RSS sat at
~164MB before any instance or network activity.

Call debug.FreeOSMemory() once after the module is instantiated.
NewHost is a one-time initialization path outside the dataplane, so
the stop-the-world pass is safe here. Measured RSS after host.New
drops from ~164MB to ~64MB; no behavioral change.

* chore(easytier-js): bump toolchain dependencies

- vitest 2.1.9 -> 3.2.7 (all three packages)
- esbuild 0.25.9 -> 0.28.2 (browser bundler)
- wrangler 4.114.0 -> 4.134.0 (cloudflare + web example)
- @cloudflare/workers-types 5.20260724.1 -> 5.20260917.1
- binaryen 131.0.0 -> 132.0.0 (JS bindings only; the wasm build
  uses the standalone wasm-opt binary fetched by the build script)

Not bumped: typescript stays at 5.9.3 (latest 5.x; 7.0 is a major
jump not worth taking for this workspace), vite stays at 5.4.21
(web-example only; 5->8 spans three majors).

Verified with pnpm test (28 + 2 + 2 tests across runtime, browser,
cloudflare) and pnpm check (tsc + wrangler deploy --dry-run).
pnpm-workspace.yaml gained three minimumReleaseAgeExclude entries
recorded automatically by pnpm for freshly published versions.

* fix(easytier-js): align host wire format with core wire v3

The core socket options wire format moved to version 3 in 38e2a621
(need_protect byte after purpose). The JS websocket-host still
required version 2 and rejected every TCP bind from a HEAD-built core,
breaking browser port leases.

- websocket-host.ts: accept version 3, minimum length 49. The
  need_protect byte sits after purpose (offset 43) and is a no-op
  outside Android VPN hosts, so the decoder just skips it.
- websocket-host.test.ts: update the test encoder to emit v3.
- binaryen stays at 131.0.0 to match script/build-wasi-core.sh, which
  intentionally pins binaryen 131 for the Go-side embedded core.
  The npm binaryen package provides the wasm-opt binary used by
  build-wasm.mjs, so keeping both sides on the same version avoids
  divergent optimization output.
- pnpm-workspace.yaml: drop two stale minimumReleaseAgeExclude entries
  for @cloudflare/workers-types versions no longer in the lockfile.

* test(easytier-go): cover socket options wire v3 decoders

Direct unit tests for decodeTCPConnectOptions, decodeUDPBindOptions, and
decodeTCPListenOptions with wire v3 documents. Covers combinations of
socket mark, netns, bind device, and local address presence, plus
rejection of wire v2.

Resolves review feedback on PR #2588.
2026-09-19 00:13:47 +08:00
..

EasyTier Browser and Cloudflare example

This example connects @easytier/browser to an inbound @easytier/cloudflare relay. Its application code imports only the two public package entries; it does not use @easytier/runtime, Wasm loaders, TOML, ABI handles, or Host Tunnel internals.

Prepare the repository build

From the EasyTier repository root:

cd easytier-js
pnpm install
pnpm --filter @easytier/web-example build:packages

The build starts from source and generates both required Wasm profiles. No artifact from an earlier build is required. Published package consumers receive the matching Wasm artifacts in the npm packages.

Set the local secret

Copy the example file and replace its placeholder with a local secret:

cp examples/web/cloudflare/.dev.vars.example \
  examples/web/cloudflare/.dev.vars

The .dev.vars file is ignored by Git. Enter the same value in the Browser UI.

Start the Cloudflare relay

In one terminal, from the easytier-js workspace:

pnpm --filter @easytier/web-example dev:cloudflare

Check that the EasyTier Instance is running:

curl http://127.0.0.1:8787/health

Expected response:

{"ok":true,"state":"running","connections":0}

Start the Browser application

In another terminal:

pnpm --filter @easytier/web-example dev:browser

Open the URL printed by Vite. Keep the default relay URL ws://127.0.0.1:8787/, enter the secret from .dev.vars, and select Connect. A successful session shows peer_added; the relay health response then reports one active connection.

The Browser and Worker must use the same network name and secret. Local development uses ws://; a deployed Worker uses wss://.

Validate the example

pnpm --filter @easytier/web-example check

This type-checks and bundles the Browser application, generates Cloudflare binding types from wrangler.jsonc, type-checks the Worker, and runs a Wrangler deployment dry-run.

Deploy the relay

Authenticate Wrangler, set the secret interactively, and deploy:

pnpm --filter @easytier/web-example exec wrangler login
pnpm --filter @easytier/web-example exec wrangler secret put \
  EASYTIER_NETWORK_SECRET --config cloudflare/wrangler.jsonc
pnpm --filter @easytier/web-example deploy:cloudflare

After deployment, enter the Worker URL in the Browser UI with the wss:// scheme.

When the packages are published, an external application installs them with:

pnpm add @easytier/browser @easytier/cloudflare