mirror of
https://github.com/EasyTier/EasyTier.git
synced 2024-11-16 11:42:27 +08:00
add verbose cli mode; add list foreign network (#156)
Some checks are pending
EasyTier Core / pre_job (push) Waiting to run
EasyTier Core / build (macos-latest, aarch64-apple-darwin) (push) Blocked by required conditions
EasyTier Core / build (macos-latest, x86_64-apple-darwin) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, aarch64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, arm-unknown-linux-musleabi) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, arm-unknown-linux-musleabihf) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, armv7-unknown-linux-musleabi) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, armv7-unknown-linux-musleabihf) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, mips-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, mipsel-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, x86_64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (windows-latest, x86_64-pc-windows-msvc) (push) Blocked by required conditions
EasyTier Core / core-result (push) Blocked by required conditions
EasyTier GUI / pre_job (push) Waiting to run
EasyTier GUI / build-gui (aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Blocked by required conditions
EasyTier GUI / build-gui (aarch64-unknown-linux-gnu, ubuntu-latest, aarch64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier GUI / build-gui (x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Blocked by required conditions
EasyTier GUI / build-gui (x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Blocked by required conditions
EasyTier GUI / build-gui (x86_64-unknown-linux-gnu, ubuntu-latest, x86_64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier GUI / gui-result (push) Blocked by required conditions
EasyTier Test / pre_job (push) Waiting to run
EasyTier Test / test (push) Blocked by required conditions
Some checks are pending
EasyTier Core / pre_job (push) Waiting to run
EasyTier Core / build (macos-latest, aarch64-apple-darwin) (push) Blocked by required conditions
EasyTier Core / build (macos-latest, x86_64-apple-darwin) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, aarch64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, arm-unknown-linux-musleabi) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, arm-unknown-linux-musleabihf) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, armv7-unknown-linux-musleabi) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, armv7-unknown-linux-musleabihf) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, mips-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, mipsel-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (ubuntu-latest, x86_64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (windows-latest, x86_64-pc-windows-msvc) (push) Blocked by required conditions
EasyTier Core / core-result (push) Blocked by required conditions
EasyTier GUI / pre_job (push) Waiting to run
EasyTier GUI / build-gui (aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Blocked by required conditions
EasyTier GUI / build-gui (aarch64-unknown-linux-gnu, ubuntu-latest, aarch64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier GUI / build-gui (x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Blocked by required conditions
EasyTier GUI / build-gui (x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Blocked by required conditions
EasyTier GUI / build-gui (x86_64-unknown-linux-gnu, ubuntu-latest, x86_64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier GUI / gui-result (push) Blocked by required conditions
EasyTier Test / pre_job (push) Waiting to run
EasyTier Test / test (push) Blocked by required conditions
This commit is contained in:
parent
513e4cacc9
commit
24143cbf1c
|
@ -81,10 +81,20 @@ message DumpRouteRequest {}
|
|||
|
||||
message DumpRouteResponse { string result = 1; }
|
||||
|
||||
message ListForeignNetworkRequest {}
|
||||
|
||||
message ForeignNetworkEntryPb { repeated PeerInfo peers = 1; }
|
||||
|
||||
message ListForeignNetworkResponse {
|
||||
map<string, ForeignNetworkEntryPb> foreign_networks = 1;
|
||||
}
|
||||
|
||||
service PeerManageRpc {
|
||||
rpc ListPeer(ListPeerRequest) returns (ListPeerResponse);
|
||||
rpc ListRoute(ListRouteRequest) returns (ListRouteResponse);
|
||||
rpc DumpRoute(DumpRouteRequest) returns (DumpRouteResponse);
|
||||
rpc ListForeignNetwork(ListForeignNetworkRequest)
|
||||
returns (ListForeignNetworkResponse);
|
||||
}
|
||||
|
||||
enum ConnectorStatus {
|
||||
|
|
|
@ -33,6 +33,9 @@ struct Cli {
|
|||
#[arg(short = 'p', long, default_value = "127.0.0.1:15888")]
|
||||
rpc_portal: SocketAddr,
|
||||
|
||||
#[arg(short, long, default_value = "false", help = "verbose output")]
|
||||
verbose: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
sub_command: SubCommand,
|
||||
}
|
||||
|
@ -49,12 +52,6 @@ enum SubCommand {
|
|||
|
||||
#[derive(Args, Debug)]
|
||||
struct PeerArgs {
|
||||
#[arg(short, long)]
|
||||
ipv4: Option<String>,
|
||||
|
||||
#[arg(short, long)]
|
||||
peers: Vec<String>,
|
||||
|
||||
#[command(subcommand)]
|
||||
sub_command: Option<PeerSubCommand>,
|
||||
}
|
||||
|
@ -70,6 +67,7 @@ enum PeerSubCommand {
|
|||
Add,
|
||||
Remove,
|
||||
List(PeerListArgs),
|
||||
ListForeign,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
|
@ -113,6 +111,7 @@ enum Error {
|
|||
|
||||
struct CommandHandler {
|
||||
addr: String,
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
impl CommandHandler {
|
||||
|
@ -204,6 +203,11 @@ impl CommandHandler {
|
|||
|
||||
let mut items: Vec<PeerTableItem> = vec![];
|
||||
let peer_routes = self.list_peer_route_pair().await?;
|
||||
if self.verbose {
|
||||
println!("{:#?}", peer_routes);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for p in peer_routes {
|
||||
items.push(p.into());
|
||||
}
|
||||
|
@ -224,6 +228,46 @@ impl CommandHandler {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_foreign_network_list(&self) -> Result<(), Error> {
|
||||
let mut client = self.get_peer_manager_client().await?;
|
||||
let request = tonic::Request::new(ListForeignNetworkRequest::default());
|
||||
let response = client.list_foreign_network(request).await?;
|
||||
let network_map = response.into_inner();
|
||||
if self.verbose {
|
||||
println!("{:#?}", network_map);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for (idx, (k, v)) in network_map.foreign_networks.iter().enumerate() {
|
||||
println!("{} Network Name: {}", idx + 1, k);
|
||||
for peer in v.peers.iter() {
|
||||
println!(
|
||||
" peer_id: {}, peer_conn_count: {}, conns: [ {} ]",
|
||||
peer.peer_id,
|
||||
peer.conns.len(),
|
||||
peer.conns
|
||||
.iter()
|
||||
.map(|conn| format!(
|
||||
"remote_addr: {}, rx_bytes: {}, tx_bytes: {}, latency_us: {}",
|
||||
conn.tunnel
|
||||
.as_ref()
|
||||
.map(|t| t.remote_addr.clone())
|
||||
.unwrap_or_default(),
|
||||
conn.stats.as_ref().map(|s| s.rx_bytes).unwrap_or_default(),
|
||||
conn.stats.as_ref().map(|s| s.tx_bytes).unwrap_or_default(),
|
||||
conn.stats
|
||||
.as_ref()
|
||||
.map(|s| s.latency_us)
|
||||
.unwrap_or_default(),
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join("; ")
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_route_list(&self) -> Result<(), Error> {
|
||||
#[derive(tabled::Tabled)]
|
||||
struct RouteTableItem {
|
||||
|
@ -292,6 +336,7 @@ async fn main() -> Result<(), Error> {
|
|||
let cli = Cli::parse();
|
||||
let handler = CommandHandler {
|
||||
addr: format!("http://{}:{}", cli.rpc_portal.ip(), cli.rpc_portal.port()),
|
||||
verbose: cli.verbose,
|
||||
};
|
||||
|
||||
match cli.sub_command {
|
||||
|
@ -309,6 +354,9 @@ async fn main() -> Result<(), Error> {
|
|||
handler.handle_peer_list(&peer_args).await?;
|
||||
}
|
||||
}
|
||||
Some(PeerSubCommand::ListForeign) => {
|
||||
handler.handle_foreign_network_list().await?;
|
||||
}
|
||||
None => {
|
||||
handler.handle_peer_list(&peer_args).await?;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ use crate::{
|
|||
global_ctx::{ArcGlobalCtx, GlobalCtxEvent, NetworkIdentity},
|
||||
PeerId,
|
||||
},
|
||||
rpc::{ForeignNetworkEntryPb, ListForeignNetworkResponse, PeerInfo},
|
||||
tunnel::packet_def::{PacketType, ZCPacket},
|
||||
};
|
||||
|
||||
|
@ -306,15 +307,16 @@ impl ForeignNetworkManager {
|
|||
self.register_peer_rpc_service().await;
|
||||
}
|
||||
|
||||
pub async fn list_foreign_networks(&self) -> DashMap<String, Vec<PeerId>> {
|
||||
let ret = DashMap::new();
|
||||
for item in self.data.network_peer_maps.iter() {
|
||||
let network_name = item.key().clone();
|
||||
ret.insert(network_name, vec![]);
|
||||
}
|
||||
pub async fn list_foreign_networks(&self) -> ListForeignNetworkResponse {
|
||||
let mut ret = ListForeignNetworkResponse::default();
|
||||
let networks = self
|
||||
.data
|
||||
.network_peer_maps
|
||||
.iter()
|
||||
.map(|v| v.key().clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for mut n in ret.iter_mut() {
|
||||
let network_name = n.key().clone();
|
||||
for network_name in networks {
|
||||
let Some(item) = self
|
||||
.data
|
||||
.network_peer_maps
|
||||
|
@ -323,7 +325,16 @@ impl ForeignNetworkManager {
|
|||
else {
|
||||
continue;
|
||||
};
|
||||
n.value_mut().extend(item.peer_map.list_peers().await);
|
||||
|
||||
let mut entry = ForeignNetworkEntryPb::default();
|
||||
for peer in item.peer_map.list_peers().await {
|
||||
let mut peer_info = PeerInfo::default();
|
||||
peer_info.peer_id = peer;
|
||||
peer_info.conns = item.peer_map.list_peer_conns(peer).await.unwrap_or(vec![]);
|
||||
entry.peers.push(peer_info);
|
||||
}
|
||||
|
||||
ret.foreign_networks.insert(network_name, entry);
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
@ -379,6 +390,13 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(1, pma_net1.list_routes().await.len());
|
||||
assert_eq!(1, pmb_net1.list_routes().await.len());
|
||||
|
||||
let rpc_resp = pm_center
|
||||
.get_foreign_network_manager()
|
||||
.list_foreign_networks()
|
||||
.await;
|
||||
assert_eq!(1, rpc_resp.foreign_networks.len());
|
||||
assert_eq!(2, rpc_resp.foreign_networks["net1"].peers.len());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -484,6 +502,14 @@ mod tests {
|
|||
.len()
|
||||
);
|
||||
|
||||
let rpc_resp = pm_center
|
||||
.get_foreign_network_manager()
|
||||
.list_foreign_networks()
|
||||
.await;
|
||||
assert_eq!(2, rpc_resp.foreign_networks.len());
|
||||
assert_eq!(3, rpc_resp.foreign_networks["net1"].peers.len());
|
||||
assert_eq!(2, rpc_resp.foreign_networks["net2"].peers.len());
|
||||
|
||||
drop(pmb_net2);
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
assert_eq!(
|
||||
|
|
|
@ -2,7 +2,8 @@ use std::sync::Arc;
|
|||
|
||||
use crate::rpc::{
|
||||
cli::PeerInfo, peer_manage_rpc_server::PeerManageRpc, DumpRouteRequest, DumpRouteResponse,
|
||||
ListPeerRequest, ListPeerResponse, ListRouteRequest, ListRouteResponse,
|
||||
ListForeignNetworkRequest, ListForeignNetworkResponse, ListPeerRequest, ListPeerResponse,
|
||||
ListRouteRequest, ListRouteResponse,
|
||||
};
|
||||
use tonic::{Request, Response, Status};
|
||||
|
||||
|
@ -68,4 +69,16 @@ impl PeerManageRpc for PeerManagerRpcService {
|
|||
reply.result = self.peer_manager.dump_route().await;
|
||||
Ok(Response::new(reply))
|
||||
}
|
||||
|
||||
async fn list_foreign_network(
|
||||
&self,
|
||||
_request: Request<ListForeignNetworkRequest>, // Accept request of type HelloRequest
|
||||
) -> Result<Response<ListForeignNetworkResponse>, Status> {
|
||||
let reply = self
|
||||
.peer_manager
|
||||
.get_foreign_network_manager()
|
||||
.list_foreign_networks()
|
||||
.await;
|
||||
Ok(Response::new(reply))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user