fabaccess-bffh/bffhd/capnp/mod.rs

81 lines
1.6 KiB
Rust
Raw Normal View History

use std::future::Future;
2021-11-26 22:11:24 +01:00
use capnp::capability::Promise;
use capnp::Error;
2022-03-10 20:52:34 +01:00
use capnp_rpc::rpc_twoparty_capnp::Side;
use capnp_rpc::RpcSystem;
use capnp_rpc::twoparty::VatNetwork;
use futures_lite::StreamExt;
2022-03-08 16:41:38 +01:00
use futures_rustls::server::TlsStream;
2022-03-10 20:52:34 +01:00
use futures_util::{AsyncRead, AsyncWrite, FutureExt};
use crate::error::Result;
2021-11-26 21:01:43 +01:00
2021-11-26 22:11:24 +01:00
use api::bootstrap::{
2022-03-10 20:52:34 +01:00
Client,
2021-11-26 22:11:24 +01:00
Server,
MechanismsParams,
MechanismsResults,
CreateSessionParams,
CreateSessionResults
};
2022-03-10 20:52:34 +01:00
mod authenticationsystem;
mod machine;
mod machinesystem;
mod permissionsystem;
mod user;
2021-12-06 21:53:42 +01:00
mod users;
2022-03-10 20:52:34 +01:00
mod session;
2021-11-26 22:11:24 +01:00
#[derive(Debug)]
pub struct APIHandler {
}
impl APIHandler {
pub fn handle<IO: 'static + Unpin + AsyncRead + AsyncWrite>(&mut self, stream: TlsStream<IO>)
-> impl Future<Output = Result<()>>
{
2022-03-10 20:52:34 +01:00
let (rx, tx) = futures_lite::io::split(stream);
let vat = VatNetwork::new(rx, tx, Side::Server, Default::default());
let bootstrap: Client = capnp_rpc::new_client(ApiSystem::new());
RpcSystem::new(Box::new(vat), Some(bootstrap.client))
.map(|res| match res {
Ok(()) => Ok(()),
Err(e) => Err(e.into())
})
}
}
2021-12-06 21:53:42 +01:00
#[derive(Debug)]
/// Cap'n Proto API Handler
2021-11-26 22:11:24 +01:00
struct ApiSystem {
}
2022-03-10 20:52:34 +01:00
impl ApiSystem {
pub fn new() -> Self {
Self {}
}
}
2021-12-06 21:53:42 +01:00
2021-11-26 22:11:24 +01:00
impl Server for ApiSystem {
fn mechanisms(
&mut self,
_: MechanismsParams,
_: MechanismsResults
) -> Promise<(), Error>
{
todo!()
}
fn create_session(
&mut self,
_: CreateSessionParams,
_: CreateSessionResults
) -> Promise<(), Error>
{
todo!()
}
}