Files
Easytier/easytier-core/src/wasi/abi.rs
T
KKRainbow 021f523431 refactor(core): separate portable core from native runtime (#2451)
Create easytier-core as the portable owner of configuration,
connectivity, tunnels, peer and routing state, gateways, management,
the data plane, and instance lifecycle. Keep operating-system
integration, native protocol engines, process startup, and presentation
in easytier behind explicit Host capability adapters.

Create easytier-proto to own schemas, generated RPC types, descriptors,
and feature-scoped protocol slices. Remove runtime protobuf reflection
from core while preserving unknown route-peer fields across forwarding.

Normalize instance construction through CoreInstance, CoreHostAdapters,
CoreProcessRuntime, and InstanceManager. Make the runtime config store
the only authoritative mutable configuration after startup.

Move the portable TCP/UDP data plane into core and extract a generic
OperationBroker for completion, cancellation, disposal, and capacity
accounting. Expose the session-based FFI v2 completion API and keep the
WASI guest ABI, wire schemas, and adapters with core.

Migrate CLI, GUI, web, FFI, Android JNI, OHOS, uptime, and mobile
consumers to the shared manager and core state. Add explicit user/web
config ownership and revision-aware web reconciliation.

Preserve configuration, wire, and management behavior while fixing
regressions discovered by the full platform and integration matrix:

- inherit advertised relay capabilities in foreign networks;
- refresh OSPF peer state immediately after runtime config changes;
- restore CLI GlobalCtx event output without forcing GUI logging;
- retain legacy encryption names and standalone RPC tunnel metadata;
- restore ICMP host composition and fragmented UDP handling;
- use portable 64-bit atomics on 32-bit MIPS targets; and
- retain discarded operations until late cancellation completes.

Validate the refactor across 45 GitHub checks, including Linux, macOS,
Windows, FreeBSD, web, GUI, Android, OHOS, feature profiles, and
three-node and subnet-proxy integration tests.

BREAKING CHANGE: internal Rust module paths are not preserved. Legacy
native data-plane APIs are replaced by the session-based FFI v2 API.
The dedicated Android data-plane wrapper is removed.
2026-07-26 15:41:55 +08:00

86 lines
3.7 KiB
Rust

//! Stable ABI contract between the EasyTier WASI guest and its runtime.
//!
//! A runtime must provide every function in the `easytier_host` import module
//! and call the guest lifecycle exports listed in [`GUEST_EXPORTS`]. The raw
//! import declarations live in the target-only `imports` Module.
//! Rust visibility does not define this cross-language contract; the imported
//! and exported WebAssembly symbol names and signatures do.
//!
//! Every `u32` pointer is an offset in wasm32 guest linear memory, never a
//! native host pointer. The runtime must copy input bytes before an import
//! returns and may write result bytes only during the matching `take_*` call.
//! An operation ID belongs to core until a terminal `take_*` call consumes it
//! or the runtime receives the `cancel_operation` import.
/// WebAssembly import module a WASI runtime must implement.
pub const HOST_IMPORT_MODULE: &str = "easytier_host";
/// Version of the JSON document accepted by `easytier_instance_create`.
pub const CORE_INSTANCE_CONFIG_VERSION: u32 = 14;
/// Version of the public data-plane guest export contract.
pub const DATA_PLANE_ABI_VERSION: u32 = 2;
/// The guest exposes an instance-scoped data-plane operation broker.
pub const DATA_PLANE_CAPABILITY: u64 = 1 << 0;
/// The guest data plane supports TCP streams and listeners.
pub const DATA_PLANE_TCP_CAPABILITY: u64 = 1 << 1;
/// The guest data plane supports UDP sockets.
pub const DATA_PLANE_UDP_CAPABILITY: u64 = 1 << 2;
/// Guest exports a WASI runtime calls to manage a core instance.
///
/// Buffer allocation precedes config, packet, and error-copy calls. Instance
/// creation and lifecycle use the returned instance handle. A runtime drives
/// all asynchronous guest work through `easytier_instance_drive` and host
/// completion notifications.
pub const GUEST_EXPORTS: &[&str] = &[
// Guest-memory buffers.
"easytier_buffer_alloc",
"easytier_buffer_free",
// Instance lifecycle and external runtime driving.
"easytier_instance_create",
"easytier_instance_start",
"easytier_instance_stop",
"easytier_instance_drive",
"easytier_instance_notify_completions",
"easytier_instance_state",
"easytier_instance_next_deadline_millis",
// Raw IP packet ingress and error retrieval.
"easytier_instance_send_packet",
"easytier_instance_drop",
"easytier_instance_error_len",
"easytier_instance_error_copy",
];
/// Guest exports present when the core is built with the smoltcp data plane.
#[cfg(feature = "proxy-smoltcp-stack")]
pub const DATA_PLANE_GUEST_EXPORTS: &[&str] = &[
// ABI discovery.
"easytier_data_plane_abi_version",
"easytier_data_plane_capabilities",
// Data-plane operation submission.
"easytier_data_plane_tcp_connect_submit",
"easytier_data_plane_tcp_bind_submit",
"easytier_data_plane_tcp_accept_submit",
"easytier_data_plane_tcp_read_submit",
"easytier_data_plane_tcp_write_submit",
"easytier_data_plane_udp_bind_submit",
"easytier_data_plane_udp_receive_submit",
"easytier_data_plane_udp_send_submit",
// Completion, result, and resource lifecycle.
"easytier_data_plane_completion_drain",
"easytier_data_plane_result_size",
"easytier_data_plane_tcp_connect_result_take",
"easytier_data_plane_tcp_bind_result_take",
"easytier_data_plane_tcp_accept_result_take",
"easytier_data_plane_tcp_read_result_take",
"easytier_data_plane_tcp_write_result_take",
"easytier_data_plane_udp_bind_result_take",
"easytier_data_plane_udp_receive_result_take",
"easytier_data_plane_udp_send_result_take",
"easytier_data_plane_operation_cancel",
"easytier_data_plane_operation_free",
"easytier_data_plane_resource_close",
];