abcperf_generic_client/cs/
mod.rs1use std::{future::Future, net::SocketAddr, pin::Pin};
2
3use async_trait::async_trait;
4
5use anyhow::Result;
6use serde::{Deserialize, Serialize};
7use tokio::sync::oneshot;
8
9pub mod http_warp;
10mod json;
11pub mod quic_quinn;
12pub mod quic_s2n;
13pub mod typed;
14
15pub trait CSTrait: Clone + Copy + Send + Sync + 'static + Default {
16 type Config: CSConfig;
17
18 fn configure(self, ca: Vec<u8>, priv_key: Vec<u8>, cert: Vec<u8>) -> Self::Config;
19}
20
21pub trait CSConfig: Clone + Send + Sync {
22 type Client: CSTraitClient;
23 type Server: CSTraitServer;
24
25 fn client(&self) -> Self::Client;
26 fn server(&self, local_socket: SocketAddr) -> Self::Server;
27}
28
29#[async_trait]
30pub trait CSTraitClient: Send + Sync {
31 type Connection: CSTraitClientConnection;
32
33 async fn connect(&self, addr: SocketAddr, server_name: &str) -> Result<Self::Connection>;
34 fn local_addr(&self) -> SocketAddr;
35}
36
37#[async_trait]
38pub trait CSTraitClientConnection: Send + Sync {
39 async fn request<Request: Serialize + Send + Sync, Response: for<'a> Deserialize<'a>>(
40 &mut self,
41 request: Request,
42 ) -> Result<Response>;
43}
44
45pub trait CSTraitServer: Send {
46 fn start<
47 S: Clone + Send + Sync + 'static,
48 Request: for<'a> Deserialize<'a> + Send + 'static,
49 Response: Serialize + Send + 'static,
50 Fut: Future<Output = Option<Response>> + Send + 'static,
51 F: Fn(S, Request) -> Fut + Send + Sync + Clone + 'static,
52 >(
53 self,
54 shared: S,
55 on_request: F,
56 exit: oneshot::Receiver<()>,
57 ) -> (SocketAddr, Pin<Box<dyn Future<Output = ()> + Send>>);
58}