Skip to content

Commit

Permalink
fix: use u8 instead of u16 for hdr len
Browse files Browse the repository at this point in the history
  • Loading branch information
rapiz1 committed Jan 7, 2022
1 parent d0d4f61 commit f989643
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down
6 changes: 3 additions & 3 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand All @@ -101,15 +101,15 @@ 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?;

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
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
Expand Down

0 comments on commit f989643

Please sign in to comment.