mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-06 20:49:46 +00:00
021f523431
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.
115 lines
3.2 KiB
Rust
115 lines
3.2 KiB
Rust
use std::sync::Arc;
|
|
|
|
use easytier_core::{gateway::dhcp::DhcpIpv4Host, instance::CorePacketPlane};
|
|
use tokio::sync::{Mutex, mpsc};
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
use crate::common::global_ctx::ArcGlobalCtx;
|
|
|
|
mod event_journal;
|
|
mod implementation;
|
|
#[cfg(feature = "tun")]
|
|
mod magic_dns;
|
|
#[cfg(feature = "tun")]
|
|
mod tun_common;
|
|
#[cfg(not(feature = "tun"))]
|
|
#[path = "runtime_host/tun_disabled.rs"]
|
|
mod tun_runtime;
|
|
#[cfg(all(feature = "tun", not(mobile)))]
|
|
#[path = "runtime_host/tun_desktop.rs"]
|
|
mod tun_runtime;
|
|
#[cfg(all(feature = "tun", mobile))]
|
|
#[path = "runtime_host/tun_mobile.rs"]
|
|
mod tun_runtime;
|
|
|
|
use event_journal::EventJournal;
|
|
#[cfg(feature = "tun")]
|
|
use magic_dns::MagicDnsRuntime;
|
|
use tun_runtime::NativeTunRuntime;
|
|
|
|
pub(super) type HostPacketReceiver = mpsc::Receiver<Vec<u8>>;
|
|
|
|
pub(crate) struct NativeInstanceRuntimeHost {
|
|
global_ctx: ArcGlobalCtx,
|
|
operation: Arc<Mutex<()>>,
|
|
cancel: CancellationToken,
|
|
event_journal: EventJournal,
|
|
tun: NativeTunRuntime,
|
|
}
|
|
|
|
impl NativeInstanceRuntimeHost {
|
|
pub(crate) fn new(
|
|
global_ctx: ArcGlobalCtx,
|
|
peer_packet_receiver: HostPacketReceiver,
|
|
) -> Arc<Self> {
|
|
let cancel = CancellationToken::new();
|
|
let tun = NativeTunRuntime::new(global_ctx.clone(), cancel.clone(), peer_packet_receiver);
|
|
let event_journal = EventJournal::new(&global_ctx);
|
|
Arc::new(Self {
|
|
global_ctx,
|
|
event_journal,
|
|
operation: Arc::new(Mutex::new(())),
|
|
cancel,
|
|
tun,
|
|
})
|
|
}
|
|
|
|
async fn prepare_runtime(
|
|
&self,
|
|
packet_plane: Arc<CorePacketPlane>,
|
|
) -> anyhow::Result<Option<Arc<dyn DhcpIpv4Host>>> {
|
|
self.event_journal.start(self.cancel.clone()).await;
|
|
self.tun.prepare(packet_plane.clone()).await?;
|
|
Ok(Some(
|
|
self.tun.dhcp_host(self.operation.clone(), packet_plane),
|
|
))
|
|
}
|
|
|
|
async fn shutdown_runtime(&self) {
|
|
self.cancel.cancel();
|
|
let _operation = self.operation.lock().await;
|
|
self.event_journal.stop().await;
|
|
self.tun.shutdown().await;
|
|
}
|
|
|
|
fn request_runtime_shutdown(&self) {
|
|
self.cancel.cancel();
|
|
}
|
|
|
|
fn management_events_snapshot(&self) -> Vec<String> {
|
|
self.event_journal.events()
|
|
}
|
|
|
|
pub(crate) fn subscribe_event(&self) -> crate::common::global_ctx::EventBusSubscriber {
|
|
self.global_ctx.subscribe()
|
|
}
|
|
|
|
fn attach_runtime_tun_fd(&self, fd: i32) -> anyhow::Result<()> {
|
|
self.tun.attach_fd(fd)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::common::{
|
|
config::TomlConfig,
|
|
global_ctx::{GlobalCtx, GlobalCtxEvent},
|
|
};
|
|
|
|
#[test]
|
|
fn runtime_host_owns_event_subscription_context() {
|
|
let global_ctx = Arc::new(GlobalCtx::new(TomlConfig::default()));
|
|
let (_packet_sender, packet_receiver) = mpsc::channel(1);
|
|
let runtime_host = NativeInstanceRuntimeHost::new(global_ctx.clone(), packet_receiver);
|
|
let mut events = runtime_host.subscribe_event();
|
|
|
|
global_ctx.issue_event(GlobalCtxEvent::CredentialChanged);
|
|
|
|
assert_eq!(
|
|
events.try_recv().unwrap(),
|
|
GlobalCtxEvent::CredentialChanged
|
|
);
|
|
}
|
|
}
|