From cf267e35dac2fd1fbd9072ba401fbced6b152b2c Mon Sep 17 00:00:00 2001 From: Yaay Nands <16502598+nandhinianandj@users.noreply.github.com> Date: Sun, 10 Nov 2024 13:31:39 +0530 Subject: [PATCH] (/usr/share/games/fortunes/science) % The solution to a problem changes the nature of the problem. -- Peer --- Cargo.lock | 118 +++++++++++++++++++++++++++++++++- rustpad-server/src/rustpad.rs | 3 +- 2 files changed, 119 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c919678..c930a3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,6 +199,18 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +[[package]] +name = "crdts" +version = "7.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "387808c885b79055facbd4b2e806a683fe1bc37abc7dfa5fea1974ad2d4137b0" +dependencies = [ + "num", + "quickcheck", + "serde", + "tiny-keccak", +] + [[package]] name = "crossbeam-queue" version = "0.3.11" @@ -214,6 +226,12 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -290,6 +308,16 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "log", + "regex", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -817,6 +845,73 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", + "serde", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -971,7 +1066,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" dependencies = [ - "env_logger", + "env_logger 0.7.1", "log", ] @@ -990,6 +1085,17 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quickcheck" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" +dependencies = [ + "env_logger 0.8.4", + "log", + "rand", +] + [[package]] name = "quote" version = "1.0.36" @@ -1152,6 +1258,7 @@ version = "0.1.0" dependencies = [ "anyhow", "bytecount", + "crdts", "dashmap", "dotenv", "futures", @@ -1495,6 +1602,15 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.8.0" diff --git a/rustpad-server/src/rustpad.rs b/rustpad-server/src/rustpad.rs index dfede38..8963542 100644 --- a/rustpad-server/src/rustpad.rs +++ b/rustpad-server/src/rustpad.rs @@ -13,7 +13,6 @@ use tokio::sync::{broadcast, Notify}; use warp::ws::{Message, WebSocket}; use crate::{database::PersistedDocument, ot::transform_index}; - /// The main object representing a collaborative session. pub struct Rustpad { /// State modified by critical sections of the code. @@ -31,6 +30,7 @@ pub struct Rustpad { /// Shared state involving multiple users, protected by a lock. #[derive(Default)] struct State { + live_users: u128, operations: Vec, text: String, language: Option, @@ -118,6 +118,7 @@ impl From for Rustpad { let rustpad = Self::default(); { let mut state = rustpad.state.write(); + state.live_users += 1; state.text = document.text; state.language = document.language; state.operations.push(UserOperation {