From f280ed70a8049244dad9fa18902e63a0d6d8d4d0 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 00:29:08 +0100 Subject: [PATCH 01/11] make a start for auth flow --- Cargo.lock | 696 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 7 +- flake.nix | 2 + src/config.rs | 1 + src/flutclient.rs | 34 ++- 5 files changed, 738 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a6b0f7..20669c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,6 +127,12 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6970a22a33d6a8f862aac371bac48505a1bfaa230ecb268c7b86fa4ac6e7121" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.4.0" @@ -456,6 +462,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -579,6 +595,17 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "either" version = "1.13.0" @@ -668,6 +695,7 @@ dependencies = [ "headers", "image", "rand", + "reqwest", "serde", "tempfile", "test-case", @@ -685,6 +713,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -820,6 +863,25 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "h2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.4.1" @@ -933,6 +995,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", + "h2", "http", "http-body", "httparse", @@ -941,6 +1004,40 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", ] [[package]] @@ -950,13 +1047,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", + "futures-channel", "futures-util", "http", "http-body", "hyper", "pin-project-lite", + "socket2", "tokio", "tower-service", + "tracing", ] [[package]] @@ -982,6 +1082,145 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "image" version = "0.25.5" @@ -1042,6 +1281,12 @@ dependencies = [ "syn", ] +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + [[package]] name = "is-terminal" version = "0.4.13" @@ -1136,6 +1381,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "lock_api" version = "0.4.12" @@ -1252,6 +1503,23 @@ dependencies = [ "version_check", ] +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -1355,6 +1623,50 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +[[package]] +name = "openssl" +version = "0.10.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "overload" version = "0.1.1" @@ -1669,12 +1981,70 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "reqwest" +version = "0.12.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.2", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + [[package]] name = "rgb" version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1694,6 +2064,45 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "rustls" +version = "0.23.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.18" @@ -1715,12 +2124,44 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.215" @@ -1865,6 +2306,18 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.90" @@ -1887,6 +2340,41 @@ name = "sync_wrapper" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "system-deps" @@ -1994,6 +2482,16 @@ dependencies = [ "weezl", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -2033,6 +2531,26 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.17" @@ -2231,6 +2749,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "tungstenite" version = "0.24.0" @@ -2267,12 +2791,41 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "utf-8" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "v_frame" version = "0.3.8" @@ -2290,6 +2843,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version-compare" version = "0.2.0" @@ -2312,6 +2871,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2343,6 +2911,19 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.99" @@ -2428,6 +3009,36 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -2519,6 +3130,42 @@ dependencies = [ "memchr", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -2540,6 +3187,55 @@ dependencies = [ "syn", ] +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zune-core" version = "0.4.12" diff --git a/Cargo.toml b/Cargo.toml index 7f87449..d314e3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ futures-util = { version = "0.3.31", features = ["sink", "std"] } headers = "0.4.0" image = "0.25.2" rand = "*" +reqwest = { version = "0.12.9", optional = true } serde = { version = "1.0.210", features = ["derive"] } tokio = { version = "1.38", features = ["full"] } tokio-stream = "0.1.16" @@ -26,7 +27,11 @@ tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } [features] -default = ["text", "binary"] +default = ["text", "binary", "auth"] +# utilities +auth = ["dep:reqwest"] + +# protocols text = [] binary = [] diff --git a/flake.nix b/flake.nix index ee8a048..bc47a8d 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,8 @@ ffpkgs.rustfmt pkgs.wgo tsunami.packages.${system}.tsunami + pkgs.openssl + pkgs.pkg-config ]; }; }); diff --git a/src/config.rs b/src/config.rs index 3318dea..94cc5a4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,6 +6,7 @@ pub const WEB_HOST: &str = "127.0.0.1:3000"; pub const IMAGE_SAVE_INTERVAL: Duration = Duration::from_secs(5); pub const JPEG_UPDATE_INTERVAL: Duration = Duration::from_millis(17); pub const WEB_UPDATE_INTERVAL: Duration = Duration::from_millis(50); +pub const AUTH_SERVER_URL: &str = "https://test.auth/"; pub const HELP_TEXT: &[u8] = b"Flurry is a pixelflut implementation, this means you can use commands to get and set pixels in the canvas SIZE returns the size of the canvas diff --git a/src/flutclient.rs b/src/flutclient.rs index ddd9f2f..6c3cf53 100644 --- a/src/flutclient.rs +++ b/src/flutclient.rs @@ -3,9 +3,12 @@ use std::{ sync::Arc, }; -use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; +#[cfg(feature = "auth")] +use reqwest::{Client, ClientBuilder}; +use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; use crate::{ + config::AUTH_SERVER_URL, get_pixel, grid::{self, Flut}, increment_counter, @@ -74,6 +77,8 @@ where grids: Arc<[Flut]>, parser: ParserTypes, counter: u64, + #[cfg(feature = "auth")] + auth_client: Client, } impl FlutClient @@ -155,10 +160,37 @@ where grids, parser: ParserTypes::default(), counter: 0, + #[cfg(feature = "auth")] + auth_client: ClientBuilder::new().https_only(true).build().unwrap(), } } pub async fn process_socket(&mut self) -> io::Result<()> { + // Handle the auth flow + #[cfg(feature = "auth")] + { + let mut buf = Vec::new(); + let chars = self.reader.read_until(b' ', &mut buf).await?; + if chars != 5 { + return Err(Error::from(ErrorKind::PermissionDenied)); + } + if buf != b"AUTH " { + return Err(Error::from(ErrorKind::PermissionDenied)); + } + + buf.clear(); + let token_length = self.reader.read_until(b'\n', &mut buf).await?; + + if token_length < 100 { + let request = self + .auth_client + .post(AUTH_SERVER_URL) + .body(buf) + .build() + .unwrap(); + let response = self.auth_client.execute(request).await.unwrap(); + } + } loop { match_parser!(parser: &self.parser.clone() => 'outer: loop { for _ in 0..1000 { From e666c7a2545218367a5012beea994a12613865a6 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 21:48:16 +0100 Subject: [PATCH 02/11] fix openssl issue --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index bc47a8d..7c3a388 100644 --- a/flake.nix +++ b/flake.nix @@ -64,7 +64,7 @@ ffpkgs.rustfmt pkgs.wgo tsunami.packages.${system}.tsunami - pkgs.openssl + pkgs.openssl.dev pkgs.pkg-config ]; }; From fe1dbedb201ac9b02378fb8a28deed59895a5393 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 21:49:34 +0100 Subject: [PATCH 03/11] improve auth --- src/flutclient.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/flutclient.rs b/src/flutclient.rs index 6c3cf53..240ad22 100644 --- a/src/flutclient.rs +++ b/src/flutclient.rs @@ -3,6 +3,7 @@ use std::{ sync::Arc, }; +use bytes::Buf; #[cfg(feature = "auth")] use reqwest::{Client, ClientBuilder}; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; @@ -79,6 +80,8 @@ where counter: u64, #[cfg(feature = "auth")] auth_client: Client, + #[cfg(feature = "auth")] + user: u32, } impl FlutClient @@ -162,6 +165,8 @@ where counter: 0, #[cfg(feature = "auth")] auth_client: ClientBuilder::new().https_only(true).build().unwrap(), + #[cfg(feature = "auth")] + user: 0, } } @@ -181,15 +186,25 @@ where buf.clear(); let token_length = self.reader.read_until(b'\n', &mut buf).await?; - if token_length < 100 { - let request = self - .auth_client - .post(AUTH_SERVER_URL) - .body(buf) - .build() - .unwrap(); - let response = self.auth_client.execute(request).await.unwrap(); + if token_length > 100 { + return Err(Error::from(ErrorKind::PermissionDenied)); + } + + let request = self + .auth_client + .post(AUTH_SERVER_URL) + .body(buf) + .build() + .unwrap(); + let response = self.auth_client.execute(request).await.unwrap(); + if response.status() != 200 { + return Err(Error::from(ErrorKind::PermissionDenied)); } + + let user = response.bytes().await.unwrap().get_u32(); + + tracing::info!("User with id {user} authenticated"); + self.user = user; } loop { match_parser!(parser: &self.parser.clone() => 'outer: loop { From 0f39c8d6fcaa7a3217d1ab371b2a9dfae6ff4b31 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 21:51:30 +0100 Subject: [PATCH 04/11] flake reformat --- flake.nix | 101 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/flake.nix b/flake.nix index 7c3a388..0245876 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,14 @@ }; }; - outputs = { self, fenix, nixpkgs, tsunami, ... }: + outputs = + { + self, + fenix, + nixpkgs, + tsunami, + ... + }: let allSystems = [ "x86_64-linux" # 64-bit Intel/AMD Linux @@ -17,24 +24,33 @@ "x86_64-darwin" # 64-bit Intel macOS "aarch64-darwin" # 64-bit ARM macOS ]; - forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { - inherit system; - inherit tsunami; - pkgs = import nixpkgs { inherit system; }; - fpkgs = import fenix { inherit system; }; - }); + forAllSystems = + f: + nixpkgs.lib.genAttrs allSystems ( + system: + f { + inherit system; + inherit tsunami; + pkgs = import nixpkgs { inherit system; }; + fpkgs = import fenix { inherit system; }; + } + ); in { - packages = forAllSystems - ({ pkgs, fpkgs, ... }: - let - toolchain = fpkgs.minimal.toolchain; - fs = pkgs.lib.fileset; - in - rec { - default = flurry; - flurry = - (pkgs.makeRustPlatform { cargo = toolchain; rustc = toolchain; }).buildRustPackage { + packages = forAllSystems ( + { pkgs, fpkgs, ... }: + let + toolchain = fpkgs.minimal.toolchain; + fs = pkgs.lib.fileset; + in + rec { + default = flurry; + flurry = + (pkgs.makeRustPlatform { + cargo = toolchain; + rustc = toolchain; + }).buildRustPackage + { pname = "flurry"; version = "0.1.0"; cargoLock.lockFile = ./Cargo.lock; @@ -47,32 +63,37 @@ ]; }; }; - }); - devShells = forAllSystems - ({ pkgs, fpkgs, system, ... }: - let - ffpkgs = fpkgs.complete; - in - { - default = pkgs.mkShell - { - buildInputs = [ - ffpkgs.cargo - ffpkgs.clippy - ffpkgs.rust-src - ffpkgs.rustc - ffpkgs.rustfmt - pkgs.wgo - tsunami.packages.${system}.tsunami - pkgs.openssl.dev - pkgs.pkg-config - ]; - }; - }); + } + ); + devShells = forAllSystems ( + { + pkgs, + fpkgs, + system, + ... + }: + let + ffpkgs = fpkgs.complete; + in + { + default = pkgs.mkShell { + buildInputs = [ + ffpkgs.cargo + ffpkgs.clippy + ffpkgs.rust-src + ffpkgs.rustc + ffpkgs.rustfmt + pkgs.wgo + tsunami.packages.${system}.tsunami + pkgs.openssl.dev + pkgs.pkg-config + ]; + }; + } + ); hydraJobs = { devShell.x86_64-linux = self.devShells.x86_64-linux.default; flurry.x86_64-linux = self.packages.x86_64-linux.flurry; }; }; } - From 76e271c269a68bd9aa0c3746f0a943ef071bff94 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 21:52:50 +0100 Subject: [PATCH 05/11] fixup! fix openssl issue --- flake.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 0245876..0fc2208 100644 --- a/flake.nix +++ b/flake.nix @@ -85,9 +85,11 @@ ffpkgs.rustfmt pkgs.wgo tsunami.packages.${system}.tsunami - pkgs.openssl.dev pkgs.pkg-config ]; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + pkgs.openssl + ]; }; } ); From ded4ba0d068ea28dac17f0ef4d9ab449a4b125f7 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 22:17:47 +0100 Subject: [PATCH 06/11] add blame map --- src/blame.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++ src/flutclient.rs | 13 ++++++++-- src/grid.rs | 34 ++++++++++++++++++++++++--- src/lib.rs | 5 +++- 4 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 src/blame.rs diff --git a/src/blame.rs b/src/blame.rs new file mode 100644 index 0000000..6b9451c --- /dev/null +++ b/src/blame.rs @@ -0,0 +1,60 @@ +use std::cell::SyncUnsafeCell; + +use image::{GenericImageView, Rgba}; + +use crate::Coordinate; + +pub(crate) type User = u32; + +pub(crate) struct BlameMap { + size_x: usize, + size_y: usize, + cells: SyncUnsafeCell>, +} + +impl BlameMap { + fn index(&self, x: Coordinate, y: Coordinate) -> Option { + let x = x as usize; + let y = y as usize; + if x >= self.size_x || y >= self.size_y { + return None; + } + Some((y * self.size_x) + x) + } + + pub(crate) fn new(size_x: usize, size_y: usize) -> Self { + let mut cells = Vec::with_capacity(size_x * size_y); + for _y in 0..size_y { + for _x in 0..size_x { + cells.push(0); + } + } + BlameMap { + size_x, + size_y, + cells: cells.into(), + } + } + + pub(crate) fn set_blame(&self, x: Coordinate, y: Coordinate, user: User) { + match self.index(x, y) { + None => (), + Some(idx) => unsafe { (*self.cells.get())[idx] = user }, + } + } +} + +impl GenericImageView for BlameMap { + type Pixel = Rgba; + + fn dimensions(&self) -> (u32, u32) { + (self.size_x as u32, self.size_y as u32) + } + + fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel { + let idx = (y as usize) * self.size_x + (x as usize); + let pixel = unsafe { (*self.cells.get())[idx] }; + let [r, g, b, a] = pixel.to_be_bytes(); + Rgba::from([r, g, b, a]) + } +} diff --git a/src/flutclient.rs b/src/flutclient.rs index 240ad22..b60801f 100644 --- a/src/flutclient.rs +++ b/src/flutclient.rs @@ -9,6 +9,7 @@ use reqwest::{Client, ClientBuilder}; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; use crate::{ + blame::User, config::AUTH_SERVER_URL, get_pixel, grid::{self, Flut}, @@ -81,7 +82,7 @@ where #[cfg(feature = "auth")] auth_client: Client, #[cfg(feature = "auth")] - user: u32, + user: User, } impl FlutClient @@ -129,7 +130,15 @@ where } Color::W8(white) => u32::from_be_bytes([*white, *white, *white, 0xff]), }; - set_pixel_rgba(self.grids.as_ref(), canvas, x, y, c); + set_pixel_rgba( + self.grids.as_ref(), + canvas, + x, + y, + c, + #[cfg(feature = "auth")] + self.user, + ); self.counter += 1; } diff --git a/src/grid.rs b/src/grid.rs index 5f0731a..43feea1 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -5,13 +5,16 @@ use std::{ use image::{GenericImageView, Rgb}; -use crate::Coordinate; +use crate::{ + blame::{BlameMap, User}, + Coordinate, +}; pub trait Grid { fn get(&self, x: I, y: I) -> Option<&V>; #[allow(dead_code)] fn get_unchecked(&self, x: I, y: I) -> &V; - fn set(&self, x: I, y: I, value: V); + fn set(&self, x: I, y: I, value: V, #[cfg(feature = "auth")] user: User); } pub struct Flut { @@ -19,6 +22,10 @@ pub struct Flut { size_y: usize, cells: SyncUnsafeCell>, jpgbuf: RwLock>, + #[cfg(feature = "auth")] + blamebuf: RwLock>, + #[cfg(feature = "auth")] + blame: BlameMap, } impl Flut { @@ -32,6 +39,10 @@ impl Flut { size_y, cells: vec.into(), jpgbuf: RwLock::new(Vec::new()), + #[cfg(feature = "auth")] + blamebuf: RwLock::new(Vec::new()), + #[cfg(feature = "auth")] + blame: BlameMap::new(size_x, size_y), } } @@ -60,11 +71,13 @@ impl Grid for Flut { .map(|idx| unsafe { &(*self.cells.get())[idx] }) } - fn set(&self, x: Coordinate, y: Coordinate, value: T) { + fn set(&self, x: Coordinate, y: Coordinate, value: T, #[cfg(feature = "auth")] user: User) { match self.index(x, y) { None => (), Some(idx) => unsafe { (*self.cells.get())[idx] = value }, } + #[cfg(feature = "auth")] + self.blame.set_blame(x, y, user); } fn get_unchecked(&self, x: Coordinate, y: Coordinate) -> &T { @@ -99,6 +112,21 @@ impl Flut { Err(err) => tracing::error!("Error writing jpeg buffer: {:?}", err), } } + + #[cfg(feature = "auth")] + pub fn update_blame_buffer(&self) { + let mut blamebuf = self.blamebuf.write().expect("Could not get write RWlock"); + blamebuf.clear(); + let encoder = image::codecs::png::PngEncoder::new(&mut *blamebuf); + let subimage = self + .blame + .view(0, 0, self.width(), self.height()) + .to_image(); + match subimage.write_with_encoder(encoder) { + Ok(_) => {} + Err(err) => tracing::error!("Error writing png buffer: {:?}", err), + } + } } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index 4b35c6f..b6fe7cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,11 @@ use std::sync::atomic::AtomicU64; +use blame::User; pub use color::Color; use grid::Grid; +pub(crate) mod blame; pub mod config; pub mod flutclient; pub mod grid; @@ -30,9 +32,10 @@ fn set_pixel_rgba( x: Coordinate, y: Coordinate, rgb: u32, + #[cfg(feature = "auth")] user: User, ) { if let Some(grid) = grids.get(canvas as usize) { - grid.set(x, y, rgb); + grid.set(x, y, rgb, user); } } From 76ac40e543cb05c0ec1b72111f8daf91f0022ebc Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 22:27:30 +0100 Subject: [PATCH 07/11] save the blame maps --- src/grid.rs | 10 +++++++++- src/main.rs | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/grid.rs b/src/grid.rs index 43feea1..05a4c8c 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -61,7 +61,15 @@ impl Flut { Some((y * self.size_x) + x) } pub fn read_jpg_buffer(&self) -> RwLockReadGuard<'_, Vec> { - self.jpgbuf.read().expect("RWlock didn't exit nicely") + self.jpgbuf + .read() + .expect("canvas RWlock didn't exit nicely") + } + #[cfg(feature = "auth")] + pub fn read_blame_buffer(&self) -> RwLockReadGuard<'_, Vec> { + self.blamebuf + .read() + .expect("blame RWlock didn't exit nicely") } } diff --git a/src/main.rs b/src/main.rs index 3581e50..d2fb24e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,10 +45,21 @@ async fn save_image_frames( loop { timer.tick().await; for grid in grids.as_ref() { - let p = base_dir.join(format!("{}", Local::now().format("%Y-%m-%d_%H-%M-%S.jpg"))); - let mut file_writer = File::create(p)?; - + let pc = base_dir.join(format!( + "{}-canvas.jpg", + Local::now().format("%Y-%m-%d_%H-%M-%S") + )); + let mut file_writer = File::create(pc)?; file_writer.write_all(&grid.read_jpg_buffer())?; + #[cfg(feature = "auth")] + { + let pb = base_dir.join(format!( + "{}-blame.png", + Local::now().format("%Y-%m-%d_%H-%M-%S") + )); + let mut file_writer = File::create(pb)?; + file_writer.write_all(&grid.read_blame_buffer())?; + } } } } @@ -82,6 +93,8 @@ async fn jpeg_update_loop(grids: Arc<[Flut]>) -> AsyncResult { interval.tick().await; for grid in grids.as_ref() { grid.update_jpg_buffer(); + #[cfg(feature = "auth")] + grid.update_blame_buffer(); } } } From 863d2b68ff7a719d91e8c8b2f9ec4511c1c74b2e Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 22:34:41 +0100 Subject: [PATCH 08/11] remove auth from default features --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d314e3e..9c837f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } [features] -default = ["text", "binary", "auth"] +default = ["text", "binary"] # utilities auth = ["dep:reqwest"] From 1c03fb21401989ab98b21fe91da82b89707e8472 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 22:35:09 +0100 Subject: [PATCH 09/11] fix compilation without --features auth --- src/blame.rs | 7 +++++++ src/flutclient.rs | 14 ++++++++------ src/grid.rs | 8 +++----- src/lib.rs | 9 ++++++++- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/blame.rs b/src/blame.rs index 6b9451c..04126fe 100644 --- a/src/blame.rs +++ b/src/blame.rs @@ -1,17 +1,23 @@ +#[cfg(feature = "auth")] use std::cell::SyncUnsafeCell; +#[cfg(feature = "auth")] use image::{GenericImageView, Rgba}; +#[cfg(feature = "auth")] use crate::Coordinate; +#[cfg(feature = "auth")] pub(crate) type User = u32; +#[cfg(feature = "auth")] pub(crate) struct BlameMap { size_x: usize, size_y: usize, cells: SyncUnsafeCell>, } +#[cfg(feature = "auth")] impl BlameMap { fn index(&self, x: Coordinate, y: Coordinate) -> Option { let x = x as usize; @@ -44,6 +50,7 @@ impl BlameMap { } } +#[cfg(feature = "auth")] impl GenericImageView for BlameMap { type Pixel = Rgba; diff --git a/src/flutclient.rs b/src/flutclient.rs index b60801f..289c92d 100644 --- a/src/flutclient.rs +++ b/src/flutclient.rs @@ -3,20 +3,22 @@ use std::{ sync::Arc, }; -use bytes::Buf; #[cfg(feature = "auth")] -use reqwest::{Client, ClientBuilder}; -use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; - +use crate::{blame::User, config::AUTH_SERVER_URL}; use crate::{ - blame::User, - config::AUTH_SERVER_URL, get_pixel, grid::{self, Flut}, increment_counter, protocols::{BinaryParser, IOProtocol, Parser, Responder, TextParser}, set_pixel_rgba, Canvas, Color, Command, Coordinate, Protocol, Response, }; +#[cfg(feature = "auth")] +use bytes::Buf; +#[cfg(feature = "auth")] +use reqwest::{Client, ClientBuilder}; +#[cfg(feature = "auth")] +use tokio::io::AsyncBufReadExt; +use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; macro_rules! build_parser_type_enum { ($($name:ident: $t:ty: $feat:expr,)*) => { diff --git a/src/grid.rs b/src/grid.rs index 05a4c8c..988e3bf 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -3,13 +3,11 @@ use std::{ sync::{RwLock, RwLockReadGuard}, }; +#[cfg(feature = "auth")] +use crate::blame::{BlameMap, User}; +use crate::Coordinate; use image::{GenericImageView, Rgb}; -use crate::{ - blame::{BlameMap, User}, - Coordinate, -}; - pub trait Grid { fn get(&self, x: I, y: I) -> Option<&V>; #[allow(dead_code)] diff --git a/src/lib.rs b/src/lib.rs index b6fe7cd..5180569 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ use std::sync::atomic::AtomicU64; +#[cfg(feature = "auth")] use blame::User; pub use color::Color; use grid::Grid; @@ -35,7 +36,13 @@ fn set_pixel_rgba( #[cfg(feature = "auth")] user: User, ) { if let Some(grid) = grids.get(canvas as usize) { - grid.set(x, y, rgb, user); + grid.set( + x, + y, + rgb, + #[cfg(feature = "auth")] + user, + ); } } From 569316fcd342c9586b05d61812fa1c2e1cd69d8f Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 22:36:10 +0100 Subject: [PATCH 10/11] fix grid tests with auth --- src/grid.rs | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/grid.rs b/src/grid.rs index 988e3bf..6d3bac8 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -159,30 +159,66 @@ mod tests { #[tokio::test] async fn test_grid_set() { let grid = Flut::init(3, 3, 0); - grid.set(1, 1, 255); - grid.set(2, 1, 256); + grid.set( + 1, + 1, + 255, + #[cfg(feature = "auth")] + 0, + ); + grid.set( + 2, + 1, + 256, + #[cfg(feature = "auth")] + 0, + ); assert_eq!(grid.cells.into_inner(), vec![0, 0, 0, 0, 255, 256, 0, 0, 0]); } #[tokio::test] async fn test_grid_set_out_of_range() { let grid = Flut::init(3, 3, 0); - grid.set(1, 1, 255); - grid.set(3, 1, 256); + grid.set( + 1, + 1, + 255, + #[cfg(feature = "auth")] + 0, + ); + grid.set( + 3, + 1, + 256, + #[cfg(feature = "auth")] + 0, + ); assert_eq!(grid.cells.into_inner(), vec![0, 0, 0, 0, 255, 0, 0, 0, 0]); } #[tokio::test] async fn test_grid_get() { let grid = Flut::init(3, 3, 0); - grid.set(1, 2, 222); + grid.set( + 1, + 2, + 222, + #[cfg(feature = "auth")] + 0, + ); assert_eq!(grid.get(1, 2), Some(&222)); } #[tokio::test] async fn test_grid_get_out_of_range() { let grid = Flut::init(3, 3, 0); - grid.set(3, 1, 256); + grid.set( + 3, + 1, + 256, + #[cfg(feature = "auth")] + 0, + ); assert_eq!(grid.get(3, 1), None); assert_eq!(grid.get(1, 2), Some(&0)); } From 8e047676d3f315a0244e808b8cdea1b925071021 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Wed, 11 Dec 2024 22:41:42 +0100 Subject: [PATCH 11/11] fix cargo.lock --- Cargo.lock | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3493bf8..154088e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,7 @@ dependencies = [ "serde_path_to_error", "serde_urlencoded", "sha1", - "sync_wrapper 1.0.2", + "sync_wrapper", "tokio", "tokio-tungstenite", "tower", @@ -214,7 +214,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 1.0.2", + "sync_wrapper", "tower-layer", "tower-service", "tracing", @@ -1938,9 +1938,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ "bitflags 2.6.0", ] @@ -2020,7 +2020,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 1.0.2", + "sync_wrapper", "system-configuration", "tokio", "tokio-native-tls", @@ -2053,6 +2053,7 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] name = "rust-embed" version = "8.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2107,9 +2108,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.19" +version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" +checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" dependencies = [ "once_cell", "rustls-pki-types", @@ -2381,12 +2382,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sync_wrapper" version = "1.0.2" @@ -2688,14 +2683,14 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", "pin-project-lite", - "sync_wrapper 0.1.2", + "sync_wrapper", "tokio", "tower-layer", "tower-service",