checkpoint

This commit is contained in:
Adam Wick
2021-06-24 19:18:16 -07:00
commit 1bf6f62d4e
16 changed files with 1789 additions and 0 deletions

43
src/network.rs Normal file
View File

@@ -0,0 +1,43 @@
pub mod address;
pub mod datagram;
pub mod generic;
pub mod listener;
pub mod standard;
pub mod stream;
use crate::messages::ServerResponseStatus;
pub use crate::network::address::{SOCKSv5Address, ToSOCKSAddress};
pub use crate::network::standard::Builtin;
use async_trait::async_trait;
use futures::{AsyncRead, AsyncWrite};
use std::fmt;
#[async_trait]
pub trait Network {
type Stream: AsyncRead + AsyncWrite + Clone + Send + Sync + Unpin + 'static;
type Listener: SingleShotListener<Self::Stream, Self::Error> + Send + Sync + 'static;
type UdpSocket;
type Error: fmt::Debug + fmt::Display + Into<ServerResponseStatus>;
async fn connect<A: ToSOCKSAddress>(
&mut self,
addr: A,
port: u16,
) -> Result<Self::Stream, Self::Error>;
async fn udp_socket<A: ToSOCKSAddress>(
&mut self,
addr: A,
port: Option<u16>,
) -> Result<Self::UdpSocket, Self::Error>;
async fn listen<A: ToSOCKSAddress>(
&mut self,
addr: A,
port: Option<u16>,
) -> Result<Self::Listener, Self::Error>;
}
#[async_trait]
pub trait SingleShotListener<Stream, Error> {
async fn accept(self) -> Result<Stream, Error>;
fn info(&self) -> Result<(SOCKSv5Address, u16), Error>;
}