async_proxies/
proxy.rs

1use tokio::io::{AsyncRead, AsyncWrite};
2use async_trait::async_trait;
3
4/// This trait comes as an abstraction over
5/// proxy protocols. Each protocol serves own methods
6/// to establish connection between a proxy, you, and the
7/// destanation service. The same applies to I/O and closing the 
8/// established connection
9#[async_trait]
10pub trait AsyncProxy {
11    type OutputStream: AsyncRead + AsyncWrite;
12    type ErrorKind;
13    type ConnParams;
14
15    /// Connects to the destanation through proxy
16    async fn connect(&mut self, params: Self::ConnParams)
17        -> Result<Self::OutputStream, Self::ErrorKind>;
18
19    /// Writes the buffer to the destanation
20    async fn write_buffer(&mut self, buffer: &[u8], stream: Self::OutputStream)
21        -> Result<Self::OutputStream, Self::ErrorKind>;
22
23    /// Reads buffer from the destanation
24    async fn read_buffer(&mut self, buffer: &mut [u8], stream: Self::OutputStream)
25        -> Result<Self::OutputStream, Self::ErrorKind>;
26
27    /// Drops the proxy stream
28    async fn drop_stream(&mut self, stream: Self::OutputStream)
29        -> Result<(), Self::ErrorKind>;
30}