diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index d363b83..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[env] -MTP_TYPE_MAPS = { value = "type-maps.yaml", relative = true } diff --git a/Cargo.lock b/Cargo.lock index 1f85cb3..5f83697 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", "bytes", "futures-core", "futures-sink", @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.13.1" +version = "3.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e2faa3e7418ed780cca54829d32782a4008a077230f67457caa063415e99c2" +checksum = "93acb4a42f64936f9b8cae4a433b237599dd6eb6ed06124eb67132ef8cc90662" dependencies = [ "actix-codec", "actix-rt", @@ -31,14 +31,14 @@ dependencies = [ "actix-tls", "actix-utils", "base64", - "bitflags 2.13.0", + "bitflags 2.12.1", "brotli", "bytes", "bytestring", "derive_more", "encoding_rs", "flate2", - "foldhash 0.2.0", + "foldhash", "futures-core", "h2 0.3.27", "http 0.2.12", @@ -131,7 +131,7 @@ dependencies = [ "actix-service", "actix-utils", "futures-core", - "impl-more 0.1.9", + "impl-more", "pin-project-lite", "rustls-pki-types", "tokio", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.14.0" +version = "4.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df09e2d9239703dd64056359c920c7f3fba6535ec61a0059e0f44e095ffe02b4" +checksum = "ff87453bc3b56e9b2b23c1cc0b1be8797184accf51d2abe0f8a33ec275d316bf" dependencies = [ "actix-codec", "actix-http", @@ -172,10 +172,10 @@ dependencies = [ "cookie", "derive_more", "encoding_rs", - "foldhash 0.2.0", + "foldhash", "futures-core", "futures-util", - "impl-more 0.3.1", + "impl-more", "itoa", "language-tags", "log", @@ -264,9 +264,9 @@ checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" [[package]] name = "alloc-stdlib" -version = "0.2.4" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" dependencies = [ "alloc-no-stdlib", ] @@ -288,9 +288,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.103" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "arbitrary" @@ -555,9 +555,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.13.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" +checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" dependencies = [ "serde_core", ] @@ -573,9 +573,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.12.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" dependencies = [ "hybrid-array", ] @@ -595,9 +595,9 @@ dependencies = [ [[package]] name = "brotli" -version = "8.0.4" +version = "8.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc91aac060a7a1e25823bdccbfb6af1875b88f17c6daac97894eed8207166b3" +checksum = "8119e4516436f5708bbc474a9d395bf12f1b5395e93a92a56e647ac3388c8610" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -606,9 +606,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "5.0.3" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583" +checksum = "5962523e1b92ce1b5e793d9169b9943eece10d39f62550bc04bb605d75b94924" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -628,9 +628,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.12.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "bytestring" @@ -652,9 +652,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.65" +version = "1.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e228eec9be7c17ccb640b59b36a5cd805ea2a564a4c5e162c2f659fea30d3b96" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" dependencies = [ "find-msvc-tools", "jobserver", @@ -676,9 +676,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chacha20" -version = "0.10.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" dependencies = [ "cfg-if", "cpufeatures 0.3.0", @@ -929,6 +929,9 @@ name = "deranged" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] [[package]] name = "derive_arbitrary" @@ -982,7 +985,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer 0.12.1", + "block-buffer 0.12.0", "const-oid 0.10.2", "crypto-common 0.2.2", ] @@ -1160,12 +1163,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "foldhash" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" - [[package]] name = "form_urlencoded" version = "1.2.2" @@ -1319,14 +1316,16 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.4.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", "rand_core 0.10.1", + "wasip2", + "wasip3", ] [[package]] @@ -1372,16 +1371,16 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.15" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155" +checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" dependencies = [ "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "http 1.4.2", + "http 1.4.1", "indexmap", "slab", "tokio", @@ -1403,7 +1402,7 @@ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "allocator-api2", "equivalent", - "foldhash 0.1.5", + "foldhash", ] [[package]] @@ -1491,9 +1490,9 @@ dependencies = [ [[package]] name = "http" -version = "1.4.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0" dependencies = [ "bytes", "itoa", @@ -1506,7 +1505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.4.2", + "http 1.4.1", ] [[package]] @@ -1517,7 +1516,7 @@ checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" dependencies = [ "bytes", "futures-core", - "http 1.4.2", + "http 1.4.1", "http-body", "pin-project-lite", ] @@ -1536,9 +1535,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hybrid-array" -version = "0.4.13" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818356c5132c1fede50f837ca96afbe78ff42413047f4abb886217845e1b6c8c" +checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da" dependencies = [ "typenum", ] @@ -1553,8 +1552,8 @@ dependencies = [ "bytes", "futures-channel", "futures-core", - "h2 0.4.15", - "http 1.4.2", + "h2 0.4.14", + "http 1.4.1", "http-body", "httparse", "itoa", @@ -1570,7 +1569,7 @@ version = "0.27.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" dependencies = [ - "http 1.4.2", + "http 1.4.1", "hyper", "hyper-util", "rustls", @@ -1589,7 +1588,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.4.2", + "http 1.4.1", "http-body", "hyper", "ipnet", @@ -1686,6 +1685,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "idna" version = "1.1.0" @@ -1713,12 +1718,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2" -[[package]] -name = "impl-more" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35a84fd5aa25fae5c0f4a33d9cac2ca017fc622cbd089be2229993514990f870" - [[package]] name = "indexmap" version = "2.14.0" @@ -1727,6 +1726,8 @@ checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", "hashbrown 0.17.1", + "serde", + "serde_core", ] [[package]] @@ -1831,12 +1832,13 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.103" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" dependencies = [ "cfg-if", "futures-util", + "once_cell", "wasm-bindgen", ] @@ -1870,6 +1872,12 @@ dependencies = [ "spin", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libbz2-rs-sys" version = "0.2.5" @@ -1894,7 +1902,7 @@ version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f02ab6bace2054fb888a3c16f990117b579d14a3088e472d63c6011fa185c9d3" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", "libc", "plain", "redox_syscall 0.8.1", @@ -1956,9 +1964,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.33" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" +checksum = "113b30b4cd05f7c06868fdb2854f66a7b9fece9a48425351cd532e810d74024f" dependencies = [ "value-bag", ] @@ -1991,9 +1999,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.8.2" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" [[package]] name = "mime" @@ -2029,76 +2037,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "mtp" -version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" -dependencies = [ - "mtp-codec", - "mtp-common", - "mtp-host", - "mtp-transport", - "mtp-type-map", -] - -[[package]] -name = "mtp-codec" -version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" -dependencies = [ - "base64", - "byteorder", - "mtp-common", - "mtp-type-map", - "rand 0.8.6", -] - -[[package]] -name = "mtp-common" -version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" -dependencies = [ - "quinn", - "rustls", - "thiserror", - "wtransport", -] - -[[package]] -name = "mtp-host" -version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" -dependencies = [ - "mtp-codec", - "mtp-common", - "mtp-transport", - "rand 0.8.6", - "tokio", -] - -[[package]] -name = "mtp-transport" -version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" -dependencies = [ - "log", - "mtp-codec", - "mtp-common", - "rustls", - "rustls-native-certs", - "tokio", - "wtransport", -] - -[[package]] -name = "mtp-type-map" -version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#41528ef7178982e70cb5789a437d863a7a35426c" -dependencies = [ - "serde", - "serde_yaml", -] - [[package]] name = "nom" version = "7.1.3" @@ -2200,7 +2138,6 @@ dependencies = [ "hex", "hkdf", "json", - "mtp", "once_cell", "rand 0.8.6", "rand_core 0.6.4", @@ -2209,10 +2146,12 @@ dependencies = [ "rustls-pemfile", "sha2 0.10.9", "sqlx", - "strum", - "strum_macros", + "strum 0.27.2", + "strum_macros 0.27.2", "thiserror", "tokio", + "ttp-core", + "ttp-native", "uuid", "x448", "zip", @@ -2428,6 +2367,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -2439,9 +2388,9 @@ dependencies = [ [[package]] name = "quinn" -version = "0.11.11" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" dependencies = [ "bytes", "cfg_aliases", @@ -2459,9 +2408,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.15" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" dependencies = [ "aws-lc-rs", "bytes", @@ -2495,9 +2444,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.46" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -2542,7 +2491,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", - "getrandom 0.4.3", + "getrandom 0.4.2", "rand_core 0.10.1", ] @@ -2615,7 +2564,7 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", ] [[package]] @@ -2624,14 +2573,14 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b44b894f2a6e36457d665d1e08c3866add6ed5e70050c1b4ba8a8ddedb02ce7" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", ] [[package]] name = "regex" -version = "1.12.4" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -2658,9 +2607,9 @@ checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" [[package]] name = "regex-syntax" -version = "0.8.11" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "reqwest" @@ -2672,8 +2621,8 @@ dependencies = [ "bytes", "encoding_rs", "futures-core", - "h2 0.4.15", - "http 1.4.2", + "h2 0.4.14", + "http 1.4.1", "http-body", "http-body-util", "hyper", @@ -2778,7 +2727,7 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", "errno", "libc", "linux-raw-sys 0.12.1", @@ -2787,9 +2736,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.41" +version = "0.23.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f" +checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" dependencies = [ "aws-lc-rs", "log", @@ -2913,7 +2862,7 @@ version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", "core-foundation 0.10.1", "core-foundation-sys", "libc", @@ -2991,19 +2940,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sha1" version = "0.10.6" @@ -3104,9 +3040,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.15.2" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" dependencies = [ "serde", ] @@ -3253,7 +3189,7 @@ checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" dependencies = [ "atoi", "base64", - "bitflags 2.13.0", + "bitflags 2.12.1", "byteorder", "bytes", "crc", @@ -3295,7 +3231,7 @@ checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" dependencies = [ "atoi", "base64", - "bitflags 2.13.0", + "bitflags 2.12.1", "byteorder", "crc", "dotenvy", @@ -3371,6 +3307,12 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" + [[package]] name = "strum_macros" version = "0.27.2" @@ -3383,6 +3325,18 @@ dependencies = [ "syn", ] +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "subtle" version = "2.6.1" @@ -3391,9 +3345,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.118" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -3426,7 +3380,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", "core-foundation 0.9.4", "system-configuration-sys", ] @@ -3463,11 +3417,12 @@ dependencies = [ [[package]] name = "time" -version = "0.3.51" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c17d80feb7334b40c484e45ed1a5273dfd8bfda537c3be2e74a06a6686f327" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" dependencies = [ "deranged", + "itoa", "num-conv", "powerfmt", "serde_core", @@ -3477,15 +3432,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" [[package]] name = "time-macros" -version = "0.2.30" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcef1a61bdb119096e153208ec5cbec23944ce8bca13be5c7f60c634f7403935" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" dependencies = [ "num-conv", "time-core", @@ -3588,10 +3543,10 @@ version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" dependencies = [ - "bitflags 2.13.0", + "bitflags 2.12.1", "bytes", "futures-util", - "http 1.4.2", + "http 1.4.1", "http-body", "pin-project-lite", "tower", @@ -3650,6 +3605,33 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ttp-core" +version = "0.1.0" +source = "git+https://git.methanium.net/Tensamin/TTP.git#23438fa8f884e6ad0d32ca1004c0dedcce0cc8d2" +dependencies = [ + "base64", + "byteorder", + "rand 0.8.6", + "serde_json", + "strum 0.28.0", + "strum_macros 0.28.0", +] + +[[package]] +name = "ttp-native" +version = "0.1.0" +source = "git+https://git.methanium.net/Tensamin/TTP.git#23438fa8f884e6ad0d32ca1004c0dedcce0cc8d2" +dependencies = [ + "quinn", + "rustls", + "rustls-native-certs", + "thiserror", + "tokio", + "ttp-core", + "wtransport", +] + [[package]] name = "typenum" version = "1.20.1" @@ -3705,12 +3687,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "untrusted" version = "0.7.1" @@ -3743,11 +3719,11 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.23.4" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53" +checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7" dependencies = [ - "getrandom 0.4.3", + "getrandom 0.4.2", "js-sys", "wasm-bindgen", ] @@ -3803,11 +3779,20 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.4+wasi-0.2.12" +version = "1.0.3+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", ] [[package]] @@ -3818,9 +3803,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.126" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" dependencies = [ "cfg-if", "once_cell", @@ -3831,9 +3816,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.76" +version = "0.4.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d" +checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" dependencies = [ "js-sys", "wasm-bindgen", @@ -3841,9 +3826,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.126" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3851,9 +3836,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.126" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" dependencies = [ "bumpalo", "proc-macro2", @@ -3864,18 +3849,52 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.126" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" dependencies = [ "unicode-ident", ] [[package]] -name = "web-sys" -version = "0.3.103" +name = "wasm-encoder" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags 2.12.1", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436" dependencies = [ "js-sys", "wasm-bindgen", @@ -3893,9 +3912,9 @@ dependencies = [ [[package]] name = "webpki-root-certs" -version = "1.0.8" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267" +checksum = "f31141ce3fc3e300ae89b78c0dd67f9708061d1d2eda54b8209346fd6be9a92c" dependencies = [ "rustls-pki-types", ] @@ -4198,12 +4217,100 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + [[package]] name = "wit-bindgen" version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags 2.12.1", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + [[package]] name = "writeable" version = "0.6.3" @@ -4287,9 +4394,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -4310,18 +4417,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.52" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce1022995ff5ff5d841ad7d994facc23098cd40152f2c1d11cd607c6f530653f" +checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.52" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ae7f38b72ec2a254e2b87ef277cf2cd4fb97cbebf944faa6f33354da0867930" +checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" dependencies = [ "proc-macro2", "quote", @@ -4351,18 +4458,18 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.9.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.5.0" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" dependencies = [ "proc-macro2", "quote", @@ -4431,9 +4538,9 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.6.4" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "977347db8caa080403f6b6b7c1cda9479a8e869316f7e13a59b19076a40f94e3" +checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513" [[package]] name = "zmij" diff --git a/Cargo.toml b/Cargo.toml index 5d4e97e..22ec471 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2024" [dependencies] -mtp = { git = "https://git.methanium.net/methanium/mtp", features = ["host"] } +ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } +ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } actix-web = { version = "4.12.1", features = ["rustls-0_23"] } aes-gcm = "*" diff --git a/src/notifications/tauri.rs b/src/notifications/tauri.rs index 8195988..c57c26d 100644 --- a/src/notifications/tauri.rs +++ b/src/notifications/tauri.rs @@ -2,12 +2,12 @@ use crate::log; use crate::util::file_util::load_file_vec; use crate::util::logger::PrintType; use dashmap::DashMap; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; -use mtp::transport::{Host, Policy, Receiver, SendMode, Sender, host}; use once_cell::sync::Lazy; -use std::net::{IpAddr, Ipv4Addr}; use std::sync::Arc; use std::time::Duration; +use tokio::sync::futures; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; +use ttp_native::{Host, Policy, Receiver, SendMode, Sender}; pub struct TauriConnection { pub user_id: i64, @@ -20,8 +20,7 @@ pub async fn start(port: u16) -> Result<(), Box> { let cert_pem = load_file_vec("certs", "transport_cert.pem").expect("Error loading Pemfile"); let key_pem = load_file_vec("certs", "transport_key.pem").expect("Error loading Keyfile"); - let mut host: Host = host( - IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + let mut host: Host = ttp_native::host( port, cert_pem, key_pem, @@ -60,41 +59,45 @@ async fn handle_connection(sender: Sender, receiver: &mut Receiver) { let sender = Arc::new(sender); while let Ok(cv) = receiver.receive().await { - if cv.is_type(CommunicationType::TauriIdentification) { - let user_id = cv.get_data(DataType::UserId).as_number().unwrap_or(0) as i64; - if user_id != 0 { - current_user_id = user_id; - let conn = Arc::new(TauriConnection { - user_id, - sender: sender.clone(), - }); + match cv.get_type() { + CommunicationType::tauri_identification => { + let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0); + if user_id != 0 { + current_user_id = user_id; + let conn = Arc::new(TauriConnection { + user_id, + sender: sender.clone(), + }); - TAURI_CONNECTIONS - .entry(user_id) - .and_modify(|conns| { - conns.retain(|c| !Arc::ptr_eq(&c.sender.handle(), &sender.handle())); - conns.push(conn.clone()); - }) - .or_insert_with(|| vec![conn]); + TAURI_CONNECTIONS + .entry(user_id) + .and_modify(|conns| { + conns.retain(|c| !Arc::ptr_eq(&c.sender.handle(), &sender.handle())); + conns.push(conn.clone()); + }) + .or_insert_with(|| vec![conn]); - let response = - CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); - if let Err(e) = sender.send(&response).await { - log!( - PrintType::General, - "Failed to send tauri success response: {}", - e - ); - } else { - log!(user_id, PrintType::Client, "Tauri device registered"); + let response = + CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); + if let Err(e) = sender.send(&response).await { + log!( + PrintType::General, + "Failed to send tauri success response: {}", + e + ); + } else { + log!(user_id, PrintType::Client, "Tauri device registered"); + } } } - } else if cv.is_type(CommunicationType::Ping) { - let response = - CommunicationValue::new(CommunicationType::Pong).with_id(cv.get_id()); - if let Err(_) = sender.send(&response).await { - break; + CommunicationType::ping => { + let response = + CommunicationValue::new(CommunicationType::pong).with_id(cv.get_id()); + if let Err(_) = sender.send(&response).await { + break; + } } + _ => {} } } @@ -113,8 +116,8 @@ pub async fn send_notification(user_id: i64, sender_id: i64) { }; if let Some(conns) = conns_opt { - let cv = CommunicationValue::new(CommunicationType::PushNotification) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id as i128)); + let cv = CommunicationValue::new(CommunicationType::push_notification) + .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); let mut remove_needed = false; for conn in conns.iter() { @@ -138,8 +141,8 @@ pub async fn remove_notification(user_id: i64, sender_id: i64) { }; if let Some(conns) = conns_opt { - let cv = CommunicationValue::new(CommunicationType::ReadNotification) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id as i128)); + let cv = CommunicationValue::new(CommunicationType::read_notification) + .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); let mut remove_needed = false; for conn in conns.iter() { diff --git a/src/server/server.rs b/src/server/server.rs index c367679..3c7fc05 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -28,7 +28,7 @@ pub async fn start(port: u16) -> anyhow::Result<()> { .with_no_client_auth() .with_single_cert(cert_chain, key)?; - config.alpn_protocols = vec![b"h2".to_vec(), b"hmtp/1.1".to_vec()]; + config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; let bind_addr = std::env::var("BIND_ADDRESS").unwrap_or_else(|_| "0.0.0.0".to_string()); let addr = format!("{}:{}", bind_addr, port); diff --git a/src/server/short_link.rs b/src/server/short_link.rs index b3f91bd..c0ab51d 100644 --- a/src/server/short_link.rs +++ b/src/server/short_link.rs @@ -11,7 +11,7 @@ pub async fn add_short_link(long: &str) -> Result { LINKS.insert(raw.clone(), long.to_string()); Ok(format!( - "hmtps://omega.tensamin.net/direct/{}", + "https://omega.tensamin.net/direct/{}", format_with_dashes(&raw) )) } diff --git a/src/transport/omikron_connection.rs b/src/transport/omikron_connection.rs index cc53520..93804fd 100644 --- a/src/transport/omikron_connection.rs +++ b/src/transport/omikron_connection.rs @@ -11,9 +11,6 @@ use crate::{ }; use base64::{Engine as _, engine::general_purpose::STANDARD}; use dashmap::DashMap; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; -use mtp::transport::{Host, Policy, Receiver, SendMode, Sender, host}; -use std::net::{IpAddr, Ipv4Addr}; use rand::{Rng, distributions::Alphanumeric}; use std::{ sync::Arc, @@ -23,6 +20,8 @@ use tokio::{ sync::{Mutex, RwLock}, time::interval, }; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; +use ttp_native::{Host, Policy, Receiver, SendMode, Sender}; use x448::PublicKey; // ============================================================================ @@ -93,7 +92,7 @@ impl AuthState { } // ============================================================================ -// Omikron Connection (mtp/QUIC-based) +// Omikron Connection (ttp/QUIC-based) // ============================================================================ pub struct OmikronConnection { @@ -181,7 +180,7 @@ impl OmikronConnection { // ------------------------------------------------------------------------- async fn process_message(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - if !cv.is_type(CommunicationType::Pong) && !cv.is_type(CommunicationType::Ping) { + if !cv.is_type(CommunicationType::pong) && !cv.is_type(CommunicationType::ping) { log_cv_in!(PrintType::Omikron, &cv); } @@ -194,7 +193,7 @@ impl OmikronConnection { } // Handle ping regardless of auth state - if cv.is_type(CommunicationType::Ping) { + if cv.is_type(CommunicationType::ping) { return self.handle_ping(cv).await; } @@ -214,22 +213,22 @@ impl OmikronConnection { // ------------------------------------------------------------------------- async fn handle_unauthenticated(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - if !cv.is_type(CommunicationType::Identification) { + if !cv.is_type(CommunicationType::identification) { let _ = self - .send_error_response(cv.get_id(), CommunicationType::ErrorNotAuthenticated) + .send_error_response(cv.get_id(), CommunicationType::error_not_authenticated) .await; return Err(OmikronError::NotAuthenticated); } // Extract omikron ID let omikron_id = cv - .get_data(DataType::OmikronId) + .get_data(DataTypes::omikron_id) .as_number() .ok_or(OmikronError::InvalidResponse)?; log!("Omikron {:?} connected", omikron_id); // Lookup omikron in database - let (public_key, _) = get_omikron_by_id(omikron_id as i64) + let (public_key, _) = get_omikron_by_id(omikron_id) .await .map_err(|e| OmikronError::Sql(e.to_string()))?; @@ -262,9 +261,7 @@ impl OmikronConnection { log!("Stored Pubkey"); - *self.state.write().await = AuthState::Identified { - omikron_id: omikron_id as i64, - }; + *self.state.write().await = AuthState::Identified { omikron_id }; log!("Stored State"); @@ -282,28 +279,28 @@ impl OmikronConnection { log!("Encrypted Challenge"); // Send challenge response - let response = CommunicationValue::new(CommunicationType::Challenge) + let response = CommunicationValue::new(CommunicationType::challenge) .with_id(cv.get_id()) - .add_typed_default( - DataType::PublicKey, + .add_data( + DataTypes::public_key, DataValue::Str(STANDARD.encode(get_public_key().as_bytes())), ) - .add_typed_default(DataType::Content, DataValue::Str(encrypted)); + .add_data(DataTypes::challenge, DataValue::Str(encrypted)); log!("Sending Challenge"); self.send(&response).await } async fn handle_identified(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - if !cv.is_type(CommunicationType::ChallengeResponse) { + if !cv.is_type(CommunicationType::challenge_response) { let _ = self - .send_error_response(cv.get_id(), CommunicationType::ErrorNotAuthenticated) + .send_error_response(cv.get_id(), CommunicationType::error_not_authenticated) .await; return Err(OmikronError::NotAuthenticated); } let client_response = cv - .get_data(DataType::Content) + .get_data(DataTypes::challenge) .as_str() .ok_or(OmikronError::InvalidResponse)?; @@ -315,16 +312,16 @@ impl OmikronConnection { omikron_manager::add_omikron(self.clone()).await; - let response = CommunicationValue::new(CommunicationType::IdentificationResponse) + let response = CommunicationValue::new(CommunicationType::identification_response) .with_id(cv.get_id()) - .add_typed_default(DataType::Accepted, DataValue::Bool(true)); + .add_data(DataTypes::accepted, DataValue::Bool(true)); self.clone().send(&response).await?; log_in!(omikron_id, PrintType::Omega, "Omikron authenticated"); Ok(()) } else { let _ = self - .send_error_response(cv.get_id(), CommunicationType::ErrorInvalidChallenge) + .send_error_response(cv.get_id(), CommunicationType::error_invalid_challenge) .await; Err(OmikronError::AuthenticationFailed) } @@ -339,53 +336,52 @@ impl OmikronConnection { cv: CommunicationValue, omikron_id: i64, ) -> OmikronResult<()> { - let comm_type = cv.get_comm_type_enum(); - match comm_type { + match cv.get_type() { // Link shortening - Some(CommunicationType::ShortenLink) => self.handle_shorten_link(cv).await, + CommunicationType::shorten_link => self.handle_shorten_link(cv).await, // Online status tracking - Some(CommunicationType::UserConnected) => { + CommunicationType::user_connected => { self.handle_user_connected(cv, omikron_id).await; Ok(()) } - Some(CommunicationType::UserDisconnected) => { + CommunicationType::user_disconnected => { self.handle_user_disconnected(cv, omikron_id).await; Ok(()) } - Some(CommunicationType::IotaConnected) => { + CommunicationType::iota_connected => { self.handle_iota_connected(cv, omikron_id).await; Ok(()) } - Some(CommunicationType::IotaDisconnected) => { + CommunicationType::iota_disconnected => { self.handle_iota_disconnected(cv, omikron_id).await; Ok(()) } - Some(CommunicationType::SyncClientIotaStatus) => { + CommunicationType::sync_client_iota_status => { self.handle_sync_status(cv, omikron_id).await; Ok(()) } - Some(CommunicationType::GetUserData) => self.handle_get_user_data(cv).await, - Some(CommunicationType::GetIotaData) => self.handle_get_iota_data(cv).await, + CommunicationType::get_user_data => self.handle_get_user_data(cv).await, + CommunicationType::get_iota_data => self.handle_get_iota_data(cv).await, - Some(CommunicationType::GetRegister) => self.handle_get_register(cv).await, - Some(CommunicationType::CompleteRegisterIota) => { + CommunicationType::get_register => self.handle_get_register(cv).await, + CommunicationType::complete_register_iota => { self.handle_complete_register_iota(cv).await } - Some(CommunicationType::CompleteRegisterUser) => { + CommunicationType::complete_register_user => { self.handle_complete_register_user(cv).await } - Some(CommunicationType::ChangeUserData) => self.handle_change_user_data(cv).await, - Some(CommunicationType::ChangeIotaData) => self.handle_change_iota_data(cv).await, - Some(CommunicationType::DeleteUser) => self.handle_delete_user(cv).await, - Some(CommunicationType::DeleteIota) => self.handle_delete_iota(cv).await, + CommunicationType::change_user_data => self.handle_change_user_data(cv).await, + CommunicationType::change_iota_data => self.handle_change_iota_data(cv).await, + CommunicationType::delete_user => self.handle_delete_user(cv).await, + CommunicationType::delete_iota => self.handle_delete_iota(cv).await, - Some(CommunicationType::GetNotifications) => self.handle_get_notifications(cv).await, - Some(CommunicationType::ReadNotification) => self.handle_read_notification(cv).await, - Some(CommunicationType::PushNotification) => self.handle_push_notification(cv).await, - Some(CommunicationType::GetStates) => self.handle_get_states(cv).await, + CommunicationType::get_notifications => self.handle_get_notifications(cv).await, + CommunicationType::read_notification => self.handle_read_notification(cv).await, + CommunicationType::push_notification => self.handle_push_notification(cv).await, + CommunicationType::get_states => self.handle_get_states(cv).await, _ => { log_err!( @@ -405,7 +401,7 @@ impl OmikronConnection { async fn handle_shorten_link(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { let link = cv - .get_data(DataType::Link) + .get_data(DataTypes::link) .as_str() .ok_or(OmikronError::InvalidResponse)?; @@ -413,28 +409,32 @@ impl OmikronConnection { .await .map_err(|_| OmikronError::Sql("Shortend link Error".to_string()))?; - let response = CommunicationValue::new(CommunicationType::ShortenLink) + let response = CommunicationValue::new(CommunicationType::shorten_link) .with_id(cv.get_id()) - .add_typed_default(DataType::Link, DataValue::Str(short)); + .add_data(DataTypes::link, DataValue::Str(short)); self.send(&response).await } async fn handle_user_connected(self: Arc, cv: CommunicationValue, omikron_id: i64) { log_in!(PrintType::Omega, "User connected"); - if let Some(user_id) = cv.get_data(DataType::UserId).as_number() { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { let status = cv - .get_data(DataType::UserState) + .get_data(DataTypes::user_state) .as_str() .and_then(|s| UserStatus::from_str(s)) .unwrap_or(UserStatus::user_online); - user_online_tracker::track_user_status(user_id.try_into().unwrap(), status, omikron_id); + user_online_tracker::track_user_status( + user_id.try_into().unwrap(), + status, + omikron_id, + ); } } async fn handle_user_disconnected(self: Arc, cv: CommunicationValue, _omikron_id: i64) { log_in!(PrintType::Omega, "User disconnected"); - if let Some(user_id) = cv.get_data(DataType::UserId).as_number() { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { if let Some(status) = user_online_tracker::get_user_status(user_id as i64) { user_online_tracker::track_user_status( user_id as i64, @@ -447,7 +447,7 @@ impl OmikronConnection { async fn handle_iota_connected(self: Arc, cv: CommunicationValue, omikron_id: i64) { log_in!(PrintType::Omega, "IOTA connected"); - let iota_id = match cv.get_data(DataType::IotaId).as_number() { + let iota_id = match cv.get_data(DataTypes::iota_id).as_number() { Some(id) => id as i64, None => return, }; @@ -456,7 +456,7 @@ impl OmikronConnection { let mut user_ids = Vec::new(); if let Ok(users) = sql::get_users_by_iota_id(iota_id.try_into().unwrap()).await { for (user_id, _, _, _, _, _, _, _, _, _, _, _) in users { - user_ids.push(DataValue::SignedNumber(user_id.try_into().unwrap())); + user_ids.push(DataValue::Number(user_id.try_into().unwrap())); user_online_tracker::track_user_status( user_id.try_into().unwrap(), UserStatus::user_offline, @@ -467,16 +467,16 @@ impl OmikronConnection { log_in!(PrintType::General, "SQL error loading users for IOTA"); } - let response = CommunicationValue::new(CommunicationType::IotaUserData) + let response = CommunicationValue::new(CommunicationType::iota_user_data) .with_id(cv.get_id()) - .add_typed_default(DataType::UserIds, DataValue::Array(user_ids)); + .add_data(DataTypes::user_ids, DataValue::Array(user_ids)); let _ = self.send(&response).await; } async fn handle_iota_disconnected(self: Arc, cv: CommunicationValue, omikron_id: i64) { log_in!(PrintType::Omega, "IOTA disconnected"); - let iota_id = match cv.get_data(DataType::IotaId).as_number() { + let iota_id = match cv.get_data(DataTypes::iota_id).as_number() { Some(id) => id as i64, None => return, }; @@ -490,11 +490,11 @@ impl OmikronConnection { } async fn handle_sync_status(self: Arc, cv: CommunicationValue, omikron_id: i64) { - if let DataValue::Array(user_ids) = cv.get_data(DataType::UserIds) { + if let DataValue::Array(user_ids) = cv.get_data(DataTypes::user_ids) { for user_id_val in user_ids { - if let DataValue::SignedNumber(user_id) = user_id_val { + if let DataValue::Number(user_id) = user_id_val { user_online_tracker::track_user_status( - *user_id as i64, + *user_id, UserStatus::user_offline, omikron_id, ); @@ -502,10 +502,10 @@ impl OmikronConnection { } } - if let DataValue::Array(iota_ids) = cv.get_data(DataType::IotaIds) { + if let DataValue::Array(iota_ids) = cv.get_data(DataTypes::iota_ids) { for iota_id_val in iota_ids { - if let DataValue::SignedNumber(iota_id) = iota_id_val { - user_online_tracker::track_iota_connection(*iota_id as i64, omikron_id, true); + if let DataValue::Number(iota_id) = iota_id_val { + user_online_tracker::track_iota_connection(*iota_id, omikron_id, true); } } } @@ -513,7 +513,7 @@ impl OmikronConnection { async fn handle_get_user_data(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { // Try by user_id first - if let Some(user_id) = cv.get_data(DataType::UserId).as_number() { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { if let Ok(user_data) = get_by_user_id(user_id as i64).await { let response = self .clone() @@ -524,7 +524,7 @@ impl OmikronConnection { } // Try by username - if let Some(username) = cv.get_data(DataType::Username).as_str() { + if let Some(username) = cv.get_data(DataTypes::username).as_str() { if let Ok(user_data) = get_by_username(username).await { let response = self .clone() @@ -536,7 +536,7 @@ impl OmikronConnection { // Not found let response = - CommunicationValue::new(CommunicationType::ErrorNotFound).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::error_not_found).with_id(cv.get_id()); self.send(&response).await } @@ -573,28 +573,28 @@ impl OmikronConnection { _, ) = user; - let mut response = CommunicationValue::new(CommunicationType::GetUserData) + let mut response = CommunicationValue::new(CommunicationType::get_user_data) .with_id(msg_id) - .add_typed_default(DataType::Username, DataValue::Str(username.clone())) - .add_typed_default(DataType::PublicKey, DataValue::Str(public_key)) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(id.into())) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())) - .add_typed_default(DataType::SubLevel, DataValue::SignedNumber(sub_level as i128)) - .add_typed_default(DataType::SubEnd, DataValue::SignedNumber(sub_end.into())); + .add_data(DataTypes::username, DataValue::Str(username.clone())) + .add_data(DataTypes::public_key, DataValue::Str(public_key)) + .add_data(DataTypes::user_id, DataValue::Number(id)) + .add_data(DataTypes::iota_id, DataValue::Number(iota_id)) + .add_data(DataTypes::sub_level, DataValue::Number(sub_level as i64)) + .add_data(DataTypes::sub_end, DataValue::Number(sub_end)); // Display name (fallback to username) let display_name = display.filter(|d| !d.is_empty()).unwrap_or(username); - response = response.add_typed_default(DataType::Display, DataValue::Str(display_name)); + response = response.add_data(DataTypes::display, DataValue::Str(display_name)); // Optional fields if let Some(s) = status.filter(|s| !s.is_empty()) { - response = response.add_typed_default(DataType::Status, DataValue::Str(s)); + response = response.add_data(DataTypes::status, DataValue::Str(s)); } if let Some(a) = about.filter(|a| !a.is_empty()) { - response = response.add_typed_default(DataType::About, DataValue::Str(a)); + response = response.add_data(DataTypes::about, DataValue::Str(a)); } if let Some(av) = avatar { - response = response.add_typed_default(DataType::Avatar, DataValue::Str(STANDARD.encode(av))); + response = response.add_data(DataTypes::avatar, DataValue::Str(STANDARD.encode(av))); } // Online status @@ -608,24 +608,24 @@ impl OmikronConnection { } else { us.connection_type.clone() }; - response = response.add_typed_default( - DataType::OnlineStatus, + response = response.add_data( + DataTypes::online_status, DataValue::Str(display_status.to_string()), ); - response = response.add_typed_default(DataType::OmikronId, DataValue::SignedNumber(us.omikron_id.into())); + response = response.add_data(DataTypes::omikron_id, DataValue::Number(us.omikron_id)); } else { - response = response.add_typed_default( - DataType::OnlineStatus, + response = response.add_data( + DataTypes::online_status, DataValue::Str(UserStatus::iota_offline.to_string()), ); } - response = response.add_typed_default( - DataType::OmikronConnections, + response = response.add_data( + DataTypes::omikron_connections, DataValue::Array( iota_connections .into_iter() - .map(|id| DataValue::SignedNumber(id as i128)) + .map(DataValue::Number) .collect(), ), ); @@ -635,7 +635,7 @@ impl OmikronConnection { async fn handle_get_iota_data(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { // Try by iota_id - if let Some(iota_id) = cv.get_data(DataType::IotaId).as_number() { + if let Some(iota_id) = cv.get_data(DataTypes::iota_id).as_number() { if let Ok((iota_id, public_key)) = get_iota_by_id(iota_id as i64).await { let response = self .clone() @@ -646,7 +646,7 @@ impl OmikronConnection { } // Try by user_id - if let Some(user_id) = cv.get_data(DataType::UserId).as_number() { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { if let Ok((_, iota_id, _, _, _, _, _, _, _, _, _, _)) = get_by_user_id(user_id as i64).await { @@ -667,7 +667,7 @@ impl OmikronConnection { } // Try by username - if let Some(username) = cv.get_data(DataType::Username).as_str() { + if let Some(username) = cv.get_data(DataTypes::username).as_str() { if let Ok((user_id, iota_id, _, _, _, _, _, _, _, _, _, _)) = get_by_username(username).await { @@ -688,7 +688,7 @@ impl OmikronConnection { } let response = - CommunicationValue::new(CommunicationType::ErrorNotFound).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::error_not_found).with_id(cv.get_id()); self.send(&response).await } @@ -700,27 +700,27 @@ impl OmikronConnection { user_id: Option, username: Option, ) -> CommunicationValue { - let mut response = CommunicationValue::new(CommunicationType::GetIotaData) + let mut response = CommunicationValue::new(CommunicationType::get_iota_data) .with_id(msg_id) - .add_typed_default(DataType::PublicKey, DataValue::Str(public_key)) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())); + .add_data(DataTypes::public_key, DataValue::Str(public_key)) + .add_data(DataTypes::iota_id, DataValue::Number(iota_id)); if let Some(uid) = user_id { - response = response.add_typed_default(DataType::UserId, DataValue::SignedNumber(uid.into())); + response = response.add_data(DataTypes::user_id, DataValue::Number(uid)); } if let Some(uname) = username { - response = response.add_typed_default(DataType::Username, DataValue::Str(uname)); + response = response.add_data(DataTypes::username, DataValue::Str(uname)); } let iota_connections = user_online_tracker::get_iota_omikron_connections(iota_id).unwrap_or_default(); - response.add_typed_default( - DataType::OmikronConnections, + response.add_data( + DataTypes::omikron_connections, DataValue::Array( iota_connections .into_iter() - .map(|id| DataValue::SignedNumber(id as i128)) + .map(DataValue::Number) .collect(), ), ) @@ -728,9 +728,9 @@ impl OmikronConnection { async fn handle_get_register(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { let register_id = sql::get_register_id().await; - let response = CommunicationValue::new(CommunicationType::GetRegister) + let response = CommunicationValue::new(CommunicationType::get_register) .with_id(cv.get_id()) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(register_id as i128)); + .add_data(DataTypes::user_id, DataValue::Number(register_id as i64)); self.send(&response).await } @@ -738,21 +738,24 @@ impl OmikronConnection { self: Arc, cv: CommunicationValue, ) -> OmikronResult<()> { - let iota_id_opt = cv.get_data(DataType::IotaId).as_number().map(|n| n as i64); + let iota_id_opt = cv + .get_data(DataTypes::iota_id) + .as_number() + .map(|n| n as i64); - if let Some(public_key) = cv.get_data(DataType::PublicKey).as_str() { + if let Some(public_key) = cv.get_data(DataTypes::public_key).as_str() { if let Some(iota_id) = iota_id_opt { // Register existing IOTA match sql::register_complete_iota(iota_id, public_key.to_string()).await { Ok(_) => { - let response = CommunicationValue::new(CommunicationType::Success) + let response = CommunicationValue::new(CommunicationType::success) .with_id(cv.get_id()); self.send(&response).await } Err(e) => { - let response = CommunicationValue::new(CommunicationType::ErrorInternal) + let response = CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); + .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); self.send(&response).await } } @@ -761,21 +764,21 @@ impl OmikronConnection { match sql::create_new_iota(public_key.to_string()).await { Ok(new_iota_id) => { let response = - CommunicationValue::new(CommunicationType::CompleteRegisterIota) + CommunicationValue::new(CommunicationType::complete_register_iota) .with_id(cv.get_id()) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(new_iota_id.into())); + .add_data(DataTypes::iota_id, DataValue::Number(new_iota_id)); self.send(&response).await } Err(e) => { - let response = CommunicationValue::new(CommunicationType::ErrorInternal) + let response = CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); + .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); self.send(&response).await } } } } else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidData) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data) .await } } @@ -784,18 +787,21 @@ impl OmikronConnection { self: Arc, cv: CommunicationValue, ) -> OmikronResult<()> { - let user_id = cv.get_data(DataType::UserId).as_number().map(|n| n as i64); + let user_id = cv + .get_data(DataTypes::user_id) + .as_number() + .map(|n| n as i64); let username = cv - .get_data(DataType::Username) + .get_data(DataTypes::username) .as_str() .map(|s| s.to_string()); let public_key = cv - .get_data(DataType::PublicKey) + .get_data(DataTypes::public_key) .as_str() .map(|s| s.to_string()); let iota_id = cv.get_sender(); let reset_token = cv - .get_data(DataType::ResetToken) + .get_data(DataTypes::reset_token) .as_str() .map(|s| s.to_string()); @@ -805,18 +811,18 @@ impl OmikronConnection { match sql::register_complete_user(uid, uname, pk, iota_id as i64, rt).await { Ok(_) => { let response = - CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); self.send(&response).await } Err(e) => { - let response = CommunicationValue::new(CommunicationType::ErrorInternal) + let response = CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); + .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); self.send(&response).await } } } else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidData) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data) .await } } @@ -827,39 +833,39 @@ impl OmikronConnection { let mut error_message = String::new(); // Process each field - if let Some(username) = cv.get_data(DataType::Username).as_str() { + if let Some(username) = cv.get_data(DataTypes::username).as_str() { if let Err(e) = sql::change_username(user_id, username.to_string()).await { success = false; error_message = e.to_string(); } } - if let Some(display) = cv.get_data(DataType::Display).as_str() { + if let Some(display) = cv.get_data(DataTypes::display).as_str() { if let Err(e) = sql::change_display_name(user_id, display.to_string()).await { success = false; error_message = e.to_string(); } } - if let Some(avatar) = cv.get_data(DataType::Avatar).as_str() { + if let Some(avatar) = cv.get_data(DataTypes::avatar).as_str() { if let Err(e) = sql::change_avatar(user_id, avatar.to_string()).await { success = false; error_message = e.to_string(); } } - if let Some(about) = cv.get_data(DataType::About).as_str() { + if let Some(about) = cv.get_data(DataTypes::about).as_str() { if let Err(e) = sql::change_about(user_id, about.to_string()).await { success = false; error_message = e.to_string(); } } - if let Some(status) = cv.get_data(DataType::Status).as_str() { + if let Some(status) = cv.get_data(DataTypes::status).as_str() { if let Err(e) = sql::change_status(user_id, status.to_string()).await { success = false; error_message = e.to_string(); } } if let (Some(public_key), Some(private_key_hash)) = ( - cv.get_data(DataType::PublicKey).as_str(), - cv.get_data(DataType::PrivateKeyHash).as_str(), + cv.get_data(DataTypes::public_key).as_str(), + cv.get_data(DataTypes::private_key_hash).as_str(), ) { if let Err(e) = sql::change_keys( user_id, @@ -874,12 +880,12 @@ impl OmikronConnection { } if success { - let response = CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); + let response = CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); self.send(&response).await } else { - let response = CommunicationValue::new(CommunicationType::ErrorInternal) + let response = CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(error_message)); + .add_data(DataTypes::error_type, DataValue::Str(error_message)); self.send(&response).await } } @@ -889,8 +895,8 @@ impl OmikronConnection { if let (iota_id, Some(reset_token), Some(new_token)) = ( cv.get_sender(), - cv.get_data(DataType::ResetToken).as_str(), - cv.get_data(DataType::NewToken).as_str(), + cv.get_data(DataTypes::reset_token).as_str(), + cv.get_data(DataTypes::new_token).as_str(), ) { match sql::get_by_user_id(user_id).await { Ok(user) => { @@ -912,31 +918,31 @@ impl OmikronConnection { } if success { - let response = CommunicationValue::new(CommunicationType::Success) + let response = CommunicationValue::new(CommunicationType::success) .with_id(cv.get_id()); self.send(&response).await } else { let response = - CommunicationValue::new(CommunicationType::ErrorInternal) + CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(error_message)); + .add_data(DataTypes::error_type, DataValue::Str(error_message)); self.send(&response).await } } else { self.send_error_response( cv.get_id(), - CommunicationType::ErrorInvalidChallenge, + CommunicationType::error_invalid_challenge, ) .await } } Err(_) => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNotFound) + self.send_error_response(cv.get_id(), CommunicationType::error_not_found) .await } } } else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidData) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data) .await } } @@ -946,13 +952,13 @@ impl OmikronConnection { match sql::delete_user(user_id).await { Ok(_) => { let response = - CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); self.send(&response).await } Err(e) => { - let response = CommunicationValue::new(CommunicationType::ErrorInternal) + let response = CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); + .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); self.send(&response).await } } @@ -963,13 +969,13 @@ impl OmikronConnection { match sql::delete_iota(iota_id as i64).await { Ok(_) => { let response = - CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); self.send(&response).await } Err(e) => { - let response = CommunicationValue::new(CommunicationType::ErrorInternal) + let response = CommunicationValue::new(CommunicationType::error_internal) .with_id(cv.get_id()) - .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); + .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); self.send(&response).await } } @@ -984,10 +990,9 @@ impl OmikronConnection { Ok(notifications) => notifications .into_iter() .map(|(sender, amount)| { - let tm = mtp::type_map::TypeMap::latest(); DataValue::Container(vec![ - (DataType::SenderId.to_id(&tm), DataValue::SignedNumber(sender.into())), - (DataType::Amount.to_id(&tm), DataValue::SignedNumber(amount.into())), + (DataTypes::sender_id, DataValue::Number(sender)), + (DataTypes::amount, DataValue::Number(amount)), ]) }) .collect(), @@ -997,9 +1002,9 @@ impl OmikronConnection { } }; - let response = CommunicationValue::new(CommunicationType::GetNotifications) + let response = CommunicationValue::new(CommunicationType::get_notifications) .with_id(cv.get_id()) - .add_typed_default(DataType::Notifications, DataValue::Array(response_array)); + .add_data(DataTypes::notifications, DataValue::Array(response_array)); self.send(&response).await } @@ -1009,21 +1014,21 @@ impl OmikronConnection { ) -> OmikronResult<()> { let receiver_id = match cv.get_sender() { s if s > 0 => s as i64, - _ => match cv.get_data(DataType::ReceiverId).as_number() { + _ => match cv.get_data(DataTypes::receiver_id).as_number() { Some(id) => id as i64, None => return Ok(()), }, }; if let Some(other_id) = cv - .get_data(DataType::SenderId) + .get_data(DataTypes::sender_id) .as_number() .map(|n| n as i64) { if let Err(e) = sql::read_notification(receiver_id, other_id).await { log!(PrintType::General, "SQL read_notification error: {}", e); } else { - let response = CommunicationValue::new(CommunicationType::ReadNotification) + let response = CommunicationValue::new(CommunicationType::read_notification) .with_id(cv.get_id()); let _ = self.send(&response).await; @@ -1031,9 +1036,9 @@ impl OmikronConnection { crate::notifications::tauri::remove_notification(receiver_id, other_id).await; // Sync with other Omikron clients - let sync_cv = CommunicationValue::new(CommunicationType::ReadNotification) + let sync_cv = CommunicationValue::new(CommunicationType::read_notification) .with_receiver(receiver_id as u64) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(other_id.into())); + .add_data(DataTypes::sender_id, DataValue::Number(other_id)); crate::transport::omikron_manager::send_to_user(receiver_id, &sync_cv).await; } } @@ -1046,13 +1051,13 @@ impl OmikronConnection { ) -> OmikronResult<()> { let receiver_id = match cv.get_receiver() { r if r > 0 => r as i64, - _ => match cv.get_data(DataType::ReceiverId).as_number() { + _ => match cv.get_data(DataTypes::receiver_id).as_number() { Some(id) => id as i64, None => return Ok(()), }, }; - let sender_id = match cv.get_data(DataType::SenderId).as_number() { + let sender_id = match cv.get_data(DataTypes::sender_id).as_number() { Some(id) => id as i64, None => cv.get_sender() as i64, }; @@ -1061,31 +1066,31 @@ impl OmikronConnection { log!(PrintType::General, "SQL add_notification error: {}", e); } else { let response = - CommunicationValue::new(CommunicationType::PushNotification).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::push_notification).with_id(cv.get_id()); let _ = self.send(&response).await; // Sync with Tauri crate::notifications::tauri::send_notification(receiver_id, sender_id).await; // Sync with other Omikron clients - let push_cv = CommunicationValue::new(CommunicationType::PushNotification) + let push_cv = CommunicationValue::new(CommunicationType::push_notification) .with_receiver(receiver_id as u64) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id.into())); + .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); crate::transport::omikron_manager::send_to_user(receiver_id, &push_cv).await; } Ok(()) } async fn handle_get_states(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - let user_ids = match cv.get_data(DataType::UserIds) { + let user_ids = match cv.get_data(DataTypes::user_ids) { DataValue::Array(ids) => ids, _ => return Ok(()), }; let mut states = Vec::new(); for id_val in user_ids { - if let DataValue::SignedNumber(user_id) = id_val { - let user_id = *user_id as i64; + if let DataValue::Number(user_id) = id_val { + let user_id = *user_id; let status = user_online_tracker::get_user_status(user_id); let status_str = match status { Some(ref us) => { @@ -1097,26 +1102,25 @@ impl OmikronConnection { } None => UserStatus::iota_offline.to_string(), }; - let tm = mtp::type_map::TypeMap::latest(); let mut map = Vec::new(); - map.push((DataType::UserId.to_id(&tm), DataValue::SignedNumber(user_id.into()))); - map.push((DataType::UserState.to_id(&tm), DataValue::Str(status_str))); + map.push((DataTypes::user_id, DataValue::Number(user_id))); + map.push((DataTypes::user_state, DataValue::Str(status_str))); states.push(DataValue::Container(map)); } } - let response = CommunicationValue::new(CommunicationType::GetStates) + let response = CommunicationValue::new(CommunicationType::get_states) .with_id(cv.get_id()) - .add_typed_default(DataType::UserStates, DataValue::Array(states)); + .add_data(DataTypes::user_states, DataValue::Array(states)); self.send(&response).await } async fn handle_ping(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - if let DataValue::SignedNumber(last_ping) = cv.get_data(DataType::LastPing) { - *self.ping.write().await = *last_ping as i64; + if let DataValue::Number(last_ping) = cv.get_data(DataTypes::last_ping) { + *self.ping.write().await = *last_ping; } - let response = CommunicationValue::new(CommunicationType::Pong).with_id(cv.get_id()); + let response = CommunicationValue::new(CommunicationType::pong).with_id(cv.get_id()); self.send(&response).await } @@ -1125,7 +1129,7 @@ impl OmikronConnection { // ------------------------------------------------------------------------- async fn send(self: Arc, cv: &CommunicationValue) -> OmikronResult<()> { - if !cv.is_type(CommunicationType::Pong) && !cv.is_type(CommunicationType::Ping) { + if !cv.is_type(CommunicationType::pong) && !cv.is_type(CommunicationType::ping) { log_cv_out!(PrintType::Omikron, cv); } @@ -1192,8 +1196,7 @@ pub async fn start(port: u16) -> Result<(), Box> { let key_pem = load_file_vec("certs", "transport_key.pem").expect("Error loading Keyfile"); - let mut host: Host = host( - IpAddr::from(Ipv4Addr::new(0, 0, 0, 0)), + let mut host: Host = ttp_native::host( port, cert_pem, key_pem, diff --git a/src/transport/omikron_manager.rs b/src/transport/omikron_manager.rs index f98a75c..70c73cd 100644 --- a/src/transport/omikron_manager.rs +++ b/src/transport/omikron_manager.rs @@ -1,9 +1,9 @@ use crate::transport::omikron_connection::OmikronConnection; use dashmap::DashMap; -use mtp::codec::CommunicationValue; use once_cell::sync::Lazy; use rand::prelude::IteratorRandom; use std::sync::Arc; +use ttp_core::CommunicationValue; pub static OMIKRON_CONNECTIONS: Lazy>> = Lazy::new(|| DashMap::new()); diff --git a/src/util/logger.rs b/src/util/logger.rs index 31606b6..845489f 100644 --- a/src/util/logger.rs +++ b/src/util/logger.rs @@ -1,4 +1,5 @@ use std::{ + collections::BTreeMap, fs::{self, OpenOptions}, io::Write, path::Path, @@ -8,7 +9,7 @@ use std::{ }; use ansi_term::Color; -use mtp::codec::{CommunicationValue, DataTypeId, DataValue, Version}; +use ttp_core::{CommunicationValue, DataTypes, DataValue}; use crate::util::file_util::get_directory; @@ -247,19 +248,17 @@ pub fn format_cv(cv: &CommunicationValue) -> String { let comm_type = cv.get_type().to_string(); parts.push(format!("{}", comm_type)); - let data = cv.data(); + let data: &BTreeMap = cv.get_data_container(); - let formated_data = format_data_container( - data.iter().map(|(k, v)| (*k, v.clone())).collect(), - Version(1, 0), - ); + let formated_data = + format_data_container(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); parts.push(format!("{}", formated_data)); parts.join(": ") } -fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) -> String { +fn format_data_container(data: Vec<(DataTypes, DataValue)>) -> String { let parts: Vec = data .into_iter() .map(|(key, value)| { @@ -269,13 +268,12 @@ fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) - DataValue::Str(s) => format!("{}=\"{}\"", key_str, s), DataValue::Container(inner) => { - let inner_formatted = - format_data_container(inner, version.clone()); + let inner_formatted = format_data_container(inner); format!("{}={{ {} }}", key_str, inner_formatted) } DataValue::Array(arr) => { - let arr_formatted = format_array(arr, version.clone()); + let arr_formatted = format_array(arr); format!("{}=[{}]", key_str, arr_formatted) } @@ -284,7 +282,7 @@ fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) - DataValue::BoolTrue => format!("{}=true", key_str), DataValue::BoolFalse => format!("{}=false", key_str), - DataValue::SignedNumber(num) => format!("{}={}", key_str, num), + DataValue::Number(num) => format!("{}={}", key_str, num), _ => "".to_string(), } @@ -294,19 +292,19 @@ fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) - parts.join(", ") } -fn format_array(arr: Vec, version: Version) -> String { +fn format_array(arr: Vec) -> String { let parts: Vec = arr .into_iter() .map(|value| match value { DataValue::Str(s) => format!("\"{}\"", s), DataValue::Container(inner) => { - let inner_formatted = format_data_container(inner, version.clone()); + let inner_formatted = format_data_container(inner); format!("{{ {} }}", inner_formatted) } DataValue::Array(inner_arr) => { - let formatted = format_array(inner_arr, version.clone()); + let formatted = format_array(inner_arr); format!("[{}]", formatted) } @@ -315,7 +313,7 @@ fn format_array(arr: Vec, version: Version) -> String { DataValue::BoolTrue => "true".to_string(), DataValue::BoolFalse => "false".to_string(), - DataValue::SignedNumber(num) => num.to_string(), + DataValue::Number(num) => num.to_string(), _ => String::new(), }) diff --git a/type-maps.yaml b/type-maps.yaml deleted file mode 100644 index 73a15e3..0000000 --- a/type-maps.yaml +++ /dev/null @@ -1,240 +0,0 @@ -# The version a Client should use -protocol_version: "1.0" - -# Note that markers 0 to 31 are reserved for default use, manually working with them is not recommended -# Fixed CommunicationType markers are: -# Error: 0 -# ErrorParsing: 1 -# ErrorBadVersion: 2 -# Disconnect: 3 -# Redirect: 4 -# Shutdown: 5 -# BadRequest: 6 -# Unauthorized: 7 -# Forbidden: 8 -# NotFound: 9 -# TooManyRequests: 10 -# InternalServerError: 11 -# BadGateway: 12 -# ServiceUnavailable: 13 -# GatewayTimeout: 14 -# Identification: 15 -# IdentificationResponse: 16 -# Register: 17 -# RegisterResponse: 18 -# Ping: 19 -# Pong: 20 -# -# Fixed Data Type markers are: -# Error: 0 -# ErrorParsing: 1 -# ErrorMessage: 2 -# Version: 3 -# Description: 4 -# Timestamp: 5 -# Id: 6 -# ClientNonce: 7 -# ServerNonce: 8 -# PublicKeys: 9 -# Signature: 10 -# Connected: 11 -# -# If a Type can't be used it will be mapped to 0 - -type_maps: - "1.0": # Protocol version 1.0 - CommunicationTypes: - ErrorProtocol: 33 - ErrorAnonymous: 34 - ErrorInternal: 35 - ErrorInvalidData: 36 - ErrorInvalidUserId: 37 - ErrorInvalidOmikronId: 38 - ErrorNotFound: 39 - ErrorNotAuthenticated: 40 - ErrorNoIota: 41 - ErrorInvalidChallenge: 42 - ErrorInvalidSecret: 43 - ErrorInvalidPrivateKey: 44 - ErrorInvalidPublicKey: 45 - ErrorNoUserId: 46 - ErrorNoCallId: 47 - ErrorInvalidCallId: 48 - Success: 49 - ShortenLink: 50 - SettingsSave: 51 - SettingsLoad: 52 - SettingsList: 53 - GlobalSettingsSave: 54 - GlobalSettingsLoad: 55 - Message: 56 - MessageState: 57 - MessageSend: 58 - MessageLive: 59 - MessageOtherIota: 60 - MessageChunk: 61 - MessagesGet: 62 - PushNotification: 63 - ReadNotification: 64 - GetNotifications: 65 - TauriIdentification: 66 - ChangeConfirm: 67 - ConfirmReceive: 68 - ConfirmRead: 69 - GetChats: 70 - GetStates: 71 - AddCommunity: 72 - RemoveCommunity: 73 - GetCommunities: 74 - RegisterIota: 81 - RegisterIotaSuccess: 82 - AddConversation: 85 - SendChat: 86 - ClientChanged: 87 - ClientConnected: 88 - ClientDisconnected: 89 - ClientClosed: 90 - PublicKey: 91 - PrivateKey: 92 - WebrtcSdp: 93 - WebrtcIce: 94 - StartStream: 95 - EndStream: 96 - WatchStream: 97 - CallToken: 98 - CallInvite: 99 - CallDisconnectUser: 100 - CallTimeoutUser: 101 - CallSetAnonymousJoining: 102 - CallData: 103 - EndCall: 104 - Function: 105 - Update: 106 - CreateUser: 107 - RhoUpdate: 108 - UserConnected: 109 - UserDisconnected: 110 - IotaConnected: 111 - IotaDisconnected: 112 - SyncClientIotaStatus: 113 - GetUserData: 114 - GetIotaData: 115 - IotaUserData: 116 - ChangeUserData: 117 - ChangeIotaData: 118 - GetRegister: 119 - CompleteRegisterUser: 120 - CompleteRegisterIota: 121 - DeleteUser: 122 - DeleteIota: 123 - StartRegister: 124 - CompleteRegister: 125 - GetApp: 126 - CreateApp: 127 - DeleteApp: 128 - SaveAppData: 129 - LoadAppData: 130 - AppIdentification: 131 - AppChallenge: 132 - AppChallengeResponse: 133 - AppIdentificationResponse: 134 - LoadTxtRecord: 135 - DataTypes: - ErrorType: 32 - ErrorProtocol: 33 - AcceptedIds: 34 - Uuid: 35 - RegisterId: 36 - Link: 37 - Settings: 38 - SettingsName: 39 - ChatPartnerId: 40 - ChatPartnerName: 41 - IotaId: 42 - UserId: 43 - UserIds: 44 - IotaIds: 45 - UserState: 46 - UserStates: 47 - UserPings: 48 - CallState: 49 - ScreenShare: 50 - PrivateKeyHash: 51 - Accepted: 52 - AcceptedProfiles: 53 - DeniedProfiles: 54 - Content: 55 - Messages: 56 - Notifications: 57 - SendTime: 58 - GetTime: 59 - GetVariant: 60 - SharedSecretOwn: 61 - SharedSecretOther: 62 - SharedSecretSign: 63 - SharedSecret: 64 - CallId: 65 - CallToken: 66 - CallSecret: 67 - Untill: 68 - Enabled: 69 - StartDate: 70 - EndDate: 71 - ReceiverId: 72 - SenderId: 73 - Signed: 75 - Message: 76 - MessageState: 77 - LastPing: 78 - PingIota: 79 - PingClients: 80 - Matches: 81 - Omikron: 82 - Offset: 83 - Amount: 84 - Position: 85 - Name: 86 - Path: 87 - Codec: 88 - Function: 89 - Payload: 90 - Result: 91 - Interactables: 92 - WantToWatch: 93 - Watcher: 94 - CreatedAt: 95 - Username: 96 - Display: 97 - Avatar: 98 - About: 99 - Status: 100 - PublicKey: 101 - SubLevel: 102 - SubEnd: 103 - CommunityAddress: 104 - CommunityTitle: 106 - Communities: 107 - RhoConnections: 108 - User: 109 - OnlineStatus: 110 - OmikronId: 111 - OmikronConnections: 112 - ResetToken: 113 - NewToken: 114 - CallInvited: 115 - CallMembers: 116 - Calls: 117 - Timeout: 118 - HasAdmin: 119 - LastMessageAt: 120 - Height: 121 - SentBySelf: 122 - SessionId: 123 - Contacts: 124 - LastMessage: 125 - AppIdentifier: 127 - AppPrivateKey: 128 - AppPublicKey: 129 - AppSession: 130 - AppData: 131 - TauriToken: 132