Library update and compile

This commit is contained in:
Gregor Reitzenstein 2020-09-08 09:56:40 +02:00
parent 3e91d3ccd5
commit 3ac60bacb0
6 changed files with 40 additions and 44 deletions

View File

@ -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"

View File

@ -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::<capnp_rpc::Server>();
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::<crate::connection::gen::message::Builder>();
let mut outer = message.init_root::<crate::connection::connection_capnp::message::Builder>();
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::<capnp_rpc::Server>();
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();

View File

@ -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"));
}

View File

@ -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::<gen::message::Reader>().unwrap();
let m = message.get_root::<connection_capnp::message::Reader>().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::<gen::message::Builder>();
let greet_outer = message.init_root::<connection_capnp::message::Builder>();
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::<gen::message::Builder>();
let outer = message.init_root::<connection_capnp::message::Builder>();
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::<gen::message::Reader>().unwrap();
let m = message.get_root::<connection_capnp::message::Reader>().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::<gen::message::Builder>().init_auth();
let mut outer = message.init_root::<connection_capnp::message::Builder>().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));
}
}

View File

@ -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<MachinesProvider>,
inner: Arc<RwLock<MachinesProvider>>,
}
impl Machines {
pub fn new(inner: RwLock<MachinesProvider>) -> Self {
pub fn new(inner: Arc<RwLock<MachinesProvider>>) -> 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;

View File

@ -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::<file>_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> {