pub mod flex;
pub use flex::{FlexFactory, FlexFusewire};
use std::sync::Arc;
use async_trait::async_trait;
use crate::conn::SocketAddr;
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TransProto {
#[default]
Tcp,
Quic,
}
impl TransProto {
pub fn is_tcp(&self) -> bool {
matches!(self, Self::Tcp)
}
pub fn is_quic(&self) -> bool {
matches!(self, Self::Quic)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FuseEvent {
TlsHandshaking,
TlsHandshaked,
Alive,
ReadData(usize),
WriteData(usize),
WaitFrame,
GainFrame,
}
pub(crate) type ArcFuseFactory = Arc<dyn FuseFactory + Sync + Send + 'static>;
pub(crate) type ArcFusewire = Arc<dyn Fusewire + Sync + Send + 'static>;
#[derive(Clone, Debug)]
pub struct FuseInfo {
pub trans_proto: TransProto,
pub remote_addr: SocketAddr,
pub local_addr: SocketAddr,
}
pub trait FuseFactory {
fn create(&self, info: FuseInfo) -> ArcFusewire;
}
#[async_trait]
pub trait Fusewire {
fn event(&self, event: FuseEvent);
async fn fused(&self);
}
impl<T, F> FuseFactory for T
where
T: Fn(FuseInfo) -> F,
F: Fusewire + Sync + Send + 'static,
{
fn create(&self, info: FuseInfo) -> ArcFusewire {
Arc::new((*self)(info))
}
}