async fn relay_r2l(
        context: &Context,
        src_addr: SocketAddr,
        remote_udp: &UdpSocket,
        response_tx: &ServerProxyHandler,
        svr_cfg: &ServerConfig,
        resolved_address_cache: &SharedResolvedAddressCache,
    ) -> io::Result<()> {
        // Waiting for response from server SERVER -> CLIENT
        // Packet length is limited by MAXIMUM_UDP_PAYLOAD_SIZE, excess bytes will be discarded.
        let mut remote_buf = vec![0u8; MAXIMUM_UDP_PAYLOAD_SIZE];
        let (remote_recv_len, remote_addr) = remote_udp.recv_from(&mut remote_buf).await?;

        let addr = match resolved_address_cache.lock().get(&remote_addr) {
            // Translate it back to the domain name address from the request
            Some(a) => a.clone(),
            None => Address::from(remote_addr),
        };

        debug!(
            "UDP ASSOCIATE {} <- {} ({}), payload length {} bytes",
            src_addr, addr, remote_addr, remote_recv_len
        );

        // CLIENT <- SERVER protocol: ADDRESS + PAYLOAD
        let mut send_buf = BytesMut::with_capacity(addr.serialized_len() + remote_recv_len);
        addr.write_to_buf(&mut send_buf);
        send_buf.extend_from_slice(&remote_buf[..remote_recv_len]);

        if let CipherCategory::None = svr_cfg.method().category() {
            // Send back to src_addr
            if let Err(err) = response_tx.send_packet(&send_buf).await {
                error!("failed to send packet into response channel, error: {}", err);

                // FIXME: What to do? Ignore?
            }
        } else {
            let mut encrypt_buf = BytesMut::new();
            encrypt_payload(context, svr_cfg.method(), svr_cfg.key(), &send_buf, &mut encrypt_buf)?;

            // Send back to src_addr
            if let Err(err) = response_tx.send_packet(&encrypt_buf).await {
                error!("failed to send packet into response channel, error: {}", err);

                // FIXME: What to do? Ignore?
            }
        }

        Ok(())
    }
/// Relay packets from remote to local
Relay packets from remote to local
Relay packets from remote to local
async fn relay_r2l(
        context: &Context,
        src_addr: SocketAddr,
        remote_udp: &UdpSocket,
        response_tx: &ServerProxyHandler,
        svr_cfg: &ServerConfig,
        resolved_address_cache: &SharedResolvedAddressCache,
    ) -> io::Result<()> {
        // Waiting for response from server SERVER -> CLIENT
        // Packet length is limited by MAXIMUM_UDP_PAYLOAD_SIZE, excess bytes will be discarded.
        let mut remote_buf = vec![0u8; MAXIMUM_UDP_PAYLOAD_SIZE];
        let (remote_recv_len, remote_addr) = remote_udp.recv_from(&mut remote_buf).await?;
        let addr = match resolved_address_cache.lock().get(&remote_addr) {
            // Translate it back to the domain name address from the request
            Some(a) => a.clone(),
            None => Address::from(remote_addr),
        };
        debug!(
            "UDP ASSOCIATE {} <- {} ({}), payload length {} bytes",
            src_addr, addr, remote_addr, remote_recv_len
        );
        // CLIENT <- SERVER protocol: ADDRESS + PAYLOAD
        let mut send_buf = BytesMut::with_capacity(addr.serialized_len() + remote_recv_len);
        addr.write_to_buf(&mut send_buf);
        send_buf.extend_from_slice(&remote_buf[..remote_recv_len]);
        if let CipherCategory::None = svr_cfg.method().category() {
            // Send back to src_addr
            if let Err(err) = response_tx.send_packet(&send_buf).await {
                error!("failed to send packet into response channel, error: {}", err);
                // FIXME: What to do? Ignore?
            }
        } else {
            let mut encrypt_buf = BytesMut::new();
            encrypt_payload(context, svr_cfg.method(), svr_cfg.key(), &send_buf, &mut encrypt_buf)?;
            // Send back to src_addr
            if let Err(err) = response_tx.send_packet(&encrypt_buf).await {
                error!("failed to send packet into response channel, error: {}", err);
                // FIXME: What to do? Ignore?
            }
        }
        Ok(())
    }
async fn relay_r2l ( context : & Context , src_addr : SocketAddr , remote_udp : & UdpSocket , response_tx : & ServerProxyHandler , svr_cfg : & ServerConfig , resolved_address_cache : & SharedResolvedAddressCache , ) -> io :: Result < ( ) > { // Waiting for response from server SERVER -> CLIENT // Packet length is limited by MAXIMUM_UDP_PAYLOAD_SIZE, excess bytes will be discarded. let mut remote_buf = vec ! [ 0u8 MAXIMUM_UDP_PAYLOAD_SIZE ] ; let ( remote_recv_len , remote_addr ) = remote_udp . recv_from ( & mut remote_buf ) . await ? ; let addr = match resolved_address_cache . lock ( ) . get ( & remote_addr ) { // Translate it back to the domain name address from the request Some ( a ) => a . clone ( ) , None => Address :: from ( remote_addr ) , } ; debug ! ( " " src_addr addr remote_addr remote_recv_len ) ; // CLIENT <- SERVER protocol: ADDRESS + PAYLOAD let mut send_buf = BytesMut :: with_capacity ( addr . serialized_len ( ) + remote_recv_len ) ; addr . write_to_buf ( & mut send_buf ) ; send_buf . extend_from_slice ( & remote_buf [ .. remote_recv_len ] ) ; if let CipherCategory :: None = svr_cfg . method ( ) . category ( ) { // Send back to src_addr if let Err ( err ) = response_tx . send_packet ( & send_buf ) . await { error ! ( " " err ) ; // FIXME: What to do? Ignore? } } else { let mut encrypt_buf = BytesMut :: new ( ) ; encrypt_payload ( context , svr_cfg . method ( ) , svr_cfg . key ( ) , & send_buf , & mut encrypt_buf ) ? ; // Send back to src_addr if let Err ( err ) = response_tx . send_packet ( & encrypt_buf ) . await { error ! ( " " err ) ; // FIXME: What to do? Ignore? } } Ok ( ( ) ) }
Relay packets from remote to local
Relay packets from remote to local
context
&Context
src_addr
SocketAddr
remote_udp
&UdpSocket
response_tx
&ServerProxyHandler
svr_cfg
&ServerConfig
resolved_address_cache
&SharedResolvedAddressCache