use crate::network::transport::TransportIo;
use anyhow::Result;
use async_trait::async_trait;
#[async_trait]
pub trait TunnelRelay: Send + Sync {
async fn relay(
&mut self,
incoming: &mut dyn TransportIo,
outgoing: &mut dyn TransportIo,
) -> Result<u64>;
}
pub async fn relay_with_rewrite(
incoming: &mut dyn TransportIo,
outgoing: &mut dyn TransportIo,
) -> Result<u64> {
let mut buf = vec![0u8; 64 * 1024];
let mut total: u64 = 0;
loop {
let n = incoming.read(&mut buf).await?;
if n == 0 {
break; }
outgoing.write_all(&buf[..n]).await?;
total += n as u64;
}
Ok(total)
}