From 6a269ca0873a12498c519078d1b445b34739c5fe Mon Sep 17 00:00:00 2001 From: Stanislav N Mikhailov Date: Thu, 6 Aug 2026 16:22:28 +0300 Subject: [PATCH] WIP: draft validation for flags (does not compile yet) --- src/main.rs | 1 - src/protocol.rs | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 67019d3..4ad921c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,6 @@ async fn main() -> io::Result<()> { client_addr, stream, ); - tokio::spawn(async move { if let Err(error) = connection.run().await { eprintln!( diff --git a/src/protocol.rs b/src/protocol.rs index 801206e..236e07f 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -90,18 +90,25 @@ impl Header { /// // Валидация Header pub fn validate(&self) -> Result<(), HeaderValidationError> { - if self.version != 1 { - return Err( - HeaderValidationError::UnsupportedVersion(self.version) + //Валидация version + if self.version != 1 { + return Err( + HeaderValidationError::UnsupportedVersion(self.version) ); - } + } - if self.command != 1 { - return Err( - HeaderValidationError::UnsupportedCommand(self.command) + // Валидация command + if self.command != 1 { + return Err( + HeaderValidationError::UnsupportedCommand(self.command) ); - } + } + // Валидация flags + if !(0..7).contains(&self.flags){ + return Err(HeaderValidationError::UnsupportedCommand(self.flags)); + }; + Ok(()) } } \ No newline at end of file