From 05a60b3cb74f21c2c878d395bbcf8a10e40d1ab2 Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:46:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8C=85=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/channel/sender.rs | 7 ++++++- vnt/src/channel/tcp_channel.rs | 6 +++++- vnt/src/protocol/mod.rs | 5 ++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/vnt/src/channel/sender.rs b/vnt/src/channel/sender.rs index ec91b42..725445e 100644 --- a/vnt/src/channel/sender.rs +++ b/vnt/src/channel/sender.rs @@ -170,7 +170,12 @@ impl PacketSenderInner { fn try_send(&self, buf: &[u8]) -> io::Result<()> { let len = buf.len(); let mut buf_vec = Vec::with_capacity(buf.len() + 4); - buf_vec.extend_from_slice(&[0, 0, (len >> 8) as u8, (len & 0xFF) as u8]); + buf_vec.extend_from_slice(&[ + (len >> 24) as u8, + (len >> 16) as u8, + (len >> 8) as u8, + len as u8, + ]); buf_vec.extend_from_slice(buf); match self.buffer.try_send(buf_vec) { Ok(_) => self.notify.notify(self.token, true), diff --git a/vnt/src/channel/tcp_channel.rs b/vnt/src/channel/tcp_channel.rs index cb2b9b9..097c71e 100644 --- a/vnt/src/channel/tcp_channel.rs +++ b/vnt/src/channel/tcp_channel.rs @@ -358,7 +358,11 @@ where if let Some((route_key, stream, buf, begin)) = map.get_mut(token) { loop { let end = if *begin >= 4 { - 4 + (((buf[2] as u16) << 8) | buf[3] as u16) as usize + let len = ((buf[0] as usize) << 24) + | ((buf[1] as usize) << 16) + | ((buf[2] as usize) << 8) + | buf[3] as usize; + 4 + len } else { 4 }; diff --git a/vnt/src/protocol/mod.rs b/vnt/src/protocol/mod.rs index a04e37c..6694771 100644 --- a/vnt/src/protocol/mod.rs +++ b/vnt/src/protocol/mod.rs @@ -128,11 +128,10 @@ impl> NetPacket { "length overflow", )); } - // 不能大于udp最大载荷长度 - if data_len < 12 || data_len > 65535 - 20 - 8 { + if data_len < 12 { return Err(io::Error::new( io::ErrorKind::InvalidData, - "length overflow", + "data_len too short", )); } Ok(NetPacket { data_len, buffer })