fix(socks5 udp): correctly reserve enough space for new packets

This commit is contained in:
Σrebe - Romain GERARD 2024-01-23 11:50:57 +01:00
parent 362fa92ac9
commit 3b4c86bce2
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4

View file

@ -9,7 +9,7 @@ use std::io::{Error, ErrorKind};
use std::net::SocketAddr;
use crate::tunnel::to_host_port;
use bytes::{Buf, BufMut, Bytes, BytesMut};
use bytes::{Buf, Bytes, BytesMut};
use fast_socks5::new_udp_header;
use fast_socks5::util::target_addr::TargetAddr;
use log::warn;
@ -229,9 +229,7 @@ pub async fn run_server(
let stream = stream::unfold((udp_server, buffer), |(mut server, mut buf)| async move {
loop {
server.clean_dead_keys();
if buf.remaining_mut() < MAX_PACKET_LENGTH {
buf.reserve(MAX_PACKET_LENGTH);
}
let peer_addr = match server.listener.recv_buf_from(&mut buf).await {
Ok((_read_len, peer_addr)) => peer_addr,