2021-12-15 23:42:16 +01:00
|
|
|
use std::future::Future;
|
|
|
|
use futures_util::future::FutureExt;
|
|
|
|
use async_rustls::TlsStream;
|
2021-11-26 22:11:24 +01:00
|
|
|
use capnp::capability::Promise;
|
|
|
|
use capnp::Error;
|
2021-12-15 23:42:16 +01:00
|
|
|
use capnp_rpc::rpc_twoparty_capnp::Side;
|
|
|
|
use capnp_rpc::RpcSystem;
|
|
|
|
use capnp_rpc::twoparty::VatNetwork;
|
|
|
|
use smol::io::{AsyncRead, AsyncWrite};
|
|
|
|
|
|
|
|
use crate::error::Result;
|
2021-11-26 21:01:43 +01:00
|
|
|
|
2021-11-26 22:11:24 +01:00
|
|
|
use api::bootstrap::{
|
2021-12-15 23:42:16 +01:00
|
|
|
Client,
|
2021-11-26 22:11:24 +01:00
|
|
|
Server,
|
|
|
|
MechanismsParams,
|
|
|
|
MechanismsResults,
|
|
|
|
CreateSessionParams,
|
|
|
|
CreateSessionResults
|
|
|
|
};
|
|
|
|
|
|
|
|
mod authentication;
|
2021-12-06 21:53:42 +01:00
|
|
|
mod session;
|
|
|
|
mod users;
|
|
|
|
mod resources;
|
2021-11-26 22:11:24 +01:00
|
|
|
|
2021-12-15 23:42:16 +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<()>>
|
|
|
|
{
|
|
|
|
let (mut reader, mut writer) = smol::io::split(stream);
|
|
|
|
|
|
|
|
let bootstrap = ApiSystem {};
|
|
|
|
let rpc: Client = capnp_rpc::new_client(bootstrap);
|
|
|
|
let network = VatNetwork::new(
|
|
|
|
reader,
|
|
|
|
writer,
|
|
|
|
Side::Server,
|
|
|
|
Default::default(),
|
|
|
|
);
|
|
|
|
let rpc_system = RpcSystem::new(Box::new(network), Some(rpc.client));
|
|
|
|
|
|
|
|
rpc_system.map(|r| r.map_err(Into::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 {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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!()
|
|
|
|
}
|
|
|
|
}
|