Sgx daemon grpc integration

This commit is contained in:
Noor 2025-01-29 17:58:43 +05:30
parent 3e4672e9e4
commit b1258ac7c7
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
3 changed files with 74 additions and 12 deletions

2
Cargo.lock generated

@ -329,7 +329,7 @@ dependencies = [
[[package]]
name = "detee-shared"
version = "0.1.0"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared#96501831509839a45d91ac793af905006b7612d5"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared#3e783b11bab6894b6f98bd3c6ce44e8bf5b1f78b"
dependencies = [
"base64",
"prost",

@ -16,8 +16,8 @@ use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
use tonic::{Request, Response, Status, Streaming};
use detee_shared::pb::daemon::{
brain_sgx_cli_server::BrainSgxCli, ContainerFilters, ContainerInspectResp, ContainerListResp,
DeleteContainerRes, NewContainerRes,
brain_sgx_cli_server::BrainSgxCli, brain_sgx_daemon_server::BrainSgxDaemon, ContainerFilters,
ContainerListResp, DeleteContainerRes, NewContainerRes,
};
pub struct BrainDaemonMock {
@ -50,6 +50,16 @@ impl BrainSgxCliMock {
}
}
pub struct BrainSgxDaemonMock {
data: Arc<BrainData>,
}
impl BrainSgxDaemonMock {
pub fn new(data: Arc<BrainData>) -> Self {
Self { data }
}
}
#[tonic::async_trait]
impl BrainDaemon for BrainDaemonMock {
type RegisterNodeStream = Pin<Box<dyn Stream<Item = Result<Contract, Status>> + Send>>;
@ -284,15 +294,6 @@ impl BrainSgxCli for BrainSgxCliMock {
}))
}
async fn inspect_container(
&self,
req: tonic::Request<detee_shared::pb::shared::Uuid>,
) -> Result<tonic::Response<ContainerInspectResp>, Status> {
dbg!(req);
Ok(Response::new(ContainerInspectResp {
..Default::default()
}))
}
async fn list_containers(
&self,
req: tonic::Request<ContainerFilters>,
@ -302,4 +303,61 @@ impl BrainSgxCli for BrainSgxCliMock {
..Default::default()
}))
}
// async fn inspect_container(
// &self,
// req: tonic::Request<detee_shared::pb::shared::Uuid>,
// ) -> Result<tonic::Response<ContainerInspectResp>, Status> {
// dbg!(req);
// Ok(Response::new(ContainerInspectResp {
// ..Default::default()
// }))
// }
}
#[tonic::async_trait]
impl BrainSgxDaemon for BrainSgxDaemonMock {
type RegisterNodeStream = Pin<
Box<dyn Stream<Item = Result<detee_shared::pb::shared::ContainerContracts, Status>> + Send>,
>;
type BrainMessagesStream =
Pin<Box<dyn Stream<Item = Result<detee_shared::pb::daemon::BrainMessage, Status>> + Send>>;
async fn register_node(
&self,
req: tonic::Request<detee_shared::pb::shared::RegisterNodeReq>,
) -> Result<tonic::Response<Self::RegisterNodeStream>, Status> {
dbg!(req);
let (tx, rx) = mpsc::channel(6);
tokio::spawn(async move {
for _ in 0..5 {
let _ = tx
.send(detee_shared::pb::shared::ContainerContracts {
..Default::default()
})
.await;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
}
});
let output_stream = ReceiverStream::new(rx).map(|msg| Ok(msg));
Ok(Response::new(Box::pin(output_stream)))
}
async fn daemon_messages(
&self,
req: tonic::Request<Streaming<detee_shared::pb::daemon::DaemonMessage>>,
) -> Result<tonic::Response<detee_shared::pb::shared::Empty>, Status> {
dbg!(req);
Ok(Response::new(detee_shared::pb::shared::Empty {}))
}
async fn brain_messages(
&self,
req: tonic::Request<detee_shared::pb::shared::Pubkey>,
) -> Result<tonic::Response<Self::BrainMessagesStream>, Status> {
dbg!(req);
Ok(Response::new(
Box::pin(tokio_stream::empty()) as Self::BrainMessagesStream
))
}
}

@ -2,11 +2,13 @@ mod data;
mod grpc;
use data::BrainData;
use detee_shared::pb::daemon::brain_sgx_daemon_server::BrainSgxDaemonServer;
use grpc::snp_proto::brain_cli_server::BrainCliServer;
use grpc::snp_proto::brain_daemon_server::BrainDaemonServer;
use grpc::BrainCliMock;
use grpc::BrainDaemonMock;
use grpc::BrainSgxCliMock;
use grpc::BrainSgxDaemonMock;
use std::sync::Arc;
use tonic::transport::Server;
@ -31,11 +33,13 @@ async fn main() {
let cli_server = BrainCliServer::new(BrainCliMock::new(data.clone()));
let sgx_cli_server = BrainSgxCliServer::new(BrainSgxCliMock::new(data.clone()));
let sgx_daemon_server = BrainSgxDaemonServer::new(BrainSgxDaemonMock::new(data.clone()));
Server::builder()
.add_service(daemon_server)
.add_service(cli_server)
.add_service(sgx_cli_server)
.add_service(sgx_daemon_server)
.serve(addr)
.await
.unwrap();