gRPC working \^w^/
This commit is contained in:
parent
2cf3ff0332
commit
a63cbae570
|
@ -32,6 +32,7 @@
|
|||
pkgs.libiconv
|
||||
pkgs.pkg-config
|
||||
pkgs.protobuf
|
||||
pkgs.grpcurl
|
||||
];
|
||||
rust-toolchain = pkgs.symlinkJoin {
|
||||
name = "rust-toolchain";
|
||||
|
|
24
uwusched-nodes/src/grpc/mod.rs
Normal file
24
uwusched-nodes/src/grpc/mod.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use crate::sched::{DataResponse, DataRequest, data_server};
|
||||
use log::{debug, info};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct DataService {}
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl data_server::Data for DataService {
|
||||
async fn data(&self, request: tonic::Request<DataRequest>) -> Result<tonic::Response<DataResponse>, tonic::Status> {
|
||||
info!("Got a request: {:?}", request);
|
||||
let input = request.get_ref();
|
||||
let data = vec![];
|
||||
|
||||
let res = DataResponse {
|
||||
node_id: input.node_id.clone(),
|
||||
hashmap_id: input.hashmap_id.clone(),
|
||||
uuid: input.uuid.clone(),
|
||||
length: data.len().to_string(),
|
||||
data,
|
||||
};
|
||||
debug!("{:?}", &res);
|
||||
Ok(tonic::Response::new(res))
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
mod config;
|
||||
mod grpc;
|
||||
|
||||
use crate::config::CONFIG;
|
||||
use clap::{Parser, Subcommand};
|
||||
use log::debug;
|
||||
use log::{debug, info};
|
||||
use tonic::transport::Server;
|
||||
// Import generated protobuf
|
||||
mod sched {
|
||||
tonic::include_proto!("sched");
|
||||
|
@ -30,37 +32,21 @@ fn get_type_of<T>(_: &T) -> &'static str {
|
|||
std::any::type_name::<T>()
|
||||
}
|
||||
|
||||
// impl sched::data_server::Data for sched::DataResponse {
|
||||
// fn data<'life0, 'async_trait>(
|
||||
// &'life0 self,
|
||||
// request: tonic::Request<sched::DataRequest>,
|
||||
// ) -> ::core::pin::Pin<
|
||||
// Box<
|
||||
// dyn ::core::future::Future<
|
||||
// Output = std::result::Result<
|
||||
// tonic::Response<sched::DataResponse>,
|
||||
// tonic::Status,
|
||||
// >,
|
||||
// > + ::core::marker::Send
|
||||
// + 'async_trait,
|
||||
// >,
|
||||
// >
|
||||
// where
|
||||
// 'life0: 'async_trait,
|
||||
// Self: 'async_trait,
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
std::env::set_var("RUST_LOG", CONFIG.log.level.clone());
|
||||
pretty_env_logger::init();
|
||||
let addr = "[::1]:50051".parse()?;
|
||||
info!("Starting gRPC server on {}", addr);
|
||||
let data = grpc::DataService::default();
|
||||
Server::builder().add_service(sched::data_server::DataServer::new(data)).serve(addr).await?;
|
||||
debug!("{:?}", CONFIG.node);
|
||||
let cli = Cli::parse();
|
||||
match &cli.command {
|
||||
Some(Commands::Start { role }) => {
|
||||
debug!("{:#?}", role)
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
// let cli = Cli::parse();
|
||||
// match &cli.command {
|
||||
// Some(Commands::Start { role }) => {
|
||||
// debug!("{:#?}", role)
|
||||
// }
|
||||
// None => {}
|
||||
// }
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue