pub struct AssociatedUdpSocket { /* private fields */ }
Expand description
This is a helper for managing the associated UDP socket.
It will add the socks5 UDP header to every UDP packet it sends, also try to parse the socks5 UDP header from any UDP packet received.
The receiving buffer size for each UDP packet can be set with set_recv_buffer_size()
,
and be read with get_max_packet_size()
.
You can create this struct by using AssociatedUdpSocket::from::<(UdpSocket, usize)>()
,
the first element of the tuple is the UDP socket, the second element is the receiving buffer size.
This struct can also be revert into a raw tokio UDP socket with UdpSocket::from::<AssociatedUdpSocket>()
.
AssociatedUdpSocket
can be used as the associated UDP socket.
Implementations§
Source§impl AssociatedUdpSocket
impl AssociatedUdpSocket
Sourcepub async fn connect<A: ToSocketAddrs>(&self, addr: A) -> Result<()>
pub async fn connect<A: ToSocketAddrs>(&self, addr: A) -> Result<()>
Connects the UDP socket setting the default destination for send() and limiting packets that are read via recv from the address specified in addr.
Sourcepub fn get_max_packet_size(&self) -> usize
pub fn get_max_packet_size(&self) -> usize
Get the maximum UDP packet size, with socks5 UDP header included.
Sourcepub fn set_max_packet_size(&self, size: usize)
pub fn set_max_packet_size(&self, size: usize)
Set the maximum UDP packet size, with socks5 UDP header included, for adjusting the receiving buffer size.
Sourcepub async fn recv(&self) -> Result<(Bytes, u8, Address)>
pub async fn recv(&self) -> Result<(Bytes, u8, Address)>
Receives a socks5 UDP relay packet on the socket from the remote address to which it is connected. On success, returns the packet itself, the fragment number and the remote target address.
The connect
method will connect this socket to a remote address.
This method will fail if the socket is not connected.
Sourcepub async fn recv_from(&self) -> Result<(Bytes, u8, Address, SocketAddr)>
pub async fn recv_from(&self) -> Result<(Bytes, u8, Address, SocketAddr)>
Receives a socks5 UDP relay packet on the socket from the any remote address. On success, returns the packet itself, the fragment number, the remote target address and the source address.