diff --git a/micro-game-lobby/Cargo.lock b/micro-game-lobby/Cargo.lock index 43d5f28a1..4d29ff68f 100644 --- a/micro-game-lobby/Cargo.lock +++ b/micro-game-lobby/Cargo.lock @@ -2,130 +2,30 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.7.14" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] [[package]] -name = "async-channel" -version = "1.5.1" +name = "anyhow" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d373d78ded7d0b3fa8039375718cde0aace493f2e34fb60f51cbf567562ca801" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "once_cell", - "vec-arena", -] - -[[package]] -name = "async-global-executor" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "124ac8c265e407641c3362b8f4d39cdb4e243885b71eef087be27199790f5a3a" -dependencies = [ - "async-executor", - "async-io", - "futures-lite", - "num_cpus", - "once_cell", -] - -[[package]] -name = "async-io" -version = "1.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54bc4c1c7292475efb2253227dbcfad8fe1ca4c02bc62c510cc2f3da5c4704e" -dependencies = [ - "concurrent-queue", - "fastrand", - "futures-lite", - "libc", - "log", - "nb-connect", - "once_cell", - "parking", - "polling", - "vec-arena", - "waker-fn", - "winapi 0.3.9", -] - -[[package]] -name = "async-mutex" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-std" -version = "1.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9fa76751505e8df1c7a77762f60486f60c71bbd9b8557f4da6ad47d083732ed" -dependencies = [ - "async-global-executor", - "async-io", - "async-mutex", - "blocking", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "num_cpus", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-task" -version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" [[package]] name = "async-trait" -version = "0.1.41" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b246867b8b3b6ae56035f1eb1ed557c1d8eae97f0d53696138a50fa0e3a3b8c0" +checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "atty" version = "0.2.14" @@ -134,7 +34,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -145,11 +45,10 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bincode" -version = "1.3.1" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" dependencies = [ - "byteorder", "serde", ] @@ -159,49 +58,11 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "blocking" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] - -[[package]] -name = "bumpalo" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" - -[[package]] -name = "byteorder" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" - [[package]] name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - -[[package]] -name = "cache-padded" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" - -[[package]] -name = "cc" -version = "1.0.61" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cfg-if" @@ -210,34 +71,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] -name = "cloudabi" -version = "0.1.0" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467" -dependencies = [ - "bitflags", -] +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "combine" -version = "4.3.2" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2809f67365382d65fd2b6d9c22577231b954ed27400efeafbe687bda75abcc0b" +checksum = "cc4369b5e4c0cddf64ad8981c0111e7df4f7078f4d6ba98fb31f2e17c4c57b7e" dependencies = [ "bytes", - "futures-util", "memchr", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "concurrent-queue" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" -dependencies = [ - "cache-padded", ] [[package]] @@ -256,7 +102,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "crossbeam-channel", "crossbeam-deque", "crossbeam-epoch", @@ -292,7 +138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ "autocfg", - "cfg-if", + "cfg-if 0.1.10", "crossbeam-utils", "lazy_static", "maybe-uninit", @@ -306,7 +152,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "crossbeam-utils", "maybe-uninit", ] @@ -318,15 +164,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ "autocfg", - "cfg-if", + "cfg-if 0.1.10", "lazy_static", ] [[package]] name = "dtoa" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" +checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" [[package]] name = "env_logger" @@ -342,138 +188,31 @@ dependencies = [ ] [[package]] -name = "event-listener" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" - -[[package]] -name = "fastrand" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" -dependencies = [ - "instant", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "futures-channel" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a4d35f7401e948629c9c3d6638fb9bf94e0b2121e96c3b428cc4e631f3eb74" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d674eaa0056896d5ada519900dbf97ead2e46a7b6621e8160d79e2f2e1e2784b" - -[[package]] -name = "futures-io" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc94b64bb39543b4e432f1790b6bf18e3ee3b74653c5449f63310e9a74b123c" - -[[package]] -name = "futures-lite" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "381a7ad57b1bad34693f63f6f377e1abded7a9c85c9d3eb6771e11c60aaadab9" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - -[[package]] -name = "futures-sink" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8764258ed64ebc5d9ed185cf86a95db5cac810269c5d20ececb32e0088abbd" - -[[package]] -name = "futures-task" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd26820a9f3637f1302da8bceba3ff33adbe53464b54ca24d4e2d4f1db30f94" -dependencies = [ - "once_cell", -] - -[[package]] -name = "futures-util" -version = "0.3.6" +name = "form_urlencoded" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a894a0acddba51a2d49a6f4263b1e64b8c579ece8af50fa86503d52cd1eea34" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "memchr", - "pin-project", - "pin-utils", - "slab", + "matches", + "percent-encoding", ] [[package]] name = "getrandom" -version = "0.1.15" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] -[[package]] -name = "gloo-timers" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -489,9 +228,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" dependencies = [ "matches", "unicode-bidi", @@ -500,55 +239,18 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "cfg-if", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", + "cfg-if 1.0.0", ] [[package]] name = "itoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" - -[[package]] -name = "js-sys" -version = "0.3.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "lazy_static" @@ -558,9 +260,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.79" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" [[package]] name = "lobby-model" @@ -573,20 +275,20 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -603,9 +305,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "memoffset" @@ -618,7 +320,7 @@ dependencies = [ [[package]] name = "micro-game-lobby" -version = "0.2.1" +version = "1.0.0" dependencies = [ "bincode", "core-model", @@ -628,52 +330,10 @@ dependencies = [ "lobby-model", "log", "move-model", - "redis 0.17.0", + "redis", "redis_streams", ] -[[package]] -name = "mio" -version = "0.6.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" -dependencies = [ - "cfg-if", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio", -] - -[[package]] -name = "miow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "move-model" version = "0.4.0" @@ -685,54 +345,11 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "nb-connect" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" -dependencies = [ - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "net2" -version = "0.2.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" -dependencies = [ - "cfg-if", - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" - -[[package]] -name = "parking" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" - [[package]] name = "parking_lot" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" dependencies = [ "instant", "lock_api", @@ -741,17 +358,16 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if", - "cloudabi", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -760,62 +376,11 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pin-project" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e555d9e657502182ac97b539fb3dae8b79cda19e3e4f8ffb5e8de4f18df93c95" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "polling" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" -dependencies = [ - "cfg-if", - "libc", - "log", - "wepoll-sys", - "winapi 0.3.9", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" - [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -828,9 +393,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] @@ -846,122 +411,57 @@ dependencies = [ "scheduled-thread-pool", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] - -[[package]] -name = "redis" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b94c6247d45d78d24481a5b7aca146f414ec0f5e39e175f294d1876b943eeeb" -dependencies = [ - "async-std", - "async-trait", - "bytes", - "combine", - "dtoa", - "futures-util", - "itoa", - "percent-encoding", - "pin-project-lite", - "sha1", - "tokio", - "tokio-util", - "url", -] - [[package]] name = "redis" -version = "0.17.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95357caf2640abc54651b93c98a8df4fe1ccbf44b8e601ccdf43d5c1451f29ac" +checksum = "0a32cb439c4e89c1e6415e5b3b23d9d8cc6dc1bf5a8cade19adbd5418de803be" dependencies = [ - "async-std", "async-trait", - "bytes", "combine", "dtoa", - "futures-util", "itoa", "percent-encoding", - "pin-project-lite", "r2d2", "sha1", - "tokio", - "tokio-util", "url", ] [[package]] name = "redis_streams" -version = "0.3.0" -source = "git+https://github.com/Terkwood/BUGOUT?rev=92b8d91abba494737caca525ecb2a4f0d7044dbd#92b8d91abba494737caca525ecb2a4f0d7044dbd" +version = "1.0.0" +source = "git+https://github.com/Terkwood/BUGOUT?rev=a394d46#a394d4650faba1c834770d9213323617208c53ab" dependencies = [ - "redis 0.16.0", + "anyhow", + "redis", "uuid", ] [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +dependencies = [ + "bitflags", +] [[package]] name = "regex" -version = "1.4.1" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.20" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "scheduled-thread-pool" @@ -980,18 +480,15 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.117" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" -dependencies = [ - "serde_derive", -] +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" [[package]] name = "serde_derive" -version = "1.0.117" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ "proc-macro2", "quote", @@ -1004,23 +501,17 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - [[package]] name = "smallvec" -version = "1.4.2" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "syn" -version = "1.0.45" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9c5432ff16d6152371f808fb5a871cd67368171b09bb21b43df8e4a47a3556" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -1029,90 +520,59 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] -[[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - [[package]] name = "tinyvec" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" - -[[package]] -name = "tokio" -version = "0.2.22" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" dependencies = [ - "bytes", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "libc", - "memchr", - "mio", - "mio-uds", - "pin-project-lite", + "tinyvec_macros", ] [[package]] -name = "tokio-util" -version = "0.3.1" +name = "tinyvec_macros" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" dependencies = [ "matches", ] [[package]] name = "unicode-normalization" -version = "0.1.13" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +checksum = "33717dca7ac877f497014e10d73f3acf948c342bee31b5ca7892faf94ccc6b49" dependencies = [ "tinyvec", ] [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "url" -version = "2.1.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ + "form_urlencoded", "idna", "matches", "percent-encoding", @@ -1120,122 +580,19 @@ dependencies = [ [[package]] name = "uuid" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "rand", + "getrandom", "serde", ] -[[package]] -name = "vec-arena" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" - -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "wasm-bindgen" -version = "0.2.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" - -[[package]] -name = "web-sys" -version = "0.3.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "wepoll-sys" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142bc2cba3fe88be1a8fcb55c727fa4cd5b0cf2d7438722792e22f26f04bc1e0" -dependencies = [ - "cc", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "winapi" @@ -1247,12 +604,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1265,7 +616,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1273,13 +624,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/micro-game-lobby/Cargo.toml b/micro-game-lobby/Cargo.toml index 25afd6543..9f1118c9b 100644 --- a/micro-game-lobby/Cargo.toml +++ b/micro-game-lobby/Cargo.toml @@ -2,7 +2,7 @@ authors = ["terkwood <38859656+Terkwood@users.noreply.github.com>"] edition = "2018" name = "micro-game-lobby" -version = "0.2.1" +version = "1.0.0" [dependencies] bincode = "1.2.1" @@ -13,5 +13,5 @@ env_logger = "0.7.1" lobby-model = {path = "lobby-model"} log = "0.4.8" move-model = {git = "https://github.com/Terkwood/BUGOUT", rev = "20e6620"} -redis = {version = "0.17.0", features = ["r2d2"]} -redis_streams = {git = "https://github.com/Terkwood/BUGOUT", version = "0.3.0", rev = "92b8d91abba494737caca525ecb2a4f0d7044dbd"} +redis = {version = "0.20.0", features = ["r2d2"]} +redis_streams = {git = "https://github.com/Terkwood/BUGOUT", rev = "a394d46"} diff --git a/micro-game-lobby/src/components.rs b/micro-game-lobby/src/components.rs index 212032bc3..8633942fc 100644 --- a/micro-game-lobby/src/components.rs +++ b/micro-game-lobby/src/components.rs @@ -1,13 +1,10 @@ use crate::repo::GameLobbyRepo; -use crate::stream::{XAck, XAdd, XRead}; - +use crate::stream::XAdd; use std::rc::Rc; pub struct Components { pub game_lobby_repo: Box, - pub xread: Box, pub xadd: Box, - pub xack: Box, } const REDIS_URL: &str = "redis://redis/"; @@ -20,9 +17,7 @@ impl Components { pub fn new(client: Rc) -> Self { Components { game_lobby_repo: Box::new(client.clone()), - xread: Box::new(client.clone()), - xadd: Box::new(client.clone()), - xack: Box::new(client), + xadd: Box::new(client), } } } diff --git a/micro-game-lobby/src/main.rs b/micro-game-lobby/src/main.rs index a3a11021d..040e4aac1 100644 --- a/micro-game-lobby/src/main.rs +++ b/micro-game-lobby/src/main.rs @@ -3,11 +3,39 @@ use micro_game_lobby::*; const VERSION: &str = env!("CARGO_PKG_VERSION"); +use redis_streams::{anyhow, Message, RedisSortedStreams, XId}; + fn main() { env_logger::init(); info!("🔢 {}", VERSION); let client = redis_client(); let components = Components::new(client.clone()); stream::create_consumer_group(&client); - stream::process(&components) + + let lobby = stream::LobbyStreams::new(components); + + let mut conn = client.get_connection().expect("redis conn"); + let stream_handlers: Vec<(&str, Box anyhow::Result<()>>)> = vec![ + ( + topics::FIND_PUBLIC_GAME, + Box::new(|_xid, msg| lobby.consume_fpg(msg)), + ), + ( + topics::JOIN_PRIVATE_GAME, + Box::new(|_xid, msg| lobby.consume_jpg(msg)), + ), + ( + topics::CREATE_GAME, + Box::new(|_xid, msg| lobby.consume_cg(msg)), + ), + ( + topics::SESSION_DISCONNECTED, + Box::new(|_xid, msg| lobby.consume_sd(msg)), + ), + ]; + let mut streams = + RedisSortedStreams::xgroup_create_mkstreams(stream_handlers, &stream::opts(), &mut conn) + .expect("stream creation"); + + lobby.process(&mut streams) } diff --git a/micro-game-lobby/src/stream/mod.rs b/micro-game-lobby/src/stream/mod.rs index 8c2f57080..da3015bac 100644 --- a/micro-game-lobby/src/stream/mod.rs +++ b/micro-game-lobby/src/stream/mod.rs @@ -1,12 +1,10 @@ mod init; -mod xack; mod xadd; -mod xread; pub use init::*; -pub use xack::*; +use redis_streams::ConsumerGroupOpts; +use redis_streams::SortedStreams; pub use xadd::*; -pub use xread::*; use crate::components::Components; use crate::game_lobby::GameLobbyOps; @@ -14,12 +12,20 @@ use crate::PUBLIC_GAME_BOARD_SIZE; use core_model::*; use lobby_model::api::*; use lobby_model::*; -use log::{error, info, trace}; +use log::{error, trace}; use move_model::GameState; -use redis_streams::XReadEntryId; +use redis_streams::Message; pub const GROUP_NAME: &str = "micro-game-lobby"; +#[derive(Clone, Debug)] +pub enum StreamInput { + FPG(FindPublicGame), + CG(CreateGame), + JPG(JoinPrivateGame), + SD(SessionDisconnected), +} + #[derive(Debug, Clone, PartialEq)] pub enum StreamOutput { WFO(WaitForOpponent), @@ -28,140 +34,173 @@ pub enum StreamOutput { LOG(GameState), } -pub fn process(reg: &Components) { - let mut unacked = Unacknowledged::default(); - loop { - match reg.xread.xread_sorted() { - Ok(xrr) => { - for (xid, data) in xrr { - info!("🧮 Processing {:?}", &data); - consume(xid, &data, ®); - unacked.push(xid, data); - } - } - Err(e) => error!("Stream err {:?}", e), - } +pub struct LobbyStreams { + pub reg: Components, +} - unacked.ack_all(®) +use redis_streams::Group; +const BLOCK_MS: usize = 5000; +pub fn opts() -> ConsumerGroupOpts { + ConsumerGroupOpts { + block_ms: BLOCK_MS, + group: Group { + group_name: GROUP_NAME.to_string(), + consumer_name: "singleton".to_string(), + }, } } -fn consume(_eid: XReadEntryId, event: &StreamInput, reg: &Components) { - match event { - StreamInput::FPG(fpg) => consume_fpg(fpg, reg), - StreamInput::CG(cg) => consume_cg(cg, reg), - StreamInput::JPG(jpg) => consume_jpg(jpg, reg), - StreamInput::SD(sd) => consume_sd(sd, reg), +use redis_streams::anyhow; +impl LobbyStreams { + pub fn new(reg: Components) -> Self { + Self { reg } } -} -fn consume_fpg(fpg: &FindPublicGame, reg: &Components) { - let visibility = Visibility::Public; - let session_id = &fpg.session_id; - if let Ok(lobby) = reg.game_lobby_repo.get() { - if let Some(queued) = lobby - .games - .iter() - .find(|g| g.visibility == Visibility::Public) - { - ready_game(session_id, &lobby, queued, reg) - } else { - let game_id = GameId::new(); - let updated: GameLobby = lobby.open(Game { - board_size: PUBLIC_GAME_BOARD_SIZE, - creator: session_id.clone(), - visibility, - game_id: game_id.clone(), - }); - if let Err(_) = reg.game_lobby_repo.put(&updated) { - error!("game lobby write F2"); - } else { - if let Err(_) = reg.xadd.xadd(StreamOutput::WFO(WaitForOpponent { - event_id: EventId::new(), - game_id, - session_id: session_id.clone(), - visibility, - })) { - error!("XADD: Wait for oppo") - } else { - trace!("Public game open. Lobby: {:?}", &updated) - } + pub fn process(&self, streams: &mut dyn SortedStreams) { + loop { + if let Err(e) = streams.consume() { + error!("Stream err {:?}", e) } } - } else { - error!("Failed to fetch game lobby: FPG") } -} -fn consume_cg(cg: &CreateGame, reg: &Components) { - let session_id = &cg.session_id; - let game_id = cg.game_id.clone().unwrap_or(GameId::new()); - if let Ok(lobby) = reg.game_lobby_repo.get() { - let updated: GameLobby = lobby.open(Game { - game_id: game_id.clone(), - board_size: cg.board_size, - creator: session_id.clone(), - visibility: cg.visibility, - }); - if let Err(_) = reg.game_lobby_repo.put(&updated) { - error!("game lobby write F1"); + pub fn consume_fpg(&self, msg: &Message) -> anyhow::Result<()> { + let maybe_value = msg.get("data"); + Ok(if let Some(redis::Value::Data(data)) = maybe_value { + let fpg: FindPublicGame = bincode::deserialize(&data)?; + let reg = &self.reg; + let visibility = Visibility::Public; + let session_id = &fpg.session_id; + if let Ok(lobby) = reg.game_lobby_repo.get() { + if let Some(queued) = lobby + .games + .iter() + .find(|g| g.visibility == Visibility::Public) + { + ready_game(session_id, &lobby, queued, ®) + } else { + let game_id = GameId::new(); + let updated: GameLobby = lobby.open(Game { + board_size: PUBLIC_GAME_BOARD_SIZE, + creator: session_id.clone(), + visibility, + game_id: game_id.clone(), + }); + if let Err(_) = reg.game_lobby_repo.put(&updated) { + error!("game lobby write F2"); + } else { + if let Err(_) = reg.xadd.xadd(StreamOutput::WFO(WaitForOpponent { + event_id: EventId::new(), + game_id, + session_id: session_id.clone(), + visibility, + })) { + error!("XADD: Wait for oppo") + } else { + trace!("Public game open. Lobby: {:?}", &updated) + } + } + } + } else { + error!("Failed to fetch game lobby: FPG") + } } else { - if let Err(_) = reg.xadd.xadd(StreamOutput::WFO(WaitForOpponent { - game_id: game_id.clone(), - session_id: session_id.clone(), - event_id: EventId::new(), - visibility: cg.visibility, - })) { - error!("XADD Game ready") + error!("could not deserialize FPG data field") + }) + } + + pub fn consume_cg(&self, msg: &Message) -> anyhow::Result<()> { + let maybe_value = msg.get("data"); + Ok(if let Some(redis::Value::Data(data)) = maybe_value { + let cg: CreateGame = bincode::deserialize(&data)?; + + let session_id = &cg.session_id; + let game_id = cg.game_id.clone().unwrap_or(GameId::new()); + if let Ok(lobby) = self.reg.game_lobby_repo.get() { + let updated: GameLobby = lobby.open(Game { + game_id: game_id.clone(), + board_size: cg.board_size, + creator: session_id.clone(), + visibility: cg.visibility, + }); + if let Err(_) = self.reg.game_lobby_repo.put(&updated) { + error!("game lobby write F1"); + } else { + if let Err(_) = self.reg.xadd.xadd(StreamOutput::WFO(WaitForOpponent { + game_id: game_id.clone(), + session_id: session_id.clone(), + event_id: EventId::new(), + visibility: cg.visibility, + })) { + error!("XADD Game ready") + } else { + trace!("Game created. Lobby: {:?}", &updated); + } + } } else { - trace!("Game created. Lobby: {:?}", &updated); + error!("CG GAME REPO GET") } - } - } else { - error!("CG GAME REPO GET") - } -} -/// Consumes the command to join a private game. -/// In the event that the game is invalid, -/// we will simply log a warning. -/// Consider implementing logic related to handling -/// private game rejection: https://github.com/Terkwood/BUGOUT/issues/304 -fn consume_jpg(jpg: &JoinPrivateGame, reg: &Components) { - if let Ok(lobby) = reg.game_lobby_repo.get() { - if let Some(queued) = lobby - .games - .iter() - .find(|g| g.visibility == Visibility::Private && g.game_id == jpg.game_id) - { - ready_game(&jpg.session_id, &lobby, queued, reg) } else { - if let Err(e) = reg.xadd.xadd(StreamOutput::PGR(PrivateGameRejected { - client_id: jpg.client_id.clone(), - event_id: EventId::new(), - game_id: jpg.game_id.clone(), - session_id: jpg.session_id.clone(), - })) { - error!("Error writing private game rejection to stream {:?}", e) + error!("could not deser create game data field") + }) + } + + /// Consumes the command to join a private game. + /// In the event that the game is invalid, + /// we will simply log a warning. + /// Consider implementing logic related to handling + /// private game rejection: https://github.com/Terkwood/BUGOUT/issues/304 + pub fn consume_jpg(&self, msg: &Message) -> anyhow::Result<()> { + let maybe_value = msg.get("data"); + Ok(if let Some(redis::Value::Data(data)) = maybe_value { + let jpg: JoinPrivateGame = bincode::deserialize(&data)?; + + let reg = &self.reg; + if let Ok(lobby) = reg.game_lobby_repo.get() { + if let Some(queued) = lobby + .games + .iter() + .find(|g| g.visibility == Visibility::Private && g.game_id == jpg.game_id) + { + ready_game(&jpg.session_id, &lobby, queued, reg) + } else { + if let Err(e) = reg.xadd.xadd(StreamOutput::PGR(PrivateGameRejected { + client_id: jpg.client_id.clone(), + event_id: EventId::new(), + game_id: jpg.game_id.clone(), + session_id: jpg.session_id.clone(), + })) { + error!("Error writing private game rejection to stream {:?}", e) + } + } + } else { + error!("game lobby JPG get") } - } - } else { - error!("game lobby JPG get") - } -} - -fn consume_sd(sd: &SessionDisconnected, reg: &Components) { - if let Ok(game_lobby) = reg.game_lobby_repo.get() { - let updated: GameLobby = game_lobby.abandon(&sd.session_id); - if let Err(_) = reg.game_lobby_repo.put(&updated) { - error!("game lobby write F1"); } else { - trace!("session {} abandoned: {:?}", sd.session_id.0, &updated); - } - } else { - error!("SD GAME REPO GET") + error!("could not consume JoinPrivateGame data field") + }) + } + + pub fn consume_sd(&self, msg: &Message) -> anyhow::Result<()> { + let maybe_value = msg.get("data"); + Ok(if let Some(redis::Value::Data(data)) = maybe_value { + let sd: SessionDisconnected = bincode::deserialize(&data)?; + let reg = &self.reg; + if let Ok(game_lobby) = reg.game_lobby_repo.get() { + let updated: GameLobby = game_lobby.abandon(&sd.session_id); + if let Err(_) = reg.game_lobby_repo.put(&updated) { + error!("game lobby write F1"); + } else { + trace!("session {} abandoned: {:?}", sd.session_id.0, &updated); + } + } else { + error!("SD GAME REPO GET") + } + } else { + error!("could not deser session disconn data field") + }) } } - fn ready_game(session_id: &SessionId, lobby: &GameLobby, queued: &Game, reg: &Components) { let updated: GameLobby = lobby.ready(queued); if let Err(_) = reg.game_lobby_repo.put(&updated) { @@ -196,220 +235,3 @@ fn init_changelog(game_id: &GameId, board_size: u16, reg: &Components) { error!("could not write game state changelog {:?}", chgerr) } } - -#[cfg(test)] -mod test { - use super::*; - use crate::components::Components; - use crate::repo::*; - use crossbeam_channel::{select, unbounded, Sender}; - use redis_streams::XReadEntryId; - use std::sync::{Arc, Mutex}; - use std::time::Duration; - - use std::thread; - - struct FakeGameLobbyRepo { - pub contents: Arc>, - } - - impl GameLobbyRepo for FakeGameLobbyRepo { - fn get(&self) -> Result { - Ok(self.contents.lock().expect("mutex lock").clone()) - } - fn put(&self, game_lobby: &GameLobby) -> Result<(), WriteErr> { - let mut data = self.contents.lock().expect("lock"); - *data = game_lobby.clone(); - Ok(()) - } - } - - struct FakeXRead { - sorted_data: Arc>>, - } - impl XRead for FakeXRead { - /// Be careful, this implementation assumes - /// that the underlying data is pre-sorted - fn xread_sorted( - &self, - ) -> Result, XReadErr> { - { - let mut data = self.sorted_data.lock().expect("lock"); - if data.is_empty() { - // stop the test thread from spinning like crazy - std::thread::sleep(Duration::from_millis(1)); - Ok(vec![]) - } else { - let result = data.clone(); - *data = vec![]; - Ok(result) - } - } - } - } - struct FakeXAdd(Sender); - impl XAdd for FakeXAdd { - fn xadd(&self, data: StreamOutput) -> Result<(), XAddErr> { - if let Err(_) = self.0.send(data) {} - Ok(()) - } - } - - enum AckType { - FPG, - CG, - JPG, - SD, - } - struct ItWasAcked { - ack_type: AckType, - xids: Vec, - } - struct FakeXAck(Sender); - impl XAck for FakeXAck { - fn ack_find_public_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - if let Err(_) = self.0.send(ItWasAcked { - ack_type: AckType::FPG, - xids: xids.to_vec(), - }) {} - Ok(()) - } - - fn ack_join_priv_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - Ok(self - .0 - .send(ItWasAcked { - ack_type: AckType::JPG, - xids: xids.to_vec(), - }) - .expect("send")) - } - - fn ack_create_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - Ok(self - .0 - .send(ItWasAcked { - ack_type: AckType::CG, - xids: xids.to_vec(), - }) - .expect("send")) - } - - fn ack_session_disconnected(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - Ok(self - .0 - .send(ItWasAcked { - ack_type: AckType::SD, - xids: xids.to_vec(), - }) - .expect("send")) - } - } - #[test] - fn test_process() { - let (xadd_in, xadd_out) = unbounded(); - let (xack_in, xack_out) = unbounded(); - - let sorted_fake_stream = Arc::new(Mutex::new(vec![])); - - let timeout = Duration::from_millis(160); - - // set up a loop to process game lobby requests - let fake_game_lobby_contents = Arc::new(Mutex::new(GameLobby::default())); - - let sfs = sorted_fake_stream.clone(); - let fgl = fake_game_lobby_contents.clone(); - - thread::spawn(move || { - let components = Components { - game_lobby_repo: Box::new(FakeGameLobbyRepo { contents: fgl }), - xread: Box::new(FakeXRead { - sorted_data: sfs.clone(), - }), - xadd: Box::new(FakeXAdd(xadd_in)), - xack: Box::new(FakeXAck(xack_in)), - }; - process(&components); - }); - - // emit some events in a time-ordered fashion - // (we need to use time-ordered push since the - // FakeXRead impl won't sort its underlying data ) - - let mut fake_time_ms = 100; - let incr_ms = 100; - - let session_b = SessionId::new(); - let session_w = SessionId::new(); - let client_b = ClientId::new(); - let client_w = ClientId::new(); - let xid0 = quick_eid(fake_time_ms); - sorted_fake_stream.lock().expect("lock").push(( - xid0, - StreamInput::FPG(FindPublicGame { - client_id: client_w.clone(), - session_id: session_w.clone(), - }), - )); - - thread::sleep(timeout); - // We should have seen a single XACK for a find public game record - select! { - recv(xack_out) -> msg => match msg { - Ok(ItWasAcked { ack_type: AckType::FPG , xids }) => { - assert_eq!(xids.len(), 1); - assert_eq!(xids[0], xid0) - } - _ => panic!("fpg ack") - } - } - - // The game lobby repo should now contain one game - assert_eq!( - fake_game_lobby_contents - .clone() - .lock() - .expect("gl") - .games - .iter() - .collect::>() - .len(), - 1 - ); - - // There should be an XADD triggered for a wait-for-opponent - // message - select! { - recv(xadd_out) -> msg => match msg { - Ok(StreamOutput::WFO(_)) => assert!(true), - _ => panic!("wrong output") - }, - default(timeout) => panic!("WAIT timeout") - } - - fake_time_ms += incr_ms; - sorted_fake_stream.lock().expect("lock").push(( - quick_eid(fake_time_ms), - StreamInput::FPG(FindPublicGame { - client_id: client_b, - session_id: session_b, - }), - )); - - // There should now be GameReady in stream - select! { - recv(xadd_out) -> msg => match msg { - Ok(StreamOutput::GR(_)) => assert!(true), - _ => assert!(false) - }, - default(timeout) => panic!("GR time out") - } - } - - fn quick_eid(ms: u64) -> XReadEntryId { - XReadEntryId { - millis_time: ms, - seq_no: 0, - } - } -} diff --git a/micro-game-lobby/src/stream/xack.rs b/micro-game-lobby/src/stream/xack.rs deleted file mode 100644 index 884c2c907..000000000 --- a/micro-game-lobby/src/stream/xack.rs +++ /dev/null @@ -1,111 +0,0 @@ -use crate::stream::StreamInput; -use crate::topics; -use crate::Components; -use log::error; -use redis::{Client, Commands}; -use redis_streams::XReadEntryId; - -pub trait XAck { - fn ack_find_public_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr>; - fn ack_join_priv_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr>; - fn ack_create_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr>; - fn ack_session_disconnected(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr>; -} - -impl XAck for std::rc::Rc { - fn ack_find_public_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - ack(self, topics::FIND_PUBLIC_GAME, xids) - } - - fn ack_join_priv_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - ack(self, topics::JOIN_PRIVATE_GAME, xids) - } - - fn ack_create_game(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - ack(self, topics::CREATE_GAME, xids) - } - - fn ack_session_disconnected(&self, xids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - ack(self, topics::SESSION_DISCONNECTED, xids) - } -} - -#[derive(Debug)] -pub struct StreamAckErr; - -pub struct Unacknowledged { - fpg: Vec, - jpg: Vec, - cg: Vec, - sd: Vec, -} - -impl Unacknowledged { - pub fn ack_all(&mut self, reg: &Components) { - if !self.fpg.is_empty() { - if let Err(_e) = reg.xack.ack_find_public_game(&self.fpg) { - error!("ack for fpg failed") - } else { - self.fpg.clear(); - } - } - - if !self.jpg.is_empty() { - if let Err(_e) = reg.xack.ack_join_priv_game(&self.jpg) { - error!("ack for jpg failed") - } else { - self.jpg.clear(); - } - } - if !self.cg.is_empty() { - if let Err(_e) = reg.xack.ack_create_game(&self.cg) { - error!("ack for create game failed") - } else { - self.cg.clear(); - } - } - if !self.sd.is_empty() { - if let Err(_e) = reg.xack.ack_session_disconnected(&self.sd) { - error!("ack for session disconn failed") - } else { - self.sd.clear(); - } - } - } - pub fn push(&mut self, xid: XReadEntryId, event: StreamInput) { - match event { - StreamInput::FPG(_) => self.fpg.push(xid), - StreamInput::JPG(_) => self.jpg.push(xid), - StreamInput::CG(_) => self.cg.push(xid), - StreamInput::SD(_) => self.sd.push(xid), - } - } -} - -const INIT_ACK_CAPACITY: usize = 50; -impl Default for Unacknowledged { - fn default() -> Self { - Self { - fpg: Vec::with_capacity(INIT_ACK_CAPACITY), - jpg: Vec::with_capacity(INIT_ACK_CAPACITY), - cg: Vec::with_capacity(INIT_ACK_CAPACITY), - sd: Vec::with_capacity(INIT_ACK_CAPACITY), - } - } -} - -fn ack(client: &Client, key: &str, ids: &[XReadEntryId]) -> Result<(), StreamAckErr> { - if let Ok(mut conn) = client.get_connection() { - let idstrs: Vec = ids.iter().map(|id| id.to_string()).collect(); - let _: usize = conn.xack(key, super::GROUP_NAME, &idstrs)?; - Ok(()) - } else { - Err(StreamAckErr) - } -} - -impl From for StreamAckErr { - fn from(_: redis::RedisError) -> Self { - Self - } -} diff --git a/micro-game-lobby/src/stream/xread.rs b/micro-game-lobby/src/stream/xread.rs deleted file mode 100644 index 2114adf98..000000000 --- a/micro-game-lobby/src/stream/xread.rs +++ /dev/null @@ -1,125 +0,0 @@ -use super::GROUP_NAME; -use crate::topics::*; -use lobby_model::api::*; -use log::{error, warn}; -use redis::streams::{StreamReadOptions, StreamReadReply}; -use redis::{Client, Commands}; -use redis_streams::XReadEntryId; -use std::collections::HashMap; -use std::rc::Rc; - -const BLOCK_MS: usize = 5000; - -/// xread_sorted performs a redis xread then sorts the results -/// -/// entry_ids: the minimum entry ids from which to read -pub trait XRead { - fn xread_sorted(&self) -> Result, XReadErr>; -} - -#[derive(Debug)] -pub enum XReadErr { - Deser(XReadDeserErr), - Other, -} -const READ_OP: &str = ">"; - -impl XRead for Rc { - fn xread_sorted(&self) -> Result, XReadErr> { - if let Ok(mut conn) = self.get_connection() { - let opts = StreamReadOptions::default() - .block(BLOCK_MS) - .group(GROUP_NAME, "singleton"); - let xrr = conn.xread_options( - &[ - FIND_PUBLIC_GAME, - CREATE_GAME, - JOIN_PRIVATE_GAME, - SESSION_DISCONNECTED, - ], - &[READ_OP, READ_OP, READ_OP, READ_OP], - opts, - ); - - if let Ok(x) = xrr { - match deser(x) { - Ok(unsorted) => { - let mut sorted_keys: Vec = - unsorted.keys().map(|k| *k).collect(); - sorted_keys.sort(); - - let mut answer = vec![]; - for sk in sorted_keys { - if let Some(data) = unsorted.get(&sk) { - answer.push((sk, data.clone())) - } - } - Ok(answer) - } - Err(e) => Err(XReadErr::Deser(e)), - } - } else { - Err(XReadErr::Other) - } - } else { - Err(XReadErr::Other) - } - } -} - -fn deser(srr: StreamReadReply) -> Result, XReadDeserErr> { - let mut out = HashMap::new(); - for k in srr.keys { - let key = k.key; - for e in k.ids { - if let Ok(eid) = XReadEntryId::from_str(&e.id) { - let maybe_data: Option> = e.get("data"); - if let Some(data) = maybe_data { - let sd: Option = if key == FIND_PUBLIC_GAME { - bincode::deserialize(&data) - .map(|fpg| StreamInput::FPG(fpg)) - .ok() - } else if key == CREATE_GAME { - bincode::deserialize(&data) - .map(|cg| StreamInput::CG(cg)) - .ok() - } else if key == JOIN_PRIVATE_GAME { - bincode::deserialize(&data) - .map(|jpg| StreamInput::JPG(jpg)) - .ok() - } else if key == SESSION_DISCONNECTED { - bincode::deserialize(&data) - .map(|sd| StreamInput::SD(sd)) - .ok() - } else { - warn!("Unknown key {}", key); - None - }; - if let Some(s) = sd { - out.insert(eid, s); - } else { - return Err(XReadDeserErr::DataDeser(key)); - } - } - } else { - error!("eid-ish"); - return Err(XReadDeserErr::EIDFormat); - } - } - } - Ok(out) -} - -#[derive(Debug)] -pub enum XReadDeserErr { - EIDFormat, - DataDeser(String), -} - -#[derive(Clone, Debug)] -pub enum StreamInput { - FPG(FindPublicGame), - CG(CreateGame), - JPG(JoinPrivateGame), - SD(SessionDisconnected), -}