Commit Graph

41 Commits

Author SHA1 Message Date
韩嘉乐 40c857748f feat(ohos): 接入 Pro 运行时并自动化 HAR 交付 (#2462) 2026-08-01 16:35:14 +08:00
KKRainbow afbba5d928 refactor(core): migrate packet processing from pnet to smoltcp (#2456)
Replace pnet_packet parsing and mutation across gateway packet paths with the existing smoltcp wire APIs. Preserve length validation, fragmentation classification, TCP flags, and checksum behavior while removing the core pnet_packet feature dependency.
Reject stale non-initiator OSPF sync sessions: only initiator requests may create missing sessions, and a rejection clears the old initiator role only when the remote session generation is unchanged. This fixes an unbounded RPC storm caused by a delayed route sync recreating a session after both peers relinquished the initiator role, with regression tests for session creation and response reordering.
2026-08-01 10:57:23 +08:00
刚刚 fc3914baf5 Require a full config server URL (#2459)
Co-authored-by: 刚刚 <239500008+225284228a-droid@users.noreply.github.com>
2026-07-31 16:47:40 +08:00
KKRainbow d55e63b88e perf(wasi): optimize data plane and extend host ABI to v3 (#2455)
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.
2026-07-28 00:29:08 +08:00
KKRainbow 7b506e25a7 perf(data-plane): reduce per-packet synchronization overhead (#2453)
* perf(stats): avoid per-update clock reads

Perf profiles show quanta::get_now consuming 2.9-4.3% of data-plane
CPU because every counter update refreshes a high-resolution timestamp.

Track metric activity with the existing 60-second cleanup cadence instead.
Relaxed 32-bit epochs preserve the three-minute retention window, support
32-bit targets, and remove repeated clock reads from packet processing.

* perf(data-plane): reduce per-packet synchronization

Perf profiles showed per-packet config Arc cloning, bounded-channel
permit futures, duplicate peer lookups, and default connection UUID
lookups consuming CPU in both TCP and UDP data paths.

Borrow stable config snapshots, use nonblocking channel fast paths with
the existing backpressure fallback, reuse direct peer lookups, and cache
the selected connection while preserving close and reselection behavior.

Add focused tests for channel backpressure and cached connection
invalidation.

* fix(peer): serialize default connection cache updates

The profile-guided default connection cache could republish a connection
after the close task removed it, leaving a stale cache while another
connection remained live.

Serialize only cache-miss selection/publication and connection removal.
The per-packet cache-hit path remains lock-free, while close and selection
can no longer race to resurrect a removed connection.
2026-07-27 21:32:57 +08:00
KKRainbow 7fb42c3b73 perf(data-plane): restore native throughput after host portability (#2452)
* perf(core): make data-plane idle check constant time

Avoid scanning every DashMap shard for each peer packet when no data-plane flows are active.

Publish the flow count before insertion and release it after removal so an Acquire load is a safe O(1) idle signal. Reject count overflow and underflow instead of silently saturating.

* test(perf): add repeatable two-node netns benchmark

Create isolated underlay namespaces, pin both EasyTier cores and iperf3 endpoints, and measure a single TCP flow in both directions over either UDP or TCP peer transport.

Keep every iperf3 JSON result and emit directional medians while cleaning up processes and namespaces on every exit path.

* perf(tcp): preserve native owned stream halves

Let each VirtualTcpSocket adapter consume itself into independent read and write halves. Portable adapters retain the generic shared split as a default.

Use lock-free Tokio owned halves for native TCP and Unix streams so tunnel I/O no longer takes the generic split mutex on every poll. Cover full-duplex traffic and write-half shutdown.

* perf(packet): preserve ownership across the Host seam

Introduce an opaque, move-only HostPacket that retains core packet storage while exposing only the raw IP payload. Clear private headers before handing storage back to a native TUN adapter.

Use an ownership-preserving bounded channel for native ingress and egress. Keep explicit copy adapters for Vec and WASI boundaries, and verify allocation identity, backpressure, shutdown, and end-to-end delivery.

* perf(udp): preserve packet ownership through sessions

Carry EasyTier tunnel packets through UDP session queues as owned values. Reuse the existing tunnel header for session framing instead of copying payloads into a second packet and rebuilding them on receive.

Keep completion delivery for the public datagram socket API while removing the unused completion channel from streaming tunnel sends. Avoid the unconditional receive-side clone before QUIC routing is known.

* perf(peer): publish packet filters as immutable snapshots

Replace per-packet async and synchronous registry locks with ArcSwap snapshots. Permanent filters now need no activity checks, while managed registrations retain explicit acquire/release visibility.

Closing a managed registration marks it inactive before atomically removing it. Existing snapshots keep in-flight filters alive, and registration mutations prune inactive entries while preserving newest-first order.

* perf(instance): give native hosts direct packet egress

Let the core create one bounded HostPacket channel and transfer its receiver directly to a PacketEgressHost during startup. Native TUN runtimes now consume that receiver without the intermediate PacketSink channel and forwarding task.

Keep PacketSinkEgress as the compatibility adapter for callback and test hosts, and make receiver installation one-shot across desktop, mobile, and disabled runtimes.

* perf(crypto): restore accelerated native AEAD backends

Move Ring and OpenSSL implementations behind the core Encryptor seam.
Portable builds continue selecting only supported backends.

Restore historical precedence: OpenSSL, Ring, then RustCrypto. Keep
backend availability consistent across secure transports and cover
fixed-nonce wire compatibility between implementations.

* perf(udp): receive native datagrams into owned buffers

Extend the portable UDP socket seam with an owned-datagram receive path.
Keep a compatible default for portable hosts. Native Unix sockets write
recvmsg output directly into the final BytesMut allocation.

This removes the per-packet stack-to-heap copy introduced by the portable
socket boundary without exposing native socket resources to core.

* perf(data-plane): remove portable hot-path overhead

Restore native throughput lost while generalizing the host and UDP
session layers.

Read packet policy once per send, update traffic counters through
registry guards, and preserve packet ownership while UDP dispatch
borrows stable session state.

Move UDP shutdown monitoring into a control task so forwarding avoids
a select future per packet. Bound native datagram storage to 8 KiB,
reject oversized sends, and drop truncated Unix receives.

Keep accelerated AEAD selection warning-free when portable crypto
features are also built. Cover session bounds, truncation, and idle
shutdown with regression tests.

* fix(udp): preserve portable datagram receive semantics

Keep the public portable receive capacity at the theoretical UDP
maximum instead of silently shrinking it to the native fast-path limit.

Apply the 8 KiB session boundary after a complete portable receive,
so Windows cannot turn an oversized datagram into a fatal listener
error and other adapters cannot dispatch a truncated prefix.

Cover dropping an oversized packet while the same portable socket
continues to deliver the following valid datagram.

* fix(ci): align feature gating with backend selection

Compile the Ring implementation in production only when OpenSSL is not
selected, while retaining it for cross-backend unit tests.

Remove stale test imports and assert UDP dispatch results so the strict
workspace Clippy job passes without suppressing diagnostics.
2026-07-26 22:54:43 +08:00
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
sijie.sun 5273f4dcca do not use workspace 2024-03-24 12:26:18 +08:00
sijie.sun a093901ed3 replace stun_format with stun_codec 2024-03-24 12:26:18 +08:00
sijie.sun ba455f2a82 update package description 2024-03-24 12:26:18 +08:00
sijie.sun 6c2a240966 allow foreign network forward nic data 2024-03-23 22:42:49 +08:00
sijie.sun 269146c9f8 fix ipv4 map use old peer_id, fix direct connector use ring 2024-03-23 18:01:28 +08:00
sijie.sun 9ed22eaf99 improve direct connector 2024-03-23 16:56:12 +08:00
sijie.sun 2cfc5a6ef6 better user interface 2024-03-23 15:56:46 +08:00
sijie.sun a4af83e82d fix peer rpc and ospf route 2024-03-21 23:46:51 +08:00
sijie.sun ba1795a113 introduce a link-state route algo 2024-03-21 22:38:35 +08:00
sijie.sun d70d085553 do some refactor
1. Route must impl PeerPacketFilter trait.
2. Use postcard lib to serial msg instead of bincode.
3. Fix cycle ref in peer_mgr & peer_rpc
2024-03-21 22:38:35 +08:00
Sijie.Sun ecb385a82c optimize packet def (#31) 2024-03-13 22:43:52 +08:00
Sijie.Sun b0494687b5 simplify packet definition (#30) 2024-03-13 18:09:48 +08:00
Sijie.Sun 0053666dfb use uint32 as peer id (#29) 2024-03-13 00:15:22 +08:00
Sijie.Sun cb0df51319 fix ip & route cfg on windows (#28) 2024-03-09 00:24:16 +08:00
Sijie.Sun 5f30747f62 fix peer_remove & peer_add event handler (#27) 2024-03-06 23:52:56 +08:00
Sijie.Sun 278a4846f1 support ip broadcast (#26) 2024-03-06 23:09:15 +08:00
Sijie.Sun d8d1c64df7 Introduce foreigner network (#25)
* support network identity for instance

* introduce foreign network

foreign network allow a node serving as one public node. other nodes can
connect to this node to discover peers and exchange route info.
2024-03-06 20:59:17 +08:00
Sijie.Sun 9261d0d32d optimize bandwidth usage (#24)
1. stable stun test result
2. stable report peers result
3. do not send same packet to rip peer
2024-03-02 22:29:31 +08:00
Sijie.Sun 7918031d8b add version to rip route, reduce bandwidth (#23)
reduce bandwidth usage on route propagation
2024-03-02 18:54:45 +08:00
Sijie.Sun c6c505f9d7 support udp proxy gateway (#22) 2024-03-01 21:37:45 +08:00
Sijie.Sun 24178bcf6e use peer center instance to gatter peers info (#21)
* use peer center instance to gatter peers info
2024-02-29 00:04:48 +08:00
Sijie.Sun 31af413b03 fix local time not work in musl (#20) 2024-02-27 21:47:08 +08:00
Sijie.Sun e5b3fb09e6 fix peer rpc send response error (#19) 2024-02-26 21:04:33 +08:00
Sijie.Sun 756d498b90 Stun fix (#18)
* make easytier-core a lib
* add stun command to easytier cli
* fix stun test for musl
2024-02-08 23:44:51 +08:00
Sijie.Sun 7fc4aecdb9 Fix udp and win route (#16)
* robust udp tunnel
* fix windows route add
* use pnet to get index
* windows disable udp reset
2024-02-08 16:27:18 +08:00
Sijie.Sun 2c2e41be24 refactor route so we can add other router (#15) 2024-02-06 20:17:08 +08:00
Sijie.Sun 7f8935a9d5 introduce peer center (#13)
peer_center is used to collect peer info into one peer node.

the center node is selected with the following rules:

1. has smallest peer id
2. TODO: has allow_to_be_center peer feature

peer center is not guaranteed to be stable and can be changed when peer enter
or leave.  it's used to reduce the cost to exchange infos between peers.
2024-02-06 13:29:12 +08:00
Sijie.Sun aeb00fb42f optimize latency window stats (#10) 2024-02-01 18:32:06 +08:00
Sijie.Sun 95a52a4b5c bind socket to device on macos (#9)
bind socket to device on macos
2024-01-31 21:43:23 +08:00
Sijie.Sun d4b0f49443 optimize cli output (#6) 2024-01-30 22:05:58 +08:00
Sijie.Sun 003520f2b4 fix elastic pingpong (#5)
fix elastic pingpong not started after peer conn established
2024-01-30 12:58:15 +08:00
Sijie.Sun 118954c745 elastic ping pong to adapt env with packet loss (#4)
* elastic ping pong to adapt env with packet loss
2024-01-29 23:21:13 +08:00
Sijie.Sun 6271f9a7a7 GitHub actions (#3)
support github actions
2024-01-28 15:56:42 +08:00
sijie.sun 9779923b87 Initial Version 2024-01-27 15:12:30 +08:00