From ffbf43821ce50d3e2bfc1ff51affe7daec45bd14 Mon Sep 17 00:00:00 2001 From: immanuwell Date: Sat, 30 May 2026 14:11:58 +0400 Subject: [PATCH] fix: correct length field size, reserved tag range, and flaky test assertion Signed-off-by: immanuwell --- docs/README.md | 2 +- src/lib.rs | 9 ++++----- src/tlv/mod.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3d3c4ed..813309d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -54,7 +54,7 @@ scalable file sharing capabilities. - **Cache Piece Content (Tag=0x07):** Raw cache piece data or cache piece fragments. - **Error (Tag=0xFF):** Conveys error. - **Close (Tag=0xFE):** Indicates the end of a connection. -- **Reserved Tags:** Tags 6-253 may be allocated for metadata, compression, encryption, or future protocol extensions. +- **Reserved Tags:** Tags 8-253 may be allocated for metadata, compression, encryption, or future protocol extensions. ## Example diff --git a/src/lib.rs b/src/lib.rs index ba42a8f..7164475 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -229,15 +229,15 @@ impl From
for Bytes { /// Packet Format: /// - Packet Identifier (1 bytes): Uniquely identifies each packet /// - Tag (1 bytes): Specifies data type in value field -/// - Length (8 bytes): Indicates Value field length, up to 4 GiB -/// - Value (variable): Actual data content, maximum 1 GiB +/// - Length (4 bytes): Indicates Value field length, up to 4 GiB +/// - Value (variable): Actual data content, maximum 4 GiB /// /// Protocol Format: /// /// ```text /// --------------------------------------------------------------------------------------------------- /// | | | | | -/// | Packet Identifier (1 bytes) | Tag (1 bytes) | Length (8 bytes) | Value (up to 4 GiB) | +/// | Packet Identifier (1 bytes) | Tag (1 bytes) | Length (4 bytes) | Value (up to 4 GiB) | /// | | | | | /// --------------------------------------------------------------------------------------------------- /// ``` @@ -374,7 +374,7 @@ impl TryFrom for Vortex { } } -/// Implement From for Bytes. +/// Implement From for Bytes. impl From for Bytes { /// from converts a Vortex packet to Bytes. fn from(packet: Vortex) -> Self { @@ -471,7 +471,6 @@ mod tests { assert_eq!(header.tag, tag); assert_eq!(header.length, value_length); - assert!(header.id <= 254); } #[test] diff --git a/src/tlv/mod.rs b/src/tlv/mod.rs index eda8483..66a4095 100644 --- a/src/tlv/mod.rs +++ b/src/tlv/mod.rs @@ -57,7 +57,7 @@ pub enum Tag { /// The content of a cache piece, with a maximum size of 4 GiB per piece. CachePieceContent = 7, - /// Reserved for future use, for tags 6-254. + /// Reserved for future use, for tags 8-253. Reserved(u8), /// Close the connection. If server or client receives this tag, it will close the connection.