From a52cac159a6dc7897a62b19be0a999a9c0126b25 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 5 Oct 2025 11:11:56 +0200 Subject: [PATCH] Fixed client overload --- src/utils/client.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/utils/client.rs b/src/utils/client.rs index 792f9cd..9e52911 100644 --- a/src/utils/client.rs +++ b/src/utils/client.rs @@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize}; use crate::types::{ClientMessage, WsMessage}; pub mod handshake { - use base64::Engine; use base64::engine::general_purpose::STANDARD as Base64; + use base64::Engine; use sha1::{Digest, Sha1}; use std::collections::HashMap; use std::io::{BufRead, BufReader, Write}; @@ -100,13 +100,13 @@ pub mod handshake { } } -pub struct Client(TcpStream, Option); +pub struct Client(TcpStream, Option, u64); impl Client { /// Create a client with no timeouts pub fn new(mut stream: TcpStream) -> crate::Result { handshake::handle_websocket_handshake(&mut stream)?; - Ok(Client(stream, None)) + Ok(Client(stream, None, rand::random())) } /// Create a client and set read/write timeouts (useful in prod) @@ -122,7 +122,7 @@ impl Client { stream.set_write_timeout(Some(t))?; } handshake::handle_websocket_handshake(&mut stream)?; - Ok(Client(stream, None)) + Ok(Client(stream, None, rand::random())) } /// Send a close frame and flush. `code` is a WebSocket close code (e.g., 1000 normal). @@ -332,6 +332,7 @@ impl Client { self.1 = Some(uuid) } + #[deprecated] pub fn addr(&self) -> crate::Result { Ok(self.0.peer_addr().unwrap_or(self.0.local_addr()?)) } @@ -339,13 +340,17 @@ impl Client { impl Clone for Client { fn clone(&self) -> Self { - Client(self.0.try_clone().expect("failed to clone TcpStream"), None) + Client( + self.0.try_clone().expect("failed to clone TcpStream"), + self.1.clone(), + self.2.clone(), + ) } } impl PartialEq for Client { fn eq(&self, other: &Self) -> bool { - self.addr().unwrap() == other.addr().unwrap() + self.2 == other.2 } } @@ -353,6 +358,6 @@ impl Eq for Client {} impl Hash for Client { fn hash(&self, state: &mut H) { - self.addr().unwrap().hash(state); + self.2.hash(state); } }