refactor(rpc): Centralize RPC service and unify API (#1427)

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.
This commit is contained in:
Mg Pig
2025-10-02 20:30:39 +08:00
committed by GitHub
parent d2efbbef04
commit 841d525913
65 changed files with 1953 additions and 1153 deletions
+91
View File
@@ -0,0 +1,91 @@
use std::sync::Arc;
use crate::{
instance_manager::NetworkInstanceManager,
proto::{
api::instance::{self, ListPeerRequest, ListPeerResponse, PeerManageRpc},
rpc_types::controller::BaseController,
},
};
#[derive(Clone)]
pub struct PeerManageRpcService {
instance_manager: Arc<NetworkInstanceManager>,
}
impl PeerManageRpcService {
pub fn new(instance_manager: Arc<NetworkInstanceManager>) -> Self {
Self { instance_manager }
}
}
#[async_trait::async_trait]
impl PeerManageRpc for PeerManageRpcService {
type Controller = BaseController;
async fn list_peer(
&self,
ctrl: Self::Controller,
req: ListPeerRequest,
) -> crate::proto::rpc_types::error::Result<ListPeerResponse> {
super::get_instance_service(&self.instance_manager, &req.instance)?
.get_peer_manage_service()
.list_peer(ctrl, req)
.await
}
async fn list_route(
&self,
ctrl: Self::Controller,
req: crate::proto::api::instance::ListRouteRequest,
) -> crate::proto::rpc_types::error::Result<instance::ListRouteResponse> {
super::get_instance_service(&self.instance_manager, &req.instance)?
.get_peer_manage_service()
.list_route(ctrl, req)
.await
}
async fn dump_route(
&self,
ctrl: Self::Controller,
req: crate::proto::api::instance::DumpRouteRequest,
) -> crate::proto::rpc_types::error::Result<instance::DumpRouteResponse> {
super::get_instance_service(&self.instance_manager, &req.instance)?
.get_peer_manage_service()
.dump_route(ctrl, req)
.await
}
async fn list_foreign_network(
&self,
ctrl: Self::Controller,
req: crate::proto::api::instance::ListForeignNetworkRequest,
) -> crate::proto::rpc_types::error::Result<instance::ListForeignNetworkResponse> {
super::get_instance_service(&self.instance_manager, &req.instance)?
.get_peer_manage_service()
.list_foreign_network(ctrl, req)
.await
}
async fn list_global_foreign_network(
&self,
ctrl: Self::Controller,
req: crate::proto::api::instance::ListGlobalForeignNetworkRequest,
) -> crate::proto::rpc_types::error::Result<instance::ListGlobalForeignNetworkResponse> {
super::get_instance_service(&self.instance_manager, &req.instance)?
.get_peer_manage_service()
.list_global_foreign_network(ctrl, req)
.await
}
async fn show_node_info(
&self,
ctrl: Self::Controller,
req: crate::proto::api::instance::ShowNodeInfoRequest,
) -> crate::proto::rpc_types::error::Result<instance::ShowNodeInfoResponse> {
super::get_instance_service(&self.instance_manager, &req.instance)?
.get_peer_manage_service()
.show_node_info(ctrl, req)
.await
}
}