pub struct AssociatedUdpSocket { /* private fields */ }
Expand description

A wrapper of a tokio UDP socket dealing with SOCKS5 UDP header.

(UdpSocket, usize) and AssociatedUdpSocket can be converted to each other with From trait, in which usize is the maximum receiving UDP packet size, with SOCKS5 UDP header included.

It only provides handful of methods to send / receive UDP packets with SOCKS5 UDP header. However, the underlying UdpSocket can be accessed with AsRef and AsMut trait, so you can use all methods provided by UdpSocket.

Implementations§

source§

impl AssociatedUdpSocket

source

pub fn get_max_pkt_size(&self) -> usize

Get the maximum receiving UDP packet size, with SOCKS5 UDP header included.

source

pub fn set_max_pkt_size(&self, size: usize)

Set the maximum receiving UDP packet size, with SOCKS5 UDP header included, for adjusting the receiving buffer size.

source

pub async fn recv( &self ) -> Result<(Bytes, UdpHeader), (Socks5Error, Option<Vec<u8>>)>

Receives a SOCKS5 UDP packet on the socket from the remote address which it is connected.

On success, it returns the packet payload and the SOCKS5 UDP header. On error, it returns the error alongside an Option<Vec<u8>>. If the error occurs before / when receiving the raw UDP packet, the Option<Vec<u8>> will be None. Otherwise, it will be Some(Vec<u8>) containing the received raw UDP packet.

source

pub async fn recv_from( &self ) -> Result<(Bytes, UdpHeader, SocketAddr), (Socks5Error, Option<Vec<u8>>)>

Receives a SOCKS5 UDP packet on the socket from a remote address.

On success, it returns the packet payload, the SOCKS5 UDP header and the source address. On error, it returns the error alongside an Option<Vec<u8>>. If the error occurs before / when receiving the raw UDP packet, the Option<Vec<u8>> will be None. Otherwise, it will be Some(Vec<u8>) containing the received raw UDP packet.

source

pub async fn send<P: AsRef<[u8]>>( &self, pkt: P, header: &UdpHeader ) -> Result<usize, Error>

Sends a UDP packet to the remote address which it is connected. The SOCKS5 UDP header will be added to the packet.

source

pub async fn send_to<P: AsRef<[u8]>>( &self, pkt: P, header: &UdpHeader, addr: SocketAddr ) -> Result<usize, Error>

Sends a UDP packet to a specified remote address. The SOCKS5 UDP header will be added to the packet.

Trait Implementations§

source§

impl AsMut<UdpSocket> for AssociatedUdpSocket

source§

fn as_mut(&mut self) -> &mut UdpSocket

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<UdpSocket> for AssociatedUdpSocket

source§

fn as_ref(&self) -> &UdpSocket

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for AssociatedUdpSocket

source§

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

Formats the value using the given formatter. Read more
source§

impl From<(UdpSocket, usize)> for AssociatedUdpSocket

source§

fn from(from: (UdpSocket, usize)) -> Self

Converts to this type from the input type.
source§

impl From<AssociatedUdpSocket> for (UdpSocket, usize)

source§

fn from(from: AssociatedUdpSocket) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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.