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>
impl<O> Server<O>
sourcepub async fn accept(&self) -> Result<(IncomingConnection<O>, SocketAddr), Error>
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.
sourcepub fn poll_accept(
&self,
cx: &mut Context<'_>
) -> Poll<Result<(IncomingConnection<O>, SocketAddr), Error>>
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.
sourcepub fn local_addr(&self) -> Result<SocketAddr, Error>
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.