AssociatedUdpSocket

Struct AssociatedUdpSocket 

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

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

It only provides handful of methods to send / receive UDP packets with SOCKS5 UDP header. The underlying UdpSocket can be accessed with AssociatedUdpSocket::get_ref() and AssociatedUdpSocket::get_mut().

Implementations§

Source§

impl AssociatedUdpSocket

Source

pub fn new(socket: UdpSocket, buf_size: usize) -> Self

Creates a new AssociatedUdpSocket with a UdpSocket and a maximum receiving UDP packet size, with SOCKS5 UDP header included.

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.

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 fn get_ref(&self) -> &UdpSocket

Returns a shared reference to the underlying socket.

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

Source

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

Returns a mutable reference to the underlying socket.

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

Source

pub fn into_inner(self) -> UdpSocket

Consumes the AssociatedUdpSocket and returns the underlying UdpSocket.

Trait Implementations§

Source§

impl Debug for AssociatedUdpSocket

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.