1use crate::{tcp::AbstractTcpStream, types::TargetAddr, udp::AbstractUdpSocket};
2
3pub trait AbstractOutbound {
4 fn handle_tcp(
6 &self,
7 target_addr: TargetAddr,
8 stream: impl AbstractTcpStream,
9 via: Option<impl AbstractOutbound + Sized + Send>,
10 ) -> impl Future<Output = eyre::Result<()>> + Send;
11 fn handle_udp(
13 &self,
14 socket: impl AbstractUdpSocket + 'static,
15 via: Option<impl AbstractOutbound + Sized + Send>,
16 ) -> impl Future<Output = eyre::Result<()>> + Send;
17}
18
19mod compat {
20 use std::{
21 pin::Pin,
22 task::{Context, Poll},
23 };
24
25 use pin_project::pin_project;
26 use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
27
28 #[pin_project]
29 struct TokioTcpCompat {
30 #[pin]
31 inner: tokio::net::TcpStream,
32 }
33
34 impl AsyncRead for TokioTcpCompat {
35 fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<std::io::Result<()>> {
36 let this = self.project();
37 this.inner.poll_read(cx, buf)
38 }
39 }
40
41 impl AsyncWrite for TokioTcpCompat {
42 fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize, std::io::Error>> {
43 let this = self.project();
44 this.inner.poll_write(cx, buf)
45 }
46
47 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
48 let this = self.project();
49 this.inner.poll_flush(cx)
50 }
51
52 fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
53 let this = self.project();
54 this.inner.poll_shutdown(cx)
55 }
56 }
57}