Struct socks5_server::Server

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

A SOCKS5 server listener

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

A (TcpListener, Arc<dyn Auth<Output = O> + Send + Sync>) can be converted into a Server<O> with From trait. Also, a Server<O> can be converted back.

Generic type <O> 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::from((listener, auth));

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

Implementations§

source§

impl<O> Server<O>

source

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

Accept an IncomingConnection<O>.

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<O>, SocketAddr), Error>>

Polls to accept an IncomingConnection<O>.

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 set_ttl(&self, ttl: u32) -> Result<(), Error>

Sets the value for the IP_TTL option on this socket.

This value sets the time-to-live field that is used in every packet sent from this socket.

source

pub fn ttl(&self) -> Result<u32, Error>

Gets the value of the IP_TTL option for this socket.

For more information about this option, see set_ttl.

Trait Implementations§

source§

impl<O> From<(TcpListener, Arc<dyn Auth<Output = O> + Send + Sync>)> for Server<O>

source§

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

Converts to this type from the input type.
source§

impl<O> From<Server<O>> for (TcpListener, Arc<dyn Auth<Output = O> + Send + Sync>)

source§

fn from(server: Server<O>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<O> !RefUnwindSafe for Server<O>

§

impl<O> Send for Server<O>

§

impl<O> Sync for Server<O>

§

impl<O> Unpin for Server<O>

§

impl<O> !UnwindSafe for Server<O>

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.