Implement App functionality #11
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -329,7 +329,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "detee-shared"
|
name = "detee-shared"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"prost",
|
"prost",
|
||||||
|
80
src/grpc.rs
80
src/grpc.rs
@ -16,8 +16,8 @@ use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
|
|||||||
use tonic::{Request, Response, Status, Streaming};
|
use tonic::{Request, Response, Status, Streaming};
|
||||||
|
|
||||||
use detee_shared::pb::daemon::{
|
use detee_shared::pb::daemon::{
|
||||||
brain_sgx_cli_server::BrainSgxCli, ContainerFilters, ContainerInspectResp, ContainerListResp,
|
brain_sgx_cli_server::BrainSgxCli, brain_sgx_daemon_server::BrainSgxDaemon, ContainerFilters,
|
||||||
DeleteContainerRes, NewContainerRes,
|
ContainerListResp, DeleteContainerRes, NewContainerRes,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct BrainDaemonMock {
|
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]
|
#[tonic::async_trait]
|
||||||
impl BrainDaemon for BrainDaemonMock {
|
impl BrainDaemon for BrainDaemonMock {
|
||||||
type RegisterNodeStream = Pin<Box<dyn Stream<Item = Result<Contract, Status>> + Send>>;
|
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(
|
async fn list_containers(
|
||||||
&self,
|
&self,
|
||||||
req: tonic::Request<ContainerFilters>,
|
req: tonic::Request<ContainerFilters>,
|
||||||
@ -302,4 +303,61 @@ impl BrainSgxCli for BrainSgxCliMock {
|
|||||||
..Default::default()
|
..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;
|
mod grpc;
|
||||||
|
|
||||||
use data::BrainData;
|
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_cli_server::BrainCliServer;
|
||||||
use grpc::snp_proto::brain_daemon_server::BrainDaemonServer;
|
use grpc::snp_proto::brain_daemon_server::BrainDaemonServer;
|
||||||
use grpc::BrainCliMock;
|
use grpc::BrainCliMock;
|
||||||
use grpc::BrainDaemonMock;
|
use grpc::BrainDaemonMock;
|
||||||
use grpc::BrainSgxCliMock;
|
use grpc::BrainSgxCliMock;
|
||||||
|
use grpc::BrainSgxDaemonMock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tonic::transport::Server;
|
use tonic::transport::Server;
|
||||||
|
|
||||||
@ -31,11 +33,13 @@ async fn main() {
|
|||||||
let cli_server = BrainCliServer::new(BrainCliMock::new(data.clone()));
|
let cli_server = BrainCliServer::new(BrainCliMock::new(data.clone()));
|
||||||
|
|
||||||
let sgx_cli_server = BrainSgxCliServer::new(BrainSgxCliMock::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()
|
Server::builder()
|
||||||
.add_service(daemon_server)
|
.add_service(daemon_server)
|
||||||
.add_service(cli_server)
|
.add_service(cli_server)
|
||||||
.add_service(sgx_cli_server)
|
.add_service(sgx_cli_server)
|
||||||
|
.add_service(sgx_daemon_server)
|
||||||
.serve(addr)
|
.serve(addr)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user