mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-10-09 20:26:15 -08:00
This change introduces a major refactoring of the RPC service layer to improve modularity, unify the API, and simplify the overall architecture. Key changes: - Replaced per-network-instance RPC services with a single global RPC server, reducing resource usage and simplifying management. - All clients (CLI, Web UI, etc.) now interact with EasyTier core through a unified RPC entrypoint, enabling consistent authentication and control. - RPC implementation logic has been moved to `easytier/src/rpc_service/` and organized by functionality (e.g., `instance_manage.rs`, `peer_manage.rs`, `config.rs`) for better maintainability. - Standardized Protobuf API definitions under `easytier/src/proto/` with an `api_` prefix (e.g., `cli.proto` → `api_instance.proto`) to provide a consistent interface. - CLI commands now require explicit `--instance-id` or `--instance-name` when multiple network instances are running; the parameter is optional when only one instance exists. BREAKING CHANGE: RPC portal configuration (`rpc_portal` and `rpc_portal_whitelist`) has been removed from per-instance configs and the Web UI. The RPC listen address must now be specified globally via the `--rpc-portal` command-line flag or the `ET_RPC_PORTAL` environment variable, as there is only one RPC service for the entire application.
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
use std::sync::Arc;
|
|
|
|
use crate::{
|
|
common::scoped_task::ScopedTask, instance_manager::NetworkInstanceManager,
|
|
tunnel::TunnelConnector,
|
|
};
|
|
|
|
pub mod controller;
|
|
pub mod session;
|
|
|
|
pub struct WebClient {
|
|
controller: Arc<controller::Controller>,
|
|
tasks: ScopedTask<()>,
|
|
}
|
|
|
|
impl WebClient {
|
|
pub fn new<T: TunnelConnector + 'static, S: ToString, H: ToString>(
|
|
connector: T,
|
|
token: S,
|
|
hostname: H,
|
|
manager: Arc<NetworkInstanceManager>,
|
|
) -> Self {
|
|
let controller = Arc::new(controller::Controller::new(
|
|
token.to_string(),
|
|
hostname.to_string(),
|
|
manager,
|
|
));
|
|
|
|
let controller_clone = controller.clone();
|
|
let tasks = ScopedTask::from(tokio::spawn(async move {
|
|
Self::routine(controller_clone, Box::new(connector)).await;
|
|
}));
|
|
|
|
WebClient { controller, tasks }
|
|
}
|
|
|
|
async fn routine(
|
|
controller: Arc<controller::Controller>,
|
|
mut connector: Box<dyn TunnelConnector>,
|
|
) {
|
|
loop {
|
|
let conn = match connector.connect().await {
|
|
Ok(conn) => conn,
|
|
Err(e) => {
|
|
println!(
|
|
"Failed to connect to the server ({}), retrying in 5 seconds...",
|
|
e
|
|
);
|
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
|
continue;
|
|
}
|
|
};
|
|
|
|
println!("Successfully connected to {:?}", conn.info());
|
|
|
|
let mut session = session::Session::new(conn, controller.clone());
|
|
session.wait().await;
|
|
}
|
|
}
|
|
}
|