2024-02-01 19:15:32 +08:00
|
|
|
use crate::{
|
|
|
|
directions::{IncomingDataEvent, OutgoingDataEvent, OutgoingDirection},
|
|
|
|
session_info::SessionInfo,
|
|
|
|
};
|
|
|
|
use std::{net::SocketAddr, sync::Arc};
|
|
|
|
use tokio::sync::Mutex;
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
pub(crate) trait ProxyHandler: Send + Sync {
|
2024-04-03 14:26:46 +00:00
|
|
|
fn get_server_addr(&self) -> SocketAddr;
|
2024-02-01 19:15:32 +08:00
|
|
|
fn get_session_info(&self) -> SessionInfo;
|
|
|
|
fn get_domain_name(&self) -> Option<String>;
|
|
|
|
async fn push_data(&mut self, event: IncomingDataEvent<'_>) -> std::io::Result<()>;
|
|
|
|
fn consume_data(&mut self, dir: OutgoingDirection, size: usize);
|
|
|
|
fn peek_data(&mut self, dir: OutgoingDirection) -> OutgoingDataEvent;
|
|
|
|
fn connection_established(&self) -> bool;
|
2024-05-05 17:02:58 +08:00
|
|
|
#[allow(dead_code)]
|
2024-02-01 19:15:32 +08:00
|
|
|
fn data_len(&self, dir: OutgoingDirection) -> usize;
|
2024-05-05 17:02:58 +08:00
|
|
|
#[allow(dead_code)]
|
2024-02-01 19:15:32 +08:00
|
|
|
fn reset_connection(&self) -> bool;
|
|
|
|
fn get_udp_associate(&self) -> Option<SocketAddr>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
pub(crate) trait ProxyHandlerManager: Send + Sync {
|
|
|
|
async fn new_proxy_handler(
|
|
|
|
&self,
|
|
|
|
info: SessionInfo,
|
|
|
|
domain_name: Option<String>,
|
|
|
|
udp_associate: bool,
|
|
|
|
) -> std::io::Result<Arc<Mutex<dyn ProxyHandler>>>;
|
|
|
|
}
|