use crate::messages::OpenOk;
use crate::types::{Refusal, Session};
use async_trait::async_trait;
use std::io;
use tokio::io::{AsyncRead, AsyncWrite};
pub type BoxSend = Box<dyn AsyncWrite + Send + Unpin>;
pub type BoxRecv = Box<dyn AsyncRead + Send + Unpin>;
#[async_trait]
pub trait SessionStreams: Send + Sync {
fn peer_key(&self) -> [u8; 32];
async fn accept_bi(&self) -> io::Result<(BoxSend, BoxRecv)>;
fn close(&self, code: u32, reason: &[u8]);
fn is_closed(&self) -> bool {
false
}
}
#[async_trait]
pub trait HostBus: Send + Sync {
async fn verify(&self, credential: &str, endpoint_id: &str) -> Result<Session, Refusal>;
async fn renew(&self, endpoint_id: &str) -> Result<Session, Refusal>;
async fn admit_renewal(&self, endpoint_id: &str) -> Result<Session, Refusal>;
async fn invoke(
&self,
capability: &str,
payload: serde_json::Value,
) -> Result<serde_json::Value, Refusal>;
}
#[async_trait]
pub trait WebRtcSignaling: Send + Sync {
async fn handle(
&self,
identity: &OpenOk,
peer: [u8; 32],
send: BoxSend,
recv: BoxRecv,
);
}