From 3ac60bacb0ddd32e2325f7d24f3c74908d82346b Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Tue, 8 Sep 2020 09:56:40 +0200 Subject: [PATCH] Library update and compile --- Cargo.toml | 14 +++++++------- src/api.rs | 20 ++++++++++---------- src/auth.rs | 2 +- src/connection.rs | 26 +++++++++++++------------- src/machine.rs | 13 +++++++------ src/main.rs | 9 ++------- 6 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8948c40..66cc378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,17 +15,17 @@ futures = { version = "0.3", features = ["thread-pool", "compat"] } futures-util = "0.3" futures-signals = "0.3" -smol = "0.4" +smol = "1.0" signal-hook = { version = "0.1", features = ["tokio-support"] } slog = { version = "2.5", features = ["max_level_trace"] } -slog-term = "2.5" -slog-async = "2.4" +slog-term = "2.6" +slog-async = "2.5" -capnp = "0.12" -capnp-rpc = "0.12" -capnp-futures = "0.12" +capnp = "0.13" +capnp-rpc = "0.13" +capnp-futures = "0.13" toml = "0.5" serde = { version = "1.0", features = ["derive"] } @@ -37,4 +37,4 @@ clap = "2.33" rsasl = "0.1" [build-dependencies] -capnpc = "0.12" +capnpc = "0.13" diff --git a/src/api.rs b/src/api.rs index a45e586..4673e55 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,6 +1,6 @@ // module needs to be top level for generated functions to be in scope: // https://github.com/capnproto/capnproto-rust/issues/16 -pub mod gen { +pub mod api_capnp { include!(concat!(env!("OUT_DIR"), "/schema/api_capnp.rs")); } @@ -19,10 +19,10 @@ use capnp_rpc::rpc_twoparty_capnp::Side; pub async fn handle_connection(log: Logger, socket: TcpStream) -> Result<()> { let client = DifAPI {}; - let api = gen::diflouroborane::ToClient::new(client).into_client::(); + let api: api_capnp::diflouroborane::Client = capnp_rpc::new_client(client); let mut message = capnp::message::Builder::new_default(); - let mut outer = message.init_root::(); + let mut outer = message.init_root::(); outer.set_api(api.clone()); let network = VatNetwork::new(socket.clone(), socket, Side::Server, Default::default()); @@ -35,14 +35,14 @@ pub async fn handle_connection(log: Logger, socket: TcpStream) -> Result<()> { pub struct DifAPI; -impl gen::diflouroborane::Server for DifAPI { +impl api_capnp::diflouroborane::Server for DifAPI { fn machines(&mut self, - _params: gen::diflouroborane::MachinesParams, - mut results: gen::diflouroborane::MachinesResults) + _params: api_capnp::diflouroborane::MachinesParams, + mut results: api_capnp::diflouroborane::MachinesResults) -> Promise<(), Error> { let mut b = results.get(); - let mach = gen::machines::ToClient::new(MachinesAPI).into_client::(); + let mach = capnp_rpc::new_client(MachinesAPI); b.set_mach(mach); Promise::ok(()) } @@ -50,10 +50,10 @@ impl gen::diflouroborane::Server for DifAPI { pub struct MachinesAPI; -impl gen::machines::Server for MachinesAPI { +impl api_capnp::machines::Server for MachinesAPI { fn list(&mut self, - _params: gen::machines::ListParams, - mut results: gen::machines::ListResults) + _params: api_capnp::machines::ListParams, + mut results: api_capnp::machines::ListResults) -> Promise<(), Error> { let mut l = results.get(); diff --git a/src/auth.rs b/src/auth.rs index b332036..52af411 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -11,7 +11,7 @@ use rsasl::sys::{Gsasl, Gsasl_session}; use crate::error::Result; use crate::config::Config; -pub mod gen { +pub mod auth_capnp { include!(concat!(env!("OUT_DIR"), "/schema/auth_capnp.rs")); } diff --git a/src/connection.rs b/src/connection.rs index 3022dff..a6ad9ba 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -6,7 +6,7 @@ use crate::error::Result; use crate::auth; use crate::api; -pub mod gen { +pub mod connection_capnp { include!(concat!(env!("OUT_DIR"), "/schema/connection_capnp.rs")); } @@ -19,11 +19,11 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> let receive_options = capnp::message::ReaderOptions::default(); { let message = capnp_futures::serialize::read_message(&mut stream, receive_options).await.unwrap().unwrap(); - let m = message.get_root::().unwrap(); + let m = message.get_root::().unwrap(); if m.has_greet() { match m.which() { - Ok(gen::message::Which::Greet(Ok(r))) => { + Ok(connection_capnp::message::Which::Greet(Ok(r))) => { println!("Host {} with program {} is saying hello. They speak API version {}.{}.", r.get_host().unwrap(), r.get_program().unwrap(), @@ -40,7 +40,7 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> { let mut message = capnp::message::Builder::new_default(); - let greet_outer = message.init_root::(); + let greet_outer = message.init_root::(); let mut greeting = greet_outer.init_greet(); greeting.set_host(host); greeting.set_program(program); @@ -51,7 +51,7 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> } { let mut message = capnp::message::Builder::new_default(); - let outer = message.init_root::(); + let outer = message.init_root::(); let mut mechs = outer.init_auth().init_mechanisms(1); mechs.set(0, "PLAIN"); @@ -60,14 +60,14 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> { let message = capnp_futures::serialize::read_message(&mut stream, receive_options).await.unwrap().unwrap(); - let m = message.get_root::().unwrap(); + let m = message.get_root::().unwrap(); let mut auth_success = false; match m.which() { - Ok(gen::message::Which::Auth(Ok(r))) => { + Ok(connection_capnp::message::Which::Auth(Ok(r))) => { if let Ok(w) = r.which() { - use crate::auth_capnp::auth_message::*; + use crate::auth::auth_capnp::auth_message::*; match w { Request(Ok(r)) => { let m = r.get_mechanism().unwrap(); @@ -77,12 +77,12 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> let mut sasl = auth::Auth::new(); let mut sess = sasl.ctx.server_start(&cm).unwrap(); - use crate::auth_capnp::request::initial_response::*; + use crate::auth::auth_capnp::request::initial_response::*; match r.get_initial_response().which() { Ok(Initial(Ok(r))) => { debug!(log, "Client Auth with initial data"); let mut message = capnp::message::Builder::new_default(); - let mut outer = message.init_root::().init_auth(); + let mut outer = message.init_root::().init_auth(); match sess.step(r) { Ok(rsasl::Step::Done(b)) => { @@ -90,7 +90,7 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> debug!(log, "Authentication successful"); let mut outcome= outer.init_outcome(); - outcome.set_result(auth::gen::outcome::Result::Successful); + outcome.set_result(auth::auth_capnp::outcome::Result::Successful); if !b.is_empty() { let mut add_data = outcome.init_additional_data(); add_data.set_additional(&b); @@ -105,8 +105,8 @@ pub async fn handle_connection(log: Logger, mut stream: TcpStream) -> Result<()> let mut outcome = outer.init_outcome(); // TODO: Distinguish errors - outcome.set_result(auth::gen::outcome::Result::Failed); - outcome.set_action(auth::gen::outcome::Action::Retry); + outcome.set_result(auth::auth_capnp::outcome::Result::Failed); + outcome.set_action(auth::auth_capnp::outcome::Action::Retry); outcome.set_help_text(&format!("{}", e)); } } diff --git a/src/machine.rs b/src/machine.rs index a95692e..d382ad3 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -7,11 +7,12 @@ use slog::Logger; use serde::{Serialize, Deserialize}; use toml; +use std::sync::Arc; +use smol::lock::RwLock; + use crate::error::Result; use crate::config::Config; -use smol::lock::{Arc, RwLock}; - use capnp::Error; use uuid::Uuid; @@ -86,10 +87,10 @@ impl MachinesProvider { #[derive(Clone)] pub struct Machines { - inner: RwLock, + inner: Arc>, } impl Machines { - pub fn new(inner: RwLock) -> Self { + pub fn new(inner: Arc>) -> Self { Self { inner } } } @@ -105,13 +106,13 @@ impl GiveBack { } } -fn uuid_from_api(uuid: crate::api_capnp::u_u_i_d::Reader) -> Uuid { +fn uuid_from_api(uuid: crate::api::api_capnp::u_u_i_d::Reader) -> Uuid { let uuid0 = uuid.get_uuid0() as u128; let uuid1 = uuid.get_uuid1() as u128; let num: u128 = (uuid1 << 64) + uuid0; Uuid::from_u128(num) } -fn api_from_uuid(uuid: Uuid, mut wr: crate::api_capnp::u_u_i_d::Builder) { +fn api_from_uuid(uuid: Uuid, mut wr: crate::api::api_capnp::u_u_i_d::Builder) { let num = uuid.to_u128_le(); let uuid0 = num as u64; let uuid1 = (num >> 64) as u64; diff --git a/src/main.rs b/src/main.rs index 0384bfe..4d65e96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,8 @@ use futures::compat::Stream01CompatExt; use futures::join; use futures::task::LocalSpawn; +use smol::net::TcpListener; + use std::io; use std::io::Write; use std::path::PathBuf; @@ -33,13 +35,6 @@ use std::sync::Arc; use error::Error; -// Re-Export generated capnp code. -// This is necessary because the Rust generator expects types to be found in the -// `crate::_capnp` hierarchy. -use api::gen as api_capnp; -use auth::gen as auth_capnp; -use connection::gen as connection_capnp; - // Returning a `Result` from `main` allows us to use the `?` shorthand. // In the case of an Err it will be printed using `fmt::Debug` fn main() -> Result<(), Error> {