Struct socks5_server::Server

source ·
pub struct Server<A> { /* private fields */ }
Expand description

A SOCKS5 server listener

This server listens on a socket and treats incoming connections as SOCKS5 connections.

Generic <A> is the output type of the authentication adapter. See trait Auth.

Example

use socks5_server::{auth::NoAuth, Server};
use std::sync::Arc;
use tokio::net::TcpListener;

async fn listen() {
    let listener = TcpListener::bind("127.0.0.1:5000").await.unwrap();
    let auth = Arc::new(NoAuth) as Arc<_>;

    let server = Server::new(listener, auth);

    while let Ok((conn, _)) = server.accept().await {
        tokio::spawn(async move {
            todo!();
        });
    }
}

Implementations§

source§

impl<A> Server<A>

source

pub fn new( listener: TcpListener, auth: Arc<dyn Auth<Output = A> + Send + Sync> ) -> Self

Creates a new Server<A> with a TcpListener and an Arc<dyn Auth<Output = A> + Send + Sync>.

source

pub async fn accept( &self ) -> Result<(IncomingConnection<A, NeedAuthenticate>, SocketAddr), Error>

Accept an IncomingConnection.

The connection is only a freshly created TCP connection and may not be a valid SOCKS5 connection. You should call IncomingConnection::authenticate() to perform a SOCKS5 authentication handshake.

source

pub fn poll_accept( &self, cx: &mut Context<'_> ) -> Poll<Result<(IncomingConnection<A, NeedAuthenticate>, SocketAddr), Error>>

Polls to accept an IncomingConnection.

The connection is only a freshly created TCP connection and may not be a valid SOCKS5 connection. You should call IncomingConnection::authenticate() to perform a SOCKS5 authentication handshake.

If there is no connection to accept, Poll::Pending is returned and the current task will be notified by a waker. Note that on multiple calls to poll_accept, only the Waker from the Context passed to the most recent call is scheduled to receive a wakeup.

source

pub fn local_addr(&self) -> Result<SocketAddr, Error>

Returns the local address that this server is bound to.

This can be useful, for example, when binding to port 0 to figure out which port was actually bound.

source

pub fn get_ref(&self) -> &TcpListener

Returns a shared reference to the listener.

Note that this may break the encapsulation of the Server and you should not use this method unless you know what you are doing.

source

pub fn get_mut(&mut self) -> &mut TcpListener

Returns a mutable reference to the listener.

Note that this may break the encapsulation of the Server and you should not use this method unless you know what you are doing.

source

pub fn into_inner( self ) -> (TcpListener, Arc<dyn Auth<Output = A> + Send + Sync>)

Consumes the Server<A> and returns the underlying TcpListener and Arc<dyn Auth<Output = A> + Send + Sync>.

Trait Implementations§

source§

impl<A> Debug for Server<A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for Server<A>

§

impl<A> Send for Server<A>

§

impl<A> Sync for Server<A>

§

impl<A> Unpin for Server<A>

§

impl<A> !UnwindSafe for Server<A>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.