From bba3f548abbc6466024ec3df369b805705f75b87 Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Mon, 8 Sep 2025 20:37:43 +0200 Subject: [PATCH] Loading Logging etc --- .gitignore | 1 + Cargo.lock | 437 ++++++++++++++++++++++-------- src/omikron/omikron_connection.rs | 209 +++++++++----- src/util/chats_util.rs | 112 +++----- src/util/config_util.rs | 5 +- src/util/file_util.rs | 34 +-- 6 files changed, 527 insertions(+), 271 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/Cargo.lock b/Cargo.lock index 0583893..5fe45ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ "bytes", "cmake", "color-eyre", - "crossterm", + "crossterm 0.29.0", "futures-util", "json", "once_cell", @@ -127,7 +127,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -138,9 +138,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.9.3" +version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" [[package]] name = "block-buffer" @@ -186,10 +186,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.34" +version = "1.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" +checksum = "5252b3d2648e5eedbc1a6f501e3c795e07025c1e93bbf8bbdd6eef7f447a6d54" dependencies = [ + "find-msvc-tools", "shlex", ] @@ -249,6 +250,15 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "convert_case" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -274,31 +284,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - [[package]] name = "crossterm" version = "0.28.1" @@ -315,6 +300,24 @@ dependencies = [ "winapi", ] +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags", + "crossterm_winapi", + "derive_more", + "document-features", + "mio", + "parking_lot", + "rustix 1.0.8", + "signal-hook", + "signal-hook-mio", + "winapi", +] + [[package]] name = "crossterm_winapi" version = "0.9.1" @@ -384,6 +387,27 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -405,6 +429,15 @@ dependencies = [ "syn", ] +[[package]] +name = "document-features" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" +dependencies = [ + "litrs", +] + [[package]] name = "either" version = "1.15.0" @@ -433,7 +466,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -452,6 +485,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d" + [[package]] name = "fnv" version = "1.0.7" @@ -571,7 +610,7 @@ dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.3+wasi-0.2.4", + "wasi 0.14.4+wasi-0.2.4", ] [[package]] @@ -935,9 +974,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "0c0b063578492ceec17683ef2f8c5e89121fbd0b172cbc280635ab7567db2738" dependencies = [ "once_cell", "wasm-bindgen", @@ -979,6 +1018,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" +[[package]] +name = "litrs" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" + [[package]] name = "lock_api" version = "0.4.13" @@ -991,9 +1036,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "lru" @@ -1084,6 +1129,25 @@ dependencies = [ "libc", ] +[[package]] +name = "objc2-core-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-io-kit" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71c1c64d6120e51cd86033f67176b1cb66780c2efe34dec55176f77befd93c0a" +dependencies = [ + "libc", + "objc2-core-foundation", +] + [[package]] name = "object" version = "0.36.7" @@ -1169,7 +1233,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1289,7 +1353,7 @@ dependencies = [ "bitflags", "cassowary", "compact_str", - "crossterm", + "crossterm 0.28.1", "indoc", "instability", "itertools", @@ -1302,26 +1366,6 @@ dependencies = [ "unicode-width 0.2.0", ] -[[package]] -name = "rayon" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_syscall" version = "0.5.17" @@ -1414,7 +1458,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -1731,16 +1775,15 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.13" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" +checksum = "07cec4dc2d2e357ca1e610cfb07de2fa7a10fc3e9fe89f72545f3d244ea87753" dependencies = [ - "cfg-if", - "core-foundation-sys", "libc", + "memchr", "ntapi", - "once_cell", - "rayon", + "objc2-core-foundation", + "objc2-io-kit", "windows", ] @@ -1775,7 +1818,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix 1.0.8", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -1809,9 +1852,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.42" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca967379f9d8eb8058d86ed467d81d03e81acd45757e4ca341c24affbe8e8e3" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" dependencies = [ "deranged", "libc", @@ -1824,9 +1867,9 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9108bb380861b07264b950ded55a44a14a4adc68b9f5efd85aafc3aa4d40a68" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" [[package]] name = "tinystr" @@ -2105,9 +2148,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ "getrandom 0.3.3", "js-sys", @@ -2159,30 +2202,31 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.3+wasi-0.2.4" +version = "0.14.4+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" +checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a" dependencies = [ "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "7e14915cadd45b529bb8d1f343c4ed0ac1de926144b746e2710f9cd05df6603b" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +checksum = "e28d1ba982ca7923fd01448d5c30c6864d0a14109560296a162f80f305fb93bb" dependencies = [ "bumpalo", "log", @@ -2194,9 +2238,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.50" +version = "0.4.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +checksum = "0ca85039a9b469b38336411d6d6ced91f3fc87109a2a27b0c197663f5144dffe" dependencies = [ "cfg-if", "js-sys", @@ -2207,9 +2251,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "7c3d463ae3eff775b0c45df9da45d68837702ac35af998361e2c84e7c5ec1b0d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2217,9 +2261,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "7bb4ce89b08211f923caf51d527662b75bdc9c9c7aab40f86dcb9fb85ac552aa" dependencies = [ "proc-macro2", "quote", @@ -2230,18 +2274,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "f143854a3b13752c6950862c906306adb27c7e839f7414cec8fea35beab624c1" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.77" +version = "0.3.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +checksum = "77e4b637749ff0d92b8fad63aa1f7cff3cbe125fd49c175cd6345e7272638b12" dependencies = [ "js-sys", "wasm-bindgen", @@ -2283,11 +2327,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.0", ] [[package]] @@ -2298,21 +2342,70 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.52.0" +version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-link 0.1.3", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ "windows-core", - "windows-targets", ] [[package]] name = "windows-core" -version = "0.52.0" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows-targets", + "windows-implement", + "windows-interface", + "windows-link 0.1.3", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" +dependencies = [ + "windows-core", + "windows-link 0.1.3", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -2321,13 +2414,29 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +[[package]] +name = "windows-link" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" + +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core", + "windows-link 0.1.3", +] + [[package]] name = "windows-registry" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b8a9ed28765efc97bbc954883f4e6796c33a06546ebafacbabee9696967499e" dependencies = [ - "windows-link", + "windows-link 0.1.3", "windows-result", "windows-strings", ] @@ -2338,7 +2447,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ - "windows-link", + "windows-link 0.1.3", ] [[package]] @@ -2347,7 +2456,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" dependencies = [ - "windows-link", + "windows-link 0.1.3", ] [[package]] @@ -2356,7 +2465,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -2365,7 +2474,25 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", +] + +[[package]] +name = "windows-sys" +version = "0.61.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa" +dependencies = [ + "windows-link 0.2.0", ] [[package]] @@ -2374,14 +2501,40 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link 0.1.3", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link 0.1.3", ] [[package]] @@ -2390,42 +2543,84 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -2433,10 +2628,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] -name = "wit-bindgen" -version = "0.45.0" +name = "windows_x86_64_msvc" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "wit-bindgen" +version = "0.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36" [[package]] name = "writeable" @@ -2470,18 +2671,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.26" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.26" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index 375f85f..bb0b575 100644 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -1,30 +1,36 @@ -use futures_util::{SinkExt, StreamExt}; -use std::collections::HashMap; -use std::str::FromStr; -use std::sync::Arc; -use std::time::{SystemTime, UNIX_EPOCH}; -use json::JsonValue; -use tokio::sync::Mutex; -use tokio::net::TcpStream; -use tokio::time::{sleep, Duration}; -use tokio_tungstenite::{ - connect_async, - tungstenite::protocol::{Message}, - MaybeTlsStream, - WebSocketStream, -}; -use uuid::{Uuid}; use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes}; use crate::users::contact::Contact; use crate::users::user_community_util::UserCommunityUtil; use crate::util::chat_files::ChatFiles; -use crate::util::chats_util::ChatsUtil; +use crate::util::chats_util::{get_user, get_users, mod_user}; +use futures_util::{SinkExt, StreamExt}; +use json::JsonValue; +use std::collections::HashMap; +use std::str::FromStr; +use std::sync::Arc; +use std::time::{SystemTime, UNIX_EPOCH}; +use tokio::net::TcpStream; +use tokio::sync::Mutex; +use tokio::time::{Duration, sleep}; +use tokio_tungstenite::{ + MaybeTlsStream, WebSocketStream, connect_async, tungstenite::protocol::Message, +}; +use uuid::Uuid; #[derive(Clone)] pub struct OmikronConnection { - pub(crate) writer: Arc>, Message>>>>, + pub(crate) writer: Arc< + Mutex< + Option< + futures_util::stream::SplitSink< + WebSocketStream>, + Message, + >, + >, + >, + >, waiting: Arc>>>, // waiting for responses - pingpong: Arc>>>, // ping-pong handler + pingpong: Arc>>>, // ping-pong handler } impl OmikronConnection { @@ -66,11 +72,13 @@ impl OmikronConnection { /// Listener for all incoming messages fn spawn_listener( &self, - mut read_half: futures_util::stream::SplitStream>>, + mut read_half: futures_util::stream::SplitStream< + WebSocketStream>, + >, ) { let waiting = self.waiting.clone(); let writer = self.writer.clone(); - + tokio::spawn(async move { while let Some(msg) = read_half.next().await { match msg { @@ -92,97 +100,151 @@ impl OmikronConnection { let sender_id = &cv.get_sender(); let receiver_id = &cv.get_receiver(); ChatFiles::add_message( - - cv.get_data(DataTypes::SendTime).unwrap().as_i64().unwrap_or(-1), + cv.get_data(DataTypes::SendTime) + .unwrap() + .as_i64() + .unwrap_or(-1), false, receiver_id.unwrap(), sender_id.unwrap(), - cv.get_data(DataTypes::MessageContent).unwrap().as_str().unwrap(), + cv.get_data(DataTypes::MessageContent) + .unwrap() + .as_str() + .unwrap(), ); let response = CommunicationValue::new(CommunicationType::MessageLive) .with_id(cv.get_id()) .with_receiver(cv.get_receiver().unwrap()) - .add_data(DataTypes::SendTime, cv.get_data(DataTypes::SendTime).unwrap().clone()) - .add_data(DataTypes::Message, cv.get_data(DataTypes::MessageContent).unwrap().clone()) - .add_data(DataTypes::SenderId, JsonValue::String(cv.get_sender().unwrap().clone().to_string())); - Self::send_message_static(&writer.clone(), response.to_json().to_string()).await; + .add_data( + DataTypes::SendTime, + cv.get_data(DataTypes::SendTime).unwrap().clone(), + ) + .add_data( + DataTypes::Message, + cv.get_data(DataTypes::MessageContent).unwrap().clone(), + ) + .add_data( + DataTypes::SenderId, + JsonValue::String(cv.get_sender().unwrap().clone().to_string()), + ); + Self::send_message_static( + &writer.clone(), + response.to_json().to_string(), + ) + .await; continue; } if cv.is_type(CommunicationType::Message) { let my_id = cv.get_sender(); - ChatFiles::add_message(SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() as i64, - true, - my_id.unwrap(), - Uuid::from_str(&*cv.get_data(DataTypes::ReceiverId).unwrap().to_string()).unwrap(), - &*cv.get_data(DataTypes::MessageContent).unwrap().to_string() + ChatFiles::add_message( + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() as i64, + true, + my_id.unwrap(), + Uuid::from_str( + &*cv.get_data(DataTypes::ReceiverId).unwrap().to_string(), + ) + .unwrap(), + &*cv.get_data(DataTypes::MessageContent).unwrap().to_string(), ); // ack let ack = CommunicationValue::ack_message(cv.get_id(), my_id); - Self::send_message_static(&writer.clone(), ack.to_json().to_string()).await; + Self::send_message_static(&writer.clone(), ack.to_json().to_string()) + .await; // forward let forward = CommunicationValue::forward_to_other_iota(&mut cv); - Self::send_message_static(&writer.clone(), forward.to_json().to_string()).await; + Self::send_message_static( + &writer.clone(), + forward.to_json().to_string(), + ) + .await; continue; } if cv.is_type(CommunicationType::MessageGet) { let my_id = cv.get_sender().unwrap(); - let partner_id = Uuid::from_str(&*cv.get_data(DataTypes::ChatPartnerId).unwrap().to_string()).unwrap(); - let offset = cv.get_data(DataTypes::LoadedMessages).unwrap().to_string().parse::().unwrap(); - let amount = cv.get_data(DataTypes::MessageAmount).unwrap().to_string().parse::().unwrap(); + let partner_id = Uuid::from_str( + &*cv.get_data(DataTypes::ChatPartnerId).unwrap().to_string(), + ) + .unwrap(); + let offset = cv + .get_data(DataTypes::LoadedMessages) + .unwrap() + .to_string() + .parse::() + .unwrap(); + let amount = cv + .get_data(DataTypes::MessageAmount) + .unwrap() + .to_string() + .parse::() + .unwrap(); - let messages = ChatFiles::get_messages(my_id, partner_id, offset, amount); // needs ChatFiles + let messages = + ChatFiles::get_messages(my_id, partner_id, offset, amount); // needs ChatFiles let mut resp = CommunicationValue::new(CommunicationType::MessageChunk) .with_id(cv.get_id()) .with_receiver(my_id); if !messages.is_empty() { resp = resp.add_data(DataTypes::MessageChunk, messages); } - Self::send_message_static(&writer.clone(), resp.to_json().to_string()).await; + Self::send_message_static(&writer.clone(), resp.to_json().to_string()) + .await; continue; } if cv.is_type(CommunicationType::GetChats) { let user_id = cv.get_sender(); - let users = ChatsUtil::get_users(user_id.unwrap()); // needs ChatsUtil + let users = get_users(user_id.unwrap()); // needs ChatsUtil let resp = CommunicationValue::new(CommunicationType::GetChats) .with_id(cv.get_id()) .with_receiver(user_id.unwrap()) .add_data(DataTypes::UserIds, users); - Self::send_message_static(&writer.clone(), resp.to_json().to_string()).await; + Self::send_message_static(&writer.clone(), resp.to_json().to_string()) + .await; continue; } if cv.is_type(CommunicationType::AddChat) { let user_id = cv.get_sender(); - let other_id = Uuid::from_str(&*cv.get_data(DataTypes::UserId).unwrap().to_string()).unwrap(); - let mut contact = ChatsUtil::get_user(user_id.unwrap(), other_id).unwrap_or(Contact::new(other_id)); // needs ChatsUtil + Contact - contact.set_last_message_at(SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() as i64); - ChatsUtil::mod_user(user_id.unwrap(), &contact); + let other_id = Uuid::from_str( + &*cv.get_data(DataTypes::UserId).unwrap().to_string(), + ) + .unwrap(); + let mut contact = get_user(user_id.unwrap(), other_id) + .unwrap_or(Contact::new(other_id)); // needs ChatsUtil + Contact + contact.set_last_message_at( + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() as i64, + ); + mod_user(user_id.unwrap(), &contact); let resp = CommunicationValue::new(CommunicationType::AddChat) .with_id(cv.get_id()) .with_receiver(user_id.unwrap()); - Self::send_message_static(&writer.clone(), resp.to_json().to_string()).await; + Self::send_message_static(&writer.clone(), resp.to_json().to_string()) + .await; continue; } if cv.is_type(CommunicationType::AddCommunity) { - UserCommunityUtil::add_community( cv.get_sender().unwrap(), - cv.get_data(DataTypes::CommunityAddress).unwrap().to_string(), - cv.get_data(DataTypes::CommunityTitle).unwrap().to_string(), - cv.get_data(DataTypes::Position).unwrap().to_string() + UserCommunityUtil::add_community( + cv.get_sender().unwrap(), + cv.get_data(DataTypes::CommunityAddress) + .unwrap() + .to_string(), + cv.get_data(DataTypes::CommunityTitle).unwrap().to_string(), + cv.get_data(DataTypes::Position).unwrap().to_string(), ); let resp = CommunicationValue::new(CommunicationType::AddCommunity) .with_id(cv.get_id()) .with_receiver(cv.get_sender().unwrap()); - Self::send_message_static(&writer.clone(), resp.to_json().to_string()).await; + Self::send_message_static(&writer.clone(), resp.to_json().to_string()) + .await; continue; } @@ -190,17 +252,27 @@ impl OmikronConnection { let resp = CommunicationValue::new(CommunicationType::GetCommunities) .with_id(cv.get_id()) .with_receiver(cv.get_sender().unwrap()) - .add_data(DataTypes::Communities, UserCommunityUtil::get_communities(cv.get_sender().unwrap())); // needs UserCommunityUtil - Self::send_message_static(&writer.clone(), resp.to_json().to_string()).await; + .add_data( + DataTypes::Communities, + UserCommunityUtil::get_communities(cv.get_sender().unwrap()), + ); // needs UserCommunityUtil + Self::send_message_static(&writer.clone(), resp.to_json().to_string()) + .await; continue; } if cv.is_type(CommunicationType::RemoveCommunity) { - UserCommunityUtil::remove_community(cv.get_sender().unwrap(), cv.get_data(DataTypes::CommunityAddress).unwrap().to_string()); // needs UserCommunityUtil + UserCommunityUtil::remove_community( + cv.get_sender().unwrap(), + cv.get_data(DataTypes::CommunityAddress) + .unwrap() + .to_string(), + ); // needs UserCommunityUtil let resp = CommunicationValue::new(CommunicationType::RemoveCommunity) .with_id(cv.get_id()) .with_receiver(cv.get_sender().unwrap()); - Self::send_message_static(&writer.clone(), resp.to_json().to_string()).await; + Self::send_message_static(&writer.clone(), resp.to_json().to_string()) + .await; continue; } } @@ -217,7 +289,16 @@ impl OmikronConnection { Self::send_message_static(&self.writer, msg).await; } pub async fn send_message_static( - writer: &Arc>, Message>>>>, + writer: &Arc< + Mutex< + Option< + futures_util::stream::SplitSink< + WebSocketStream>, + Message, + >, + >, + >, + >, msg: String, ) -> Result<(), tokio_tungstenite::tungstenite::Error> { let mut guard = writer.lock().await; @@ -229,7 +310,7 @@ impl OmikronConnection { Err(tokio_tungstenite::tungstenite::Error::ConnectionClosed) } } - + pub fn on_answer(&self, message_id: Uuid, callback: F) where F: Fn(CommunicationValue) + Send + 'static, diff --git a/src/util/chats_util.rs b/src/util/chats_util.rs index 3ab4163..eda887b 100644 --- a/src/util/chats_util.rs +++ b/src/util/chats_util.rs @@ -1,93 +1,65 @@ -use std::string::String; -use json::{self, array, JsonValue}; -use std::fs::{self, File}; -use std::io::{Read, Write}; -use std::path::Path; use axum::Json; +use json::{self, JsonValue, array}; +use std::path::Path; +use std::string::String; use uuid::Uuid; -use crate::users::contact; use crate::users::contact::Contact; -// assuming you have a Contact struct in a module +use crate::util::file_util::{load_file, save_file}; -pub struct ChatsUtil; +pub fn mod_user(storage_owner: Uuid, contact: &Contact) { + let dir: &str = &format!("users/{}/contacts/", storage_owner); + let s = load_file(dir, "contacts.json"); -impl ChatsUtil { - fn load_file(dir: &str, file_name: &str) -> String { - let path = Path::new(dir).join(file_name); - if let Ok(mut f) = File::open(&path) { - let mut content = String::new(); - let _ = f.read_to_string(&mut content); - content - } else { - String::new() + let mut contacts = if !s.is_empty() { + json::parse(&s).unwrap_or(array![]) + } else { + array![] + }; + + for i in 0..contacts.len() { + if contacts[i]["userID"].as_str() == Some(&contact.user_id.unwrap().to_string()) { + contacts.remove(stringify!("{}", i)); + break; } } - fn save_file(dir: &str, file_name: &str, content: &str) -> std::io::Result<()> { - fs::create_dir_all(dir)?; - let path = Path::new(dir).join(file_name); - let mut file = File::create(path)?; - file.write_all(content.as_bytes()) + contacts.push(contact.to_json()).unwrap(); + save_file(&dir, "contacts.json", &contacts.dump()); +} + +pub fn get_user(storage_owner: Uuid, user_id: Uuid) -> Option { + let dir = format!("users/{}/contacts/", storage_owner); + let s = load_file(&dir, "contacts.json"); + if s.is_empty() { + return None; } - pub fn mod_user(storage_owner: Uuid, contact: &Contact){ - let dir = format!("users/{}/contacts/", storage_owner); - let file_name = "contacts.json"; - let s = Self::load_file(&dir, file_name); - - let mut contacts = if !s.is_empty() { - json::parse(&s).unwrap_or(array![]) - } else { - array![] - }; - + if let Ok(contacts) = json::parse(&s) { for i in 0..contacts.len() { - if contacts[i]["userID"].as_str() == Some(&contact.user_id.unwrap().to_string()) { - contacts.remove(stringify!("{}", i)); - break; + if let Some(uid) = contacts[i]["userID"].as_str() { + if Uuid::parse_str(uid).ok()? == user_id { + return Option::from(Contact::from_json(&contacts[i])); + } } } - - contacts.push(contact.to_json()).unwrap(); - Self::save_file(&dir, file_name, &contacts.dump()); } + None +} - pub fn get_user(storage_owner: Uuid, user_id: Uuid) -> Option { - let dir = format!("users/{}/contacts/", storage_owner); - let file_name = "contacts.json"; - let s = Self::load_file(&dir, file_name); - if s.is_empty() { - return None; - } +pub fn get_users(storage_owner: Uuid) -> JsonValue { + let dir: &str = &format!("users/{}/contacts/", storage_owner); + let s = load_file(dir, "contacts.json"); + let mut contacts_out = array![]; + if !s.is_empty() { if let Ok(contacts) = json::parse(&s) { for i in 0..contacts.len() { - if let Some(uid) = contacts[i]["userID"].as_str() { - if Uuid::parse_str(uid).ok()? == user_id { - return Option::from(Contact::from_json(&contacts[i])); - } - } + let c = Contact::from_json(&contacts[i]); + contacts_out.push(c.to_json()).unwrap(); } } - None } - pub fn get_users(storage_owner: Uuid) -> JsonValue { - let dir = format!("/users/{}/contacts/", storage_owner); - let file_name = "contacts.json"; - let s = Self::load_file(&dir, file_name); - - let mut contacts_out = array![]; - if !s.is_empty() { - if let Ok(contacts) = json::parse(&s) { - for i in 0..contacts.len() { - let c = Contact::from_json(&contacts[i]); - contacts_out.push(c.to_json()).unwrap(); - } - } - } - - contacts_out - } -} \ No newline at end of file + contacts_out +} diff --git a/src/util/config_util.rs b/src/util/config_util.rs index 1a92a7b..54867ea 100644 --- a/src/util/config_util.rs +++ b/src/util/config_util.rs @@ -1,9 +1,8 @@ +use crate::util::file_util::{load_file, save_file}; use json::JsonValue; use std::fs::{self, File}; -use std::io::{Read, Write}; use std::path::Path; use uuid::Uuid; -use crate::util::file_util::{load_file, save_file}; pub struct ConfigUtil { pub config: JsonValue, @@ -37,6 +36,6 @@ impl ConfigUtil { } pub fn save(&self) { - save_file("","config.json", &self.config.to_string()); + save_file("", "config.json", &self.config.to_string()); } } diff --git a/src/util/file_util.rs b/src/util/file_util.rs index 1045925..ac3d822 100644 --- a/src/util/file_util.rs +++ b/src/util/file_util.rs @@ -1,13 +1,14 @@ -use sysinfo::{System}; +use std::ffi::OsStr; +use std::fmt::Write as FmtWrite; use std::fs::{self, File}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; -use std::time::SystemTime; -use std::ffi::OsStr; use std::process; -use walkdir::WalkDir; -use std::fmt::Write as FmtWrite; +use std::time::SystemTime; +use sysinfo::System; use uuid::Uuid; +use walkdir::WalkDir; + pub fn delete_file(path: &str, name: &str) -> bool { let dir = Path::new(&get_directory()).join(path); let file = dir.join(name); @@ -27,7 +28,11 @@ fn delete_dir_recursive(directory: &Path) -> bool { return false; } if let Err(e) = fs::remove_dir_all(directory) { - println!("[IMPORTANT] Couldn't delete directory {}: {}", directory.display(), e); + println!( + "[IMPORTANT] Couldn't delete directory {}: {}", + directory.display(), + e + ); return false; } true @@ -78,7 +83,11 @@ pub fn save_file(path: &str, name: &str, value: &str) { } if let Err(e) = fs::write(&file_path, value) { - println!("[IMPORTANT] Couldn't write file {}: {}", file_path.display(), e); + println!( + "[IMPORTANT] Couldn't write file {}: {}", + file_path.display(), + e + ); } } @@ -100,10 +109,7 @@ pub fn get_directory_size(directory: &Path) -> u64 { let path = entry.path(); if path.is_file() { if let Ok(metadata) = path.metadata() { - size += path - .file_name() - .unwrap_or(OsStr::new("")) - .len() as u64; + size += path.file_name().unwrap_or(OsStr::new("")).len() as u64; size += metadata.len(); } } @@ -142,9 +148,5 @@ pub fn get_used_ram() -> String { sys.refresh_all(); let used = sys.used_memory() * 1024; // kB to bytes let total = sys.total_memory() * 1024; - format!( - "{}/{}", - design_byte(used), - design_byte(total) - ) + format!("{}/{}", design_byte(used), design_byte(total)) }