diff --git a/Cargo.lock b/Cargo.lock index 3226e2c..fe32705 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,7 +193,19 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.1+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.7+wasi-0.2.4", ] [[package]] @@ -335,6 +347,15 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.101" @@ -353,6 +374,41 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.3", +] + [[package]] name = "ring" version = "0.17.14" @@ -361,7 +417,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom", + "getrandom 0.2.16", "libc", "untrusted", "windows-sys", @@ -594,6 +650,7 @@ dependencies = [ "base64", "chrono", "once_cell", + "rand", "rusqlite", "serde", "serde_json", @@ -607,6 +664,24 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasi" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasm-bindgen" version = "0.2.104" @@ -807,6 +882,32 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "zerocopy" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zeroize" version = "1.8.2" diff --git a/Cargo.toml b/Cargo.toml index fffe69e..20f1cb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ once_cell = "1.21.3" chrono = "0.4.42" ureq = "3.1.2" rusqlite = "0.37.0" +rand = "0.9.2" diff --git a/src/utils/client.rs b/src/utils/client.rs index 66626b2..fbc5827 100644 --- a/src/utils/client.rs +++ b/src/utils/client.rs @@ -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()?)) } @@ -342,13 +343,14 @@ impl Clone for Client { 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 } } @@ -356,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); } }