mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-05-27 04:07:11 +00:00
beginning async version (#84)
This commit is contained in:
parent
337619169e
commit
9c4fa4260a
41 changed files with 2022 additions and 3286 deletions
30
src/proxy_handler.rs
Normal file
30
src/proxy_handler.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
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 {
|
||||
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;
|
||||
fn data_len(&self, dir: OutgoingDirection) -> usize;
|
||||
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>>>;
|
||||
fn get_server_addr(&self) -> SocketAddr;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue