diff --git a/Cargo.lock b/Cargo.lock index bcf8af9..38d60b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/src/grpc.rs b/src/grpc.rs index 90a236e..7b4c1d5 100644 --- a/src/grpc.rs +++ b/src/grpc.rs @@ -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, +} + +impl BrainSgxDaemonMock { + pub fn new(data: Arc) -> Self { + Self { data } + } +} + #[tonic::async_trait] impl BrainDaemon for BrainDaemonMock { type RegisterNodeStream = Pin> + Send>>; @@ -284,15 +294,6 @@ impl BrainSgxCli for BrainSgxCliMock { })) } - async fn inspect_container( - &self, - req: tonic::Request, - ) -> Result, Status> { - dbg!(req); - Ok(Response::new(ContainerInspectResp { - ..Default::default() - })) - } async fn list_containers( &self, req: tonic::Request, @@ -302,4 +303,61 @@ impl BrainSgxCli for BrainSgxCliMock { ..Default::default() })) } + + // async fn inspect_container( + // &self, + // req: tonic::Request, + // ) -> Result, Status> { + // dbg!(req); + // Ok(Response::new(ContainerInspectResp { + // ..Default::default() + // })) + // } +} + +#[tonic::async_trait] +impl BrainSgxDaemon for BrainSgxDaemonMock { + type RegisterNodeStream = Pin< + Box> + Send>, + >; + type BrainMessagesStream = + Pin> + Send>>; + + async fn register_node( + &self, + req: tonic::Request, + ) -> Result, 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>, + ) -> Result, Status> { + dbg!(req); + Ok(Response::new(detee_shared::pb::shared::Empty {})) + } + async fn brain_messages( + &self, + req: tonic::Request, + ) -> Result, Status> { + dbg!(req); + Ok(Response::new( + Box::pin(tokio_stream::empty()) as Self::BrainMessagesStream + )) + } } diff --git a/src/main.rs b/src/main.rs index d29b42c..7305cc0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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();