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
impl AssociatedUdpSocket
Sourcepub fn new(socket: UdpSocket, buf_size: usize) -> Self
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.
Sourcepub async fn recv(
&self,
) -> Result<(Bytes, UdpHeader), (Socks5Error, Option<Vec<u8>>)>
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.
Sourcepub async fn recv_from(
&self,
) -> Result<(Bytes, UdpHeader, SocketAddr), (Socks5Error, Option<Vec<u8>>)>
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.
Sourcepub async fn send<P: AsRef<[u8]>>(
&self,
pkt: P,
header: &UdpHeader,
) -> Result<usize, Error>
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.
Sourcepub async fn send_to<P: AsRef<[u8]>>(
&self,
pkt: P,
header: &UdpHeader,
addr: SocketAddr,
) -> Result<usize, Error>
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.
Sourcepub fn get_max_pkt_size(&self) -> usize
pub fn get_max_pkt_size(&self) -> usize
Get the maximum receiving UDP packet size, with SOCKS5 UDP header included.
Sourcepub fn set_max_pkt_size(&self, size: usize)
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.
Sourcepub fn get_ref(&self) -> &UdpSocket
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.
Sourcepub fn get_mut(&mut self) -> &mut UdpSocket
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.
Sourcepub fn into_inner(self) -> UdpSocket
pub fn into_inner(self) -> UdpSocket
Consumes the AssociatedUdpSocket and returns the underlying UdpSocket.