mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-14 21:57:24 +08:00
feat/web (Patchset 2) (#444)
This patch implement a restful server without any auth.
usage:
```bash
# run easytier-web, which acts as an gateway and registry for all easytier-core
$> easytier-web
# run easytier-core and connect to easytier-web with a token
$> easytier-core --config-server udp://127.0.0.1:22020/fdsafdsa
# use restful api to list session
$> curl -H "Content-Type: application/json" -X GET 127.0.0.1:11211/api/v1/sessions
[{"token":"fdsafdsa","client_url":"udp://127.0.0.1:48915","machine_id":"de3f5b8f-0f2f-d9d0-fb30-a2ac8951d92f"}]%
# use restful api to run a network instance
$> curl -H "Content-Type: application/json" -X POST 127.0.0.1:11211/api/v1/network/de3f5b8f-0f2f-d9d0-fb30-a2ac8951d92f -d '{"config": "listeners = [\"udp://0.0.0.0:12344\"]"}'
# use restful api to get network instance info
$> curl -H "Content-Type: application/json" -X GET 127.0.0.1:11211/api/v1/network/de3f5b8f-0f2f-d9d0-fb30-a2ac8951d92f/65437e50-b286-4098-a624-74429f2cb839
```
This commit is contained in:
@@ -12,27 +12,12 @@ use crate::{
|
||||
},
|
||||
instance::instance::Instance,
|
||||
peers::rpc_service::PeerManagerRpcService,
|
||||
proto::{
|
||||
cli::{PeerInfo, Route},
|
||||
common::StunInfo,
|
||||
peer_rpc::GetIpListResponse,
|
||||
},
|
||||
utils::{list_peer_route_pair, PeerRoutePair},
|
||||
proto::cli::{list_peer_route_pair, PeerInfo, Route},
|
||||
};
|
||||
use chrono::{DateTime, Local};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::{sync::broadcast, task::JoinSet};
|
||||
|
||||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct MyNodeInfo {
|
||||
pub virtual_ipv4: String,
|
||||
pub hostname: String,
|
||||
pub version: String,
|
||||
pub ips: GetIpListResponse,
|
||||
pub stun_info: StunInfo,
|
||||
pub listeners: Vec<String>,
|
||||
pub vpn_portal_cfg: Option<String>,
|
||||
}
|
||||
pub type MyNodeInfo = crate::proto::web::MyNodeInfo;
|
||||
|
||||
struct EasyTierData {
|
||||
events: RwLock<VecDeque<(DateTime<Local>, GlobalCtxEvent)>>,
|
||||
@@ -164,18 +149,15 @@ impl EasyTierLauncher {
|
||||
global_ctx_c.get_flags().dev_name.clone();
|
||||
|
||||
let node_info = MyNodeInfo {
|
||||
virtual_ipv4: global_ctx_c
|
||||
.get_ipv4()
|
||||
.map(|x| x.to_string())
|
||||
.unwrap_or_default(),
|
||||
virtual_ipv4: global_ctx_c.get_ipv4().map(|x| x.address().into()),
|
||||
hostname: global_ctx_c.get_hostname(),
|
||||
version: EASYTIER_VERSION.to_string(),
|
||||
ips: global_ctx_c.get_ip_collector().collect_ip_addrs().await,
|
||||
stun_info: global_ctx_c.get_stun_info_collector().get_stun_info(),
|
||||
ips: Some(global_ctx_c.get_ip_collector().collect_ip_addrs().await),
|
||||
stun_info: Some(global_ctx_c.get_stun_info_collector().get_stun_info()),
|
||||
listeners: global_ctx_c
|
||||
.get_running_listeners()
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
vpn_portal_cfg: Some(
|
||||
vpn_portal
|
||||
@@ -311,18 +293,7 @@ impl Drop for EasyTierLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct NetworkInstanceRunningInfo {
|
||||
pub dev_name: String,
|
||||
pub my_node_info: MyNodeInfo,
|
||||
pub events: Vec<(DateTime<Local>, GlobalCtxEvent)>,
|
||||
pub node_info: MyNodeInfo,
|
||||
pub routes: Vec<Route>,
|
||||
pub peers: Vec<PeerInfo>,
|
||||
pub peer_route_pairs: Vec<PeerRoutePair>,
|
||||
pub running: bool,
|
||||
pub error_msg: Option<String>,
|
||||
}
|
||||
pub type NetworkInstanceRunningInfo = crate::proto::web::NetworkInstanceRunningInfo;
|
||||
|
||||
pub struct NetworkInstance {
|
||||
config: TomlConfigLoader,
|
||||
@@ -362,9 +333,13 @@ impl NetworkInstance {
|
||||
|
||||
Some(NetworkInstanceRunningInfo {
|
||||
dev_name: launcher.get_dev_name(),
|
||||
my_node_info: launcher.get_node_info(),
|
||||
events: launcher.get_events(),
|
||||
node_info: launcher.get_node_info(),
|
||||
my_node_info: Some(launcher.get_node_info()),
|
||||
events: launcher
|
||||
.get_events()
|
||||
.iter()
|
||||
.map(|(t, e)| (t.to_string(), format!("{:?}", e)))
|
||||
.collect(),
|
||||
node_info: Some(launcher.get_node_info()),
|
||||
routes,
|
||||
peers,
|
||||
peer_route_pairs,
|
||||
|
||||
Reference in New Issue
Block a user