mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-08 05:29:47 +00:00
841d525913
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.
53 lines
1.6 KiB
Rust
53 lines
1.6 KiB
Rust
// 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.
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
use crate::proto::api::instance::PeerInfo;
|
|
use crate::proto::peer_rpc::{DirectConnectedPeerInfo, PeerInfoForGlobalMap};
|
|
|
|
pub mod instance;
|
|
mod server;
|
|
|
|
#[derive(thiserror::Error, Debug, serde::Deserialize, serde::Serialize)]
|
|
pub enum Error {
|
|
#[error("Digest not match, need provide full peer info to center server.")]
|
|
DigestMismatch,
|
|
#[error("Not center server")]
|
|
NotCenterServer,
|
|
#[error("Instance shutdown")]
|
|
Shutdown,
|
|
}
|
|
|
|
pub type Digest = u64;
|
|
|
|
impl From<Vec<PeerInfo>> for PeerInfoForGlobalMap {
|
|
fn from(peers: Vec<PeerInfo>) -> Self {
|
|
let mut peer_map = BTreeMap::new();
|
|
for peer in peers {
|
|
let Some(min_lat) = peer
|
|
.conns
|
|
.iter()
|
|
.map(|conn| conn.stats.as_ref().unwrap().latency_us)
|
|
.min()
|
|
else {
|
|
continue;
|
|
};
|
|
|
|
let dp_info = DirectConnectedPeerInfo {
|
|
latency_ms: std::cmp::max(1, (min_lat as u32 / 1000) as i32),
|
|
};
|
|
|
|
// sort conn info so hash result is stable
|
|
peer_map.insert(peer.peer_id, dp_info);
|
|
}
|
|
PeerInfoForGlobalMap {
|
|
direct_peers: peer_map,
|
|
}
|
|
}
|
|
}
|