gRPC working \^w^/
This commit is contained in:
parent
2cf3ff0332
commit
a63cbae570
|
@ -32,6 +32,7 @@
|
||||||
pkgs.libiconv
|
pkgs.libiconv
|
||||||
pkgs.pkg-config
|
pkgs.pkg-config
|
||||||
pkgs.protobuf
|
pkgs.protobuf
|
||||||
|
pkgs.grpcurl
|
||||||
];
|
];
|
||||||
rust-toolchain = pkgs.symlinkJoin {
|
rust-toolchain = pkgs.symlinkJoin {
|
||||||
name = "rust-toolchain";
|
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 config;
|
||||||
|
mod grpc;
|
||||||
|
|
||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use log::debug;
|
use log::{debug, info};
|
||||||
|
use tonic::transport::Server;
|
||||||
// Import generated protobuf
|
// Import generated protobuf
|
||||||
mod sched {
|
mod sched {
|
||||||
tonic::include_proto!("sched");
|
tonic::include_proto!("sched");
|
||||||
|
@ -30,37 +32,21 @@ fn get_type_of<T>(_: &T) -> &'static str {
|
||||||
std::any::type_name::<T>()
|
std::any::type_name::<T>()
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl sched::data_server::Data for sched::DataResponse {
|
#[tokio::main]
|
||||||
// fn data<'life0, 'async_trait>(
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// &'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() {
|
|
||||||
std::env::set_var("RUST_LOG", CONFIG.log.level.clone());
|
std::env::set_var("RUST_LOG", CONFIG.log.level.clone());
|
||||||
pretty_env_logger::init();
|
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);
|
debug!("{:?}", CONFIG.node);
|
||||||
let cli = Cli::parse();
|
// let cli = Cli::parse();
|
||||||
match &cli.command {
|
// match &cli.command {
|
||||||
Some(Commands::Start { role }) => {
|
// Some(Commands::Start { role }) => {
|
||||||
debug!("{:#?}", role)
|
// debug!("{:#?}", role)
|
||||||
}
|
// }
|
||||||
None => {}
|
// None => {}
|
||||||
}
|
// }
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue