fix: use u8 instead of u16 for hdr len

This commit is contained in:
Yujia Qiao 2022-01-07 19:11:25 +08:00
parent d0d4f61efd
commit f989643c10
No known key found for this signature in database
GPG Key ID: DC129173B148701B
3 changed files with 5 additions and 5 deletions

View File

@ -250,7 +250,7 @@ async fn run_data_channel_for_udp<T: Transport>(conn: T::Stream, local_addr: &st
loop {
// Read a packet from the server
let hdr_len = rd.read_u16().await?;
let hdr_len = rd.read_u8().await?;
let packet = UdpTraffic::read(&mut rd, hdr_len)
.await
.with_context(|| "Failed to read UDPTraffic from the server")?;

View File

@ -79,7 +79,7 @@ impl UdpTraffic {
let v = bincode::serialize(&hdr).unwrap();
trace!("Write {:?} of length {}", hdr, v.len());
writer.write_u16(v.len() as u16).await?;
writer.write_u8(v.len() as u8).await?;
writer.write_all(&v).await?;
writer.write_all(&self.data).await?;
@ -101,7 +101,7 @@ impl UdpTraffic {
let v = bincode::serialize(&hdr).unwrap();
trace!("Write {:?} of length {}", hdr, v.len());
writer.write_u16(v.len() as u16).await?;
writer.write_u8(v.len() as u8).await?;
writer.write_all(&v).await?;
writer.write_all(data).await?;
@ -109,7 +109,7 @@ impl UdpTraffic {
Ok(())
}
pub async fn read<T: AsyncRead + Unpin>(reader: &mut T, hdr_len: u16) -> Result<UdpTraffic> {
pub async fn read<T: AsyncRead + Unpin>(reader: &mut T, hdr_len: u8) -> Result<UdpTraffic> {
let mut buf = Vec::new();
buf.resize(hdr_len as usize, 0);
reader

View File

@ -617,7 +617,7 @@ async fn run_udp_connection_pool<T: Transport>(
},
// Forward outbound traffic from the client to the visitor
hdr_len = conn.read_u16() => {
hdr_len = conn.read_u8() => {
let t = UdpTraffic::read(&mut conn, hdr_len?).await?;
l.send_to(&t.data, t.from).await?;
}