make all frontend functions works (#466)

This commit is contained in:
Sijie.Sun
2024-11-10 11:06:58 +08:00
committed by GitHub
parent e948dbfcc1
commit 88e6de9d7e
36 changed files with 1039 additions and 483 deletions

View File

@@ -6,8 +6,9 @@ use easytier::{
rpc_impl::bidirect::BidirectRpcManager,
rpc_types::{self, controller::BaseController},
web::{
HeartbeatRequest, HeartbeatResponse, RunNetworkInstanceRequest, WebClientService,
WebClientServiceClientFactory, WebServerService, WebServerServiceServer,
HeartbeatRequest, HeartbeatResponse, NetworkConfig, RunNetworkInstanceRequest,
WebClientService, WebClientServiceClientFactory, WebServerService,
WebServerServiceServer,
},
},
tunnel::Tunnel,
@@ -160,7 +161,13 @@ impl Session {
);
return;
}
let req = req.unwrap();
if req.machine_id.is_none() {
tracing::warn!(?req, "Machine id is not set, ignore");
continue;
}
let running_inst_ids = req
.running_network_instances
.iter()
@@ -187,7 +194,11 @@ impl Session {
}
};
let local_configs = match storage.db.list_network_configs(user_id, true).await {
let local_configs = match storage
.db
.list_network_configs(user_id, Some(req.machine_id.unwrap().into()), true)
.await
{
Ok(configs) => configs,
Err(e) => {
tracing::error!("Failed to list network configs, error: {:?}", e);
@@ -206,7 +217,9 @@ impl Session {
BaseController::default(),
RunNetworkInstanceRequest {
inst_id: Some(c.network_instance_id.clone().into()),
config: c.network_config,
config: Some(
serde_json::from_str::<NetworkConfig>(&c.network_config).unwrap(),
),
},
)
.await;

View File

@@ -16,7 +16,7 @@ pub struct StorageToken {
pub struct StorageInner {
// some map for indexing
pub token_clients_map: DashMap<String, DashSet<url::Url>>,
pub machine_client_url_map: DashMap<uuid::Uuid, url::Url>,
pub machine_client_url_map: DashMap<uuid::Uuid, DashSet<url::Url>>,
pub db: Db,
}
@@ -51,7 +51,9 @@ impl Storage {
self.0
.machine_client_url_map
.insert(stoken.machine_id, stoken.client_url.clone());
.entry(stoken.machine_id)
.or_insert_with(DashSet::new)
.insert(stoken.client_url.clone());
}
pub fn remove_client(&self, stoken: &StorageToken) {
@@ -60,7 +62,12 @@ impl Storage {
set.is_empty()
});
self.0.machine_client_url_map.remove(&stoken.machine_id);
self.0
.machine_client_url_map
.remove_if(&stoken.machine_id, |_, set| {
set.remove(&stoken.client_url);
set.is_empty()
});
}
pub fn weak_ref(&self) -> WeakRefStorage {
@@ -71,7 +78,8 @@ impl Storage {
self.0
.machine_client_url_map
.get(&machine_id)
.map(|url| url.clone())
.map(|url| url.iter().next().map(|url| url.clone()))
.flatten()
}
pub fn list_token_clients(&self, token: &str) -> Vec<url::Url> {