diff --git a/Cargo.lock b/Cargo.lock index c26c129..5a8e505 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,188 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "actix-codec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" +dependencies = [ + "bitflags 2.6.0", + "bytes", + "futures-core", + "futures-sink", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "actix-http" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae682f693a9cd7b058f2b0b5d9a6d7728a8555779bedbbc35dd88528611d020" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "ahash", + "base64", + "bitflags 2.6.0", + "brotli", + "bytes", + "bytestring", + "derive_more", + "encoding_rs", + "flate2", + "futures-core", + "h2", + "http", + "httparse", + "httpdate", + "itoa", + "language-tags", + "local-channel", + "mime", + "percent-encoding", + "pin-project-lite", + "rand", + "sha1", + "smallvec", + "tokio", + "tokio-util", + "tracing", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "actix-router" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" +dependencies = [ + "bytestring", + "cfg-if", + "http", + "regex", + "regex-lite", + "serde", + "tracing", +] + +[[package]] +name = "actix-rt" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208" +dependencies = [ + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b02303ce8d4e8be5b855af6cf3c3a08f3eff26880faad82bab679c22d3650cb5" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "futures-util", + "mio", + "socket2", + "tokio", + "tracing", +] + +[[package]] +name = "actix-service" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b894941f818cfdc7ccc4b9e60fa7e53b5042a2e8567270f9147d5591893373a" +dependencies = [ + "futures-core", + "paste", + "pin-project-lite", +] + +[[package]] +name = "actix-utils" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +dependencies = [ + "local-waker", + "pin-project-lite", +] + +[[package]] +name = "actix-web" +version = "4.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1988c02af8d2b718c05bc4aeb6a66395b7cdf32858c2c71131e5637a8c05a9ff" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "ahash", + "bytes", + "bytestring", + "cfg-if", + "cookie", + "derive_more", + "encoding_rs", + "futures-core", + "futures-util", + "itoa", + "language-tags", + "log", + "mime", + "once_cell", + "pin-project-lite", + "regex", + "regex-lite", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2", + "time", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f591380e2e68490b5dfaf1dd1aa0ebe78d84ba7067078512b4ea6e4492d622b8" +dependencies = [ + "actix-router", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "addr2line" version = "0.22.0" @@ -17,12 +199,49 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "aligned-vec" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "anyhow" version = "1.0.86" @@ -96,6 +315,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bincode" version = "1.3.3" @@ -125,9 +350,39 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitstream-io" -version = "2.4.2" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415f8399438eb5e4b2f73ed3152a3448b98149dda642a957ee704e1daa5cf1d8" +checksum = "7c12d1856e42f0d817a835fe55853957c85c8c8a470114029143d3f12671446e" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "brotli" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] [[package]] name = "built" @@ -149,9 +404,9 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" [[package]] name = "bytemuck" -version = "1.16.1" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" +checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" [[package]] name = "byteorder" @@ -171,11 +426,20 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "bytestring" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d80203ea6b29df88012294f62733de21cfeab47f17b41af3a38bc30a03ee72" +dependencies = [ + "bytes", +] + [[package]] name = "cc" -version = "1.0.104" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" dependencies = [ "jobserver", "libc", @@ -249,6 +513,32 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cookie" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -289,6 +579,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "csv" version = "1.3.0" @@ -329,17 +629,49 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + [[package]] name = "deunicode" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "339544cc9e2c4dc3fc7149fd630c5f22263a4fdf18a98afd0075784968b5cf00" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "either" -version = "1.13.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] [[package]] name = "equivalent" @@ -407,6 +739,114 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -434,6 +874,25 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.4.1" @@ -462,6 +921,39 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "image" version = "0.25.1" @@ -558,6 +1050,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + [[package]] name = "lazy_static" version = "1.5.0" @@ -645,8 +1143,10 @@ version = "0.1.0" name = "lesson18" version = "0.1.0" dependencies = [ + "actix-web", "ciborium", "eyre", + "futures", "image", "lazy_static", "parking_lot", @@ -654,6 +1154,7 @@ dependencies = [ "serde", "thiserror", "time", + "tokio", ] [[package]] @@ -673,6 +1174,23 @@ dependencies = [ "once_cell", ] +[[package]] +name = "local-channel" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" +dependencies = [ + "futures-core", + "futures-sink", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487" + [[package]] name = "lock_api" version = "0.4.12" @@ -685,9 +1203,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "loop9" @@ -710,9 +1228,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minimal-lexical" @@ -722,9 +1246,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", "simd-adler32", @@ -737,6 +1261,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", + "log", "wasi", "windows-sys 0.48.0", ] @@ -765,9 +1290,9 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "num-bigint" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ "num-integer", "num-traits", @@ -831,9 +1356,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.1" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -884,12 +1409,24 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pin-project-lite" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.30" @@ -923,9 +1460,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -1061,9 +1598,9 @@ dependencies = [ [[package]] name = "ravif" -version = "0.11.7" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67376f469e7e7840d0040bbf4b9b3334005bb167f814621326e4c7ab8cd6e944" +checksum = "bc13288f5ab39e6d7c9d501759712e6969fcc9734220846fc9ed26cae2cc4234" dependencies = [ "avif-serialize", "imgref", @@ -1103,11 +1640,46 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "rgb" -version = "0.8.40" +version = "0.8.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7439be6844e40133eda024efd85bf07f59d0dd2f59b10c00dd6cfb92cc5c741" +checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" dependencies = [ "bytemuck", ] @@ -1118,6 +1690,15 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1130,6 +1711,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" version = "1.0.203" @@ -1152,9 +1739,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -1170,6 +1757,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "server" version = "0.1.0" @@ -1188,6 +1787,17 @@ dependencies = [ "time", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shared" version = "0.1.0" @@ -1230,6 +1840,15 @@ dependencies = [ "quote", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "slug" version = "0.1.5" @@ -1267,9 +1886,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1343,10 +1962,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", + "itoa", "num-conv", "powerfmt", "serde", "time-core", + "time-macros", ] [[package]] @@ -1355,6 +1976,31 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinyvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.38.0" @@ -1385,6 +2031,19 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.8.14" @@ -1419,18 +2078,70 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "v_frame" version = "0.3.8" @@ -1448,6 +2159,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1655,13 +2372,61 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.13" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +checksum = "56c52728401e1dc672a56e81e593e912aa54c78f40246869f78359a2bf24d29d" dependencies = [ "memchr", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zstd" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.11+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75652c55c0b6f3e6f12eb786fe1bc960396bf05a1eb3bf1f3691c3610ac2e6d4" +dependencies = [ + "cc", + "pkg-config", +] + [[package]] name = "zune-core" version = "0.4.12" diff --git a/README.md b/README.md index c7105e2..52d57f6 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ [16](https://www.dropbox.com/scl/fi/3hf3ystbijpvu57f48yua/Lecture-16.MP4?rlkey=qntbm0gmjrt5xr3hjom3drktl&st=t3t5gzuj&dl=0&authuser=0) [17](https://www.dropbox.com/scl/fi/m182zj2hjvn95dckx3616/Lecture-17.MP4?rlkey=9k5f1qub18fkme81v6x1jzozk&st=pg3833ad&dl=0&authuser=0) [18](https://www.dropbox.com/scl/fi/zglhfknjwa39ywefwjox7/Lecture-18.MP4?rlkey=fmb6j1fmzk1zr1imyxbrivipr&st=iutxkn02&dl=0&authuser=0) -19 20 +[19](https://www.dropbox.com/scl/fi/of3f02n3xdcuwfostpciu/Lecture-19.MP4?rlkey=068dvc8udx5nd6508s04j2xvw&st=88l3kw9v&dl=0&authuser=0) + 20 - **DevStreams**: [1](https://www.dropbox.com/scl/fi/t7wfwubrl0361bjwxd5vx/DevStream-1.MP4?rlkey=4i319jzky1eqa3omcbpziuqum&st=t93zhcji&dl=0&authuser=0) diff --git a/files/Cargo.toml b/files/Cargo.toml new file mode 100644 index 0000000..96d2bbb --- /dev/null +++ b/files/Cargo.toml @@ -0,0 +1,20 @@ +[workspace] + +members = [ + "lesson01", + "lesson02", + "lesson05", + "lesson07", + "lesson09", + "lesson11/shared", + "lesson11/client", + "lesson11/server", + "lesson13/client13", + "lesson13/server13", + "lesson13/shared13", + "lesson15", + "lesson16", + "lesson17", + "lesson18", +] +resolver = "2" diff --git a/files/README.md b/files/README.md new file mode 100644 index 0000000..52d57f6 --- /dev/null +++ b/files/README.md @@ -0,0 +1,67 @@ +[![Rust](https://github.com/alembiq/rust-developer/actions/workflows/rust.yml/badge.svg)](https://github.com/alembiq/rust-developer/actions/workflows/rust.yml) + + +# Some random notes and links ;) +## Course related links +- [classroom](https://classroom.google.com/c/NjU2NTMyOTI1NDY3) +- [wiki](https://robot-dreams-rust.mag.wiki/) +- [demo homeworks](https://github.com/Global-Classes-CZE/rust_developer) +#### Recordings +- **Lessons**: [01](https://www.dropbox.com/scl/fi/lxzebh9t16gbuv1nv7v30/Lecture-1.MP4?rlkey=undugghhtnh09leavcgaijn39&st=of9h4va9&dl=0&authuser=0) +[02](https://www.dropbox.com/scl/fi/c5lfm2csaaf7vyz7mgz4c/Lecture-2.MP4?rlkey=pp2w2v2ig054mwf528ogysw4w&st=szbwx2i8&dl=0&authuser=0) +[03](https://www.dropbox.com/scl/fi/e1w9x1p7uqcy2187zgunc/Lecture-3.MP4?rlkey=ocl82uzyoftcwum80wbhlomau&st=u7ybpxv1&dl=0&authuser=0) +[04](https://www.dropbox.com/scl/fi/nfg8qzqlsz7wj7o4kw23p/Lecture-4.MP4?rlkey=gm1h6c3zsd2uqj9f5dah6h46k&st=6z34788w&dl=0&authuser=0) +[05](https://www.dropbox.com/scl/fi/7tlhvg0835y86zi54i9lm/Lecture-5.MP4?rlkey=kkzoq6xq9246meb5316zi33kq&st=84ijzbfy&dl=0&authuser=0) +[06](https://www.dropbox.com/scl/fi/lvm9n122m6c4rvlus5n8h/Lecture-6.MP4?rlkey=v7pvm0dk4khinpzh5984s9uyw&st=kbw3xtjp&dl=0&authuser=0) +[07](https://www.dropbox.com/scl/fi/vzhb43f02dpu6ole88jry/Lecture-7.MP4?rlkey=250sy13x9fk3oi4c4dsqh2kla&st=z2m6j0xt&dl=0&authuser=0) +[08](https://www.dropbox.com/scl/fi/6k06qmchswe25r99827fc/Lecture-8.MP4?rlkey=zlub7hiaxaio9rlhf8o3hvz1a&st=acznjiz9&dl=0&authuser=0) +[09](https://www.dropbox.com/scl/fi/pflqn1qat4de3qy0alm74/Lecture-9.MP4?rlkey=plthacxnqaerwzdebjy3y4g2d&st=6v63rh1j&dl=0&authuser=0) +[10](https://www.dropbox.com/scl/fi/5u4kfw7vkpx4p1q2h1x5d/Lecture-10.MP4?rlkey=i685dq56v03x3vl838a6hlv56&st=x3w2bjpr&dl=0&authuser=0) +[11](https://www.dropbox.com/scl/fi/d4x7w3teq2ay7x1f9ax3m/Lecture-11.MP4?rlkey=4r2zjeejkscxa4x39pv2fnlkw&st=defy23bb&dl=0&authuser=0) +[12](https://www.dropbox.com/scl/fi/af36dxkz7zloj7m5q29qa/Lecture-12.MP4?rlkey=y5lg76g08u21yrm2ib8i0bpfg&st=xh8g60jm&dl=0&authuser=0) +[13](https://www.dropbox.com/scl/fi/hbp7mcyfp99iv0219v9vq/Lecture-13.MP4?rlkey=0799t0it8opno8ea685zllmmv&st=64awwmen&dl=0&authuser=0) +[14](https://www.dropbox.com/scl/fi/u3dttgbaxgqdf8kh6fx3g/Lecture-14.MP4?rlkey=sbkut7t8m3xc45ppwsymv7zuj&st=xon10nni&dl=0&authuser=0) +[15](https://www.dropbox.com/scl/fi/qpdeda3kx646jnwaf8j1s/Lecture-15.MP4?rlkey=b4ng5msydqt5zpm3pz05lqmm7&st=edb0in9i&dl=0&authuser=0) +[16](https://www.dropbox.com/scl/fi/3hf3ystbijpvu57f48yua/Lecture-16.MP4?rlkey=qntbm0gmjrt5xr3hjom3drktl&st=t3t5gzuj&dl=0&authuser=0) +[17](https://www.dropbox.com/scl/fi/m182zj2hjvn95dckx3616/Lecture-17.MP4?rlkey=9k5f1qub18fkme81v6x1jzozk&st=pg3833ad&dl=0&authuser=0) +[18](https://www.dropbox.com/scl/fi/zglhfknjwa39ywefwjox7/Lecture-18.MP4?rlkey=fmb6j1fmzk1zr1imyxbrivipr&st=iutxkn02&dl=0&authuser=0) +[19](https://www.dropbox.com/scl/fi/of3f02n3xdcuwfostpciu/Lecture-19.MP4?rlkey=068dvc8udx5nd6508s04j2xvw&st=88l3kw9v&dl=0&authuser=0) + 20 + +- **DevStreams**: +[1](https://www.dropbox.com/scl/fi/t7wfwubrl0361bjwxd5vx/DevStream-1.MP4?rlkey=4i319jzky1eqa3omcbpziuqum&st=t93zhcji&dl=0&authuser=0) +[2](https://www.dropbox.com/scl/fi/n8mk9lfylmgtpfnnr15lr/DevStream-2.MP4?rlkey=3ixyjsujkif074729ttavj4l8&st=c1c3hfu7&dl=0&authuser=0) + 3 + +#### Classmates homeworks ;) +- [abergasov](https://github.com/abergasov/rd_rust) +- [bhoglo](https://github.com/bhoglo/projects/) +- [bieleluk](https://github.com/bieleluk/rust-developer) +- [b-rowan](https://github.com/b-rowan/braiins-rust-course) +- [czJanKrejci](https://github.com/czJanKrejci/RustDeveloper) +- [HarryRybacki](https://github.com/HarryRybacki/rust_developer) +- [Hugoargui](https://github.com/Hugoargui/rust/) +- [i4nf0x](https://github.com/i4nf0x/rust_course/) +- [JakubKuljovsky](https://github.com/JakubKuljovsky/rust_homeworks) +- [jiri-sedlacek](https://github.com/jiri-sedlacek/rust_course) +- Ma5thewbond [1](https://github.com/ma5thewbond/rust_01_helloworld) [5](https://github.com/ma5thewbond/rust_05_csv_parser/tree/main) [7](https://github.com/ma5thewbond/rust_07_threads) +[9](https://github.com/ma5thewbond/rust_09_networking) [15](https://github.com/ma5thewbond/rust_15_async_chat) +- [moribusV](https://github.com/moribusV/rustCourse/) +- [nlukic97](https://github.com/nlukic97/rust1) +- [oceanbreath](https://github.com/oceanbreath/rust_course) +- [smoofy24](https://github.com/smoofy24/Rust_project) +- [Standazwicky](https://github.com/Standazwicky/rust_homeworks) + +# Tools/links +- [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021) + +## Environment +So far, I'm running these: +- [Rust on NixOs](https://nixos.wiki/wiki/Rust) +- [Rust overlay](https://github.com/oxalica/rust-overlay) +- [direnv to get `nix develop` to VS terminal](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv) + +Alternatives I didn't look into yet +- [crane](https://github.com/ipetkov/crane) +- [naersk](https://github.com/nix-community/naersk) +- [fenix](https://github.com/nix-community/fenix) diff --git a/flake.nix b/flake.nix index 98c423e..80e22f1 100644 --- a/flake.nix +++ b/flake.nix @@ -22,8 +22,8 @@ openssl pkg-config bacon - # rust-bin.stable.latest.default - rust-bin.beta.latest.default + rust-bin.stable.latest.default + # rust-bin.beta.latest.default ]; }; } diff --git a/lesson18/Cargo.toml b/lesson18/Cargo.toml index eed6ea7..3c575d8 100644 --- a/lesson18/Cargo.toml +++ b/lesson18/Cargo.toml @@ -13,3 +13,6 @@ parking_lot = "0.12.3" eyre = "0.6.12" prometheus = "0.13.4" lazy_static = "1.5.0" +actix-web = "4.8.0" +futures = "0.3.30" +tokio = { version = "1.38.0", features = ["full"] } diff --git a/lesson18/README.md b/lesson18/README.md index 38ae780..3f85cf9 100644 --- a/lesson18/README.md +++ b/lesson18/README.md @@ -5,7 +5,7 @@ Server and client that can send messages, files and images (yes, those are also ## Usage You can simply run the `server` and it will start listening on 127.0.0.1:11111. Or you can start it on a specific IP and port - `server18 10.0.42.101:1234`. The same parameter works also for the `client`, it also tries to connect to the same default as server unless you provide server address specifically. -The server also provides some [Prometheus](https://prometheus.io/) metrics you can scrape on `your_ip:9090/metrics`. This will allow you to monitor number of messages processed by the chat app, same as number of active clients and all the client over the runtime of the server. +The server also provides some [Prometheus](https://prometheus.io/) metrics you can scrape on `your_ip:11112/metrics`. This will allow you to monitor number of messages processed by the chat app, same as number of active clients and all the client over the runtime of the server. # Requirements for this homework ;) diff --git a/lesson18/docker/docker-compose.yml b/lesson18/docker/docker-compose.yml index 1c339a4..c18679d 100644 --- a/lesson18/docker/docker-compose.yml +++ b/lesson18/docker/docker-compose.yml @@ -12,6 +12,6 @@ services: environment: - GF_SECURITY_ADMIN_PASSWORD=admin ports: - - "3123:3000" + - "3000:3000" depends_on: - prometheus diff --git a/lesson18/docker/prometheus.yml b/lesson18/docker/prometheus.yml index d3cf925..e821eaa 100644 --- a/lesson18/docker/prometheus.yml +++ b/lesson18/docker/prometheus.yml @@ -4,4 +4,4 @@ global: scrape_configs: - job_name: 'rust_application' static_configs: - - targets: [':10002'] + - targets: [':11112'] diff --git a/lesson18/src/bin/server18.rs b/lesson18/src/bin/server18.rs index b1ef9b3..6de8bc2 100644 --- a/lesson18/src/bin/server18.rs +++ b/lesson18/src/bin/server18.rs @@ -4,21 +4,24 @@ use std::collections::HashMap; use std::env; +use std::io::Result as IoResult; use std::net::{SocketAddr, TcpListener, TcpStream}; use std::sync::Arc; use std::thread; +use actix_web::{http::StatusCode, web, App, HttpResponse, HttpServer, Responder}; use eyre::{bail, Result}; -use parking_lot::Mutex; -// use prometheus::{Gauge, Opts, Registry, Counter}; use lazy_static::lazy_static; +use parking_lot::Mutex; use prometheus::{ - self, register_int_counter, register_int_gauge, Encoder, IntCounter, IntGauge, TextEncoder, + self, gather, register_int_counter, register_int_gauge, Encoder, IntCounter, IntGauge, + Registry, TextEncoder, }; use lesson18::{incoming_message, outgoing_message, server_address, timestamp, MessageType}; lazy_static! { + static ref REGISTRY: Registry = Registry::new(); static ref COUNTER_MESSAGE_TEXT: IntCounter = register_int_counter!("message_text", "Text messages delivered").unwrap(); static ref COUNTER_MESSAGE_FILE: IntCounter = @@ -26,27 +29,52 @@ lazy_static! { static ref COUNTER_MESSAGE_IMAGE: IntCounter = register_int_counter!("message_image", "Images delivered").unwrap(); static ref COUNTER_CLIENTS: IntCounter = - register_int_counter!("clients", "Clients over time").unwrap(); + register_int_counter!("clients_runtime", "Clients over time").unwrap(); static ref GAUGE_CLIENTS: IntGauge = register_int_gauge!("clients_current", "Active clients").unwrap(); } -fn main() -> Result<()> { +/// Generates Prometheus metrics +async fn metrics() -> impl Responder { + let encoder = TextEncoder::new(); + let mut buf = vec![]; + + if let Err(e) = encoder.encode(&gather(), &mut buf) { + eprintln!("Failed to collect metrics: {e}"); + return HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR) + .body("Failed to collect metrics!"); + } + HttpResponse::build(StatusCode::OK).body(String::from_utf8(buf).unwrap()) +} + +/// Webserver for /metrics +async fn metrics_http() -> IoResult<()> { + let _ = HttpServer::new(|| App::new().route("/metrics", web::get().to(metrics))) + .bind("0.0.0.0:11112") + .expect("Failed to bind metrics endpoint") + .run() + .await; + + Ok(()) +} + +#[tokio::main] +async fn main() -> Result<()> { let server_address: String = server_address(env::args().collect()); println!("{} Starting server on {}!", timestamp(), server_address); - // Register & measure some metrics. - let mut buffer = Vec::new(); - let encoder = TextEncoder::new(); - // Gather the metrics. - let metric_families = prometheus::gather(); - // Encode them to send. - encoder.encode(&metric_families, &mut buffer).unwrap(); - let output = String::from_utf8(buffer.clone()).unwrap(); - println!("{output:?}"); + let metrics_handle = tokio::spawn(async { + let _ = metrics_http().await; + }); + let server_handle = tokio::spawn(async { + let _ = listen_and_accept(server_address); + }); + + metrics_handle.await.unwrap(); + server_handle.await.unwrap(); - // Listen and process clients - listen_and_accept(server_address)?; + //TODO find a way how to terminate the server ;) + // listen_and_accept(server_address); Ok(()) } @@ -79,6 +107,7 @@ fn listen_and_accept(address: String) -> Result<()> { Ok(msg) => msg, Err(e) => { eprintln!("{} {addr} stream interrupted: {e}", timestamp()); + // TODO announce disconnected client to everyone and remove everywhere? GAUGE_CLIENTS.dec(); break; } @@ -86,7 +115,7 @@ fn listen_and_accept(address: String) -> Result<()> { // message other clients let mut clients_lock = clients_clone.lock(); - let mut peers_to_remove = vec![]; + let peers_to_remove = vec![]; for (peer_addr, peer_stream) in clients_lock.iter_mut() { if *peer_addr == addr { continue; @@ -94,17 +123,17 @@ fn listen_and_accept(address: String) -> Result<()> { if let Err(e) = outgoing_message(peer_stream, &message) { eprintln!("{} failed to send message: {message:?} -> {e}", timestamp()); - peers_to_remove.push(*peer_addr); } } - + // remove dead clients for peer_addr in peers_to_remove { clients_lock.remove(&peer_addr); + println!("remove dead client {}", &peer_addr); } drop(clients_lock); - //MESSAGE SNEAKPEAK + //MESSAGE SNEAKPEAK and COUNTERS match message { MessageType::Text(text) => { println!("{} {addr}: {text:?}", timestamp());