completed migrating to new proto structure

This commit is contained in:
Noor 2025-02-06 09:42:24 +00:00
parent afaa478f46
commit d5667e4cd1
Signed by: noormohammedb
GPG Key ID: E424C39E19EFD7DF
4 changed files with 21 additions and 34 deletions

2
Cargo.lock generated

@ -290,7 +290,7 @@ dependencies = [
[[package]]
name = "detee-shared"
version = "0.1.0"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared#42443b816299afb0da6493b35165f8ce7558d717"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#df3a4631dd919e0cb35f6238f91f262c999c93b8"
dependencies = [
"base64",
"prost",

@ -16,7 +16,7 @@ anyhow = "1.0.95"
rand = "0.8.5"
tokio-stream = "0.1.17"
detee-shared = { git = "ssh://git@gitea.detee.cloud/noormohammedb/detee-shared" }
detee-shared = { git = "ssh://git@gitea.detee.cloud/noormohammedb/detee-shared", branch = "stable_01" }
# detee-shared = { path = "../detee-shared" }
log = "0.4.25"
serde = "1.0.217"

@ -1,13 +1,13 @@
use anyhow::Result;
use detee_shared::pb::brain::brain_app_daemon_client::BrainAppDaemonClient;
use detee_shared::pb::brain::daemon_message_app;
use detee_shared::pb::brain::{
AppContract, BrainMessageApp, DaemonMessageApp, Pubkey, RegisterAppNodeReq,
};
use anyhow::Result;
use tokio::sync::mpsc::Receiver;
use tokio::sync::mpsc::Sender;
use tokio::task::JoinSet;
// use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::StreamExt;
use tonic::transport::Channel;
@ -62,11 +62,11 @@ pub async fn connect_and_run(conn_data: ConnectionData) -> Result<()> {
let mut streaming_tasks = JoinSet::new();
streaming_tasks.spawn(receive_messages(client.clone(), conn_data.brain_msg_tx));
// streaming_tasks.spawn(send_messages(
// client.clone(),
// conn_data.daemon_msg_rx,
// conn_data.daemon_msg_tx,
// ));
streaming_tasks.spawn(send_messages(
client.clone(),
conn_data.daemon_msg_rx,
conn_data.daemon_msg_tx,
));
let task_output = streaming_tasks.join_next().await;
println!("exiting: {task_output:?}");
@ -97,22 +97,19 @@ pub async fn receive_messages(
Ok(())
}
/*
pub async fn send_messages(
mut client: BrainSgxDaemonClient<Channel>,
rx: Receiver<DaemonMessage>,
tx: Sender<DaemonMessage>,
mut client: BrainAppDaemonClient<Channel>,
rx: Receiver<DaemonMessageApp>,
tx: Sender<DaemonMessageApp>,
) -> Result<()> {
let pubkey = NODE_PUBKEY.to_string();
let rx_stream = ReceiverStream::new(rx);
tx.send(DaemonMessage {
msg: Some(Msg::Pubkey(Pubkey { pubkey })),
tx.send(DaemonMessageApp {
msg: Some(daemon_message_app::Msg::Pubkey(pubkey)),
})
.await?;
client.daemon_messages(rx_stream).await?;
log::debug!("daemon_messages is about to exit");
Ok(())
}
*/

@ -70,24 +70,14 @@ impl ContainerHandler {
Some(brain_message_app::Msg::NewAppReq(msg)) => {
self.handle_new_container_req(msg.into()).await;
}
/*
Some(brain_message::Msg::DeleteContainer(msg)) => {
let container_id = msg.uuid.unwrap_or_default();
self.handle_del_container_req(container_id).await;
Some(brain_message_app::Msg::DeleteAppReq(msg)) => {
let app_id = msg.uuid;
self.handle_del_container_req(app_id).await;
}
Some(brain_message::Msg::ListContainer(msg)) => {
dbg!(&msg);
}
*/
None => {
log::error!("Brain disconnected");
break;
}
_ => {
todo!("wip")
}
}
}
}
@ -104,7 +94,7 @@ impl ContainerHandler {
Ok(unarchive_dir) => unarchive_dir,
Err(e) => {
let res = DaemonMessageApp {
msg: Some(daemon_message_app::Msg::NewAppResp(NewAppRes {
msg: Some(daemon_message_app::Msg::NewAppRes(NewAppRes {
uuid: new_container_req.uuid,
status: "failed".to_string(),
error: e.to_string(),
@ -126,7 +116,7 @@ impl ContainerHandler {
Ok(mapped_ports) => mapped_ports.into_iter().map(MappedPort::from).collect(),
Err(e) => {
let res = DaemonMessageApp {
msg: Some(daemon_message_app::Msg::NewAppResp(NewAppRes {
msg: Some(daemon_message_app::Msg::NewAppRes(NewAppRes {
uuid: container_uuid,
status: "failed".to_string(),
error: e.to_string(),
@ -141,7 +131,7 @@ impl ContainerHandler {
};
let res = DaemonMessageApp {
msg: Some(daemon_message_app::Msg::NewAppResp(NewAppRes {
msg: Some(daemon_message_app::Msg::NewAppRes(NewAppRes {
uuid: container_uuid,
status: "Success".to_string(),
error: "".to_string(),