brainwires_proxy/transport/
mod.rs1#[cfg(feature = "http")]
4pub mod http;
5#[cfg(feature = "http")]
6pub mod sse;
7
8pub mod tcp;
9pub mod unix;
10
11#[cfg(feature = "websocket")]
12pub mod websocket;
13
14use crate::error::ProxyResult;
15use crate::types::{ProxyRequest, ProxyResponse};
16use tokio::sync::{mpsc, oneshot};
17
18pub type InboundConnection = (ProxyRequest, oneshot::Sender<ProxyResponse>);
20
21#[derive(Debug, Clone)]
23pub enum ListenAddr {
24 Tcp(std::net::SocketAddr),
25 Unix(std::path::PathBuf),
26}
27
28#[derive(Debug, Clone)]
30pub enum UpstreamTarget {
31 Url(url::Url),
32 Tcp { host: String, port: u16 },
33 Unix(std::path::PathBuf),
34}
35
36#[async_trait::async_trait]
39pub trait TransportListener: Send + Sync {
40 async fn listen(
43 &self,
44 tx: mpsc::Sender<InboundConnection>,
45 shutdown: tokio::sync::watch::Receiver<bool>,
46 ) -> ProxyResult<()>;
47
48 fn transport_name(&self) -> &str;
50}
51
52#[async_trait::async_trait]
54pub trait TransportConnector: Send + Sync {
55 async fn forward(&self, request: ProxyRequest) -> ProxyResult<ProxyResponse>;
57
58 fn connector_name(&self) -> &str;
60}