diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..d363b83 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[env] +MTP_TYPE_MAPS = { value = "type-maps.yaml", relative = true } diff --git a/Cargo.lock b/Cargo.lock index 5f83697..1f85cb3 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.12.1", + "bitflags 2.13.0", "bytes", "futures-core", "futures-sink", @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.12.1" +version = "3.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93acb4a42f64936f9b8cae4a433b237599dd6eb6ed06124eb67132ef8cc90662" +checksum = "48e2faa3e7418ed780cca54829d32782a4008a077230f67457caa063415e99c2" dependencies = [ "actix-codec", "actix-rt", @@ -31,14 +31,14 @@ dependencies = [ "actix-tls", "actix-utils", "base64", - "bitflags 2.12.1", + "bitflags 2.13.0", "brotli", "bytes", "bytestring", "derive_more", "encoding_rs", "flate2", - "foldhash", + "foldhash 0.2.0", "futures-core", "h2 0.3.27", "http 0.2.12", @@ -131,7 +131,7 @@ dependencies = [ "actix-service", "actix-utils", "futures-core", - "impl-more", + "impl-more 0.1.9", "pin-project-lite", "rustls-pki-types", "tokio", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.13.0" +version = "4.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff87453bc3b56e9b2b23c1cc0b1be8797184accf51d2abe0f8a33ec275d316bf" +checksum = "df09e2d9239703dd64056359c920c7f3fba6535ec61a0059e0f44e095ffe02b4" dependencies = [ "actix-codec", "actix-http", @@ -172,10 +172,10 @@ dependencies = [ "cookie", "derive_more", "encoding_rs", - "foldhash", + "foldhash 0.2.0", "futures-core", "futures-util", - "impl-more", + "impl-more 0.3.1", "itoa", "language-tags", "log", @@ -264,9 +264,9 @@ checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" [[package]] name = "alloc-stdlib" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195" dependencies = [ "alloc-no-stdlib", ] @@ -288,9 +288,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.102" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" [[package]] name = "arbitrary" @@ -555,9 +555,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" dependencies = [ "serde_core", ] @@ -573,9 +573,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" dependencies = [ "hybrid-array", ] @@ -595,9 +595,9 @@ dependencies = [ [[package]] name = "brotli" -version = "8.0.3" +version = "8.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8119e4516436f5708bbc474a9d395bf12f1b5395e93a92a56e647ac3388c8610" +checksum = "5cc91aac060a7a1e25823bdccbfb6af1875b88f17c6daac97894eed8207166b3" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -606,9 +606,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "5.0.1" +version = "5.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5962523e1b92ce1b5e793d9169b9943eece10d39f62550bc04bb605d75b94924" +checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -628,9 +628,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" [[package]] name = "bytestring" @@ -652,9 +652,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.63" +version = "1.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" +checksum = "e228eec9be7c17ccb640b59b36a5cd805ea2a564a4c5e162c2f659fea30d3b96" dependencies = [ "find-msvc-tools", "jobserver", @@ -676,9 +676,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chacha20" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" dependencies = [ "cfg-if", "cpufeatures 0.3.0", @@ -929,9 +929,6 @@ name = "deranged" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" -dependencies = [ - "powerfmt", -] [[package]] name = "derive_arbitrary" @@ -985,7 +982,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer 0.12.0", + "block-buffer 0.12.1", "const-oid 0.10.2", "crypto-common 0.2.2", ] @@ -1163,6 +1160,12 @@ 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" @@ -1316,16 +1319,14 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", "rand_core 0.10.1", - "wasip2", - "wasip3", ] [[package]] @@ -1371,16 +1372,16 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" +checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155" dependencies = [ "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "http 1.4.1", + "http 1.4.2", "indexmap", "slab", "tokio", @@ -1402,7 +1403,7 @@ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "allocator-api2", "equivalent", - "foldhash", + "foldhash 0.1.5", ] [[package]] @@ -1490,9 +1491,9 @@ dependencies = [ [[package]] name = "http" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0" +checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" dependencies = [ "bytes", "itoa", @@ -1505,7 +1506,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.4.1", + "http 1.4.2", ] [[package]] @@ -1516,7 +1517,7 @@ checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" dependencies = [ "bytes", "futures-core", - "http 1.4.1", + "http 1.4.2", "http-body", "pin-project-lite", ] @@ -1535,9 +1536,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hybrid-array" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da" +checksum = "818356c5132c1fede50f837ca96afbe78ff42413047f4abb886217845e1b6c8c" dependencies = [ "typenum", ] @@ -1552,8 +1553,8 @@ dependencies = [ "bytes", "futures-channel", "futures-core", - "h2 0.4.14", - "http 1.4.1", + "h2 0.4.15", + "http 1.4.2", "http-body", "httparse", "itoa", @@ -1569,7 +1570,7 @@ version = "0.27.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" dependencies = [ - "http 1.4.1", + "http 1.4.2", "hyper", "hyper-util", "rustls", @@ -1588,7 +1589,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.4.1", + "http 1.4.2", "http-body", "hyper", "ipnet", @@ -1685,12 +1686,6 @@ 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" @@ -1718,6 +1713,12 @@ 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" @@ -1726,8 +1727,6 @@ checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", "hashbrown 0.17.1", - "serde", - "serde_core", ] [[package]] @@ -1832,13 +1831,12 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.99" +version = "0.3.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" dependencies = [ "cfg-if", "futures-util", - "once_cell", "wasm-bindgen", ] @@ -1872,12 +1870,6 @@ 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" @@ -1902,7 +1894,7 @@ version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f02ab6bace2054fb888a3c16f990117b579d14a3088e472d63c6011fa185c9d3" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", "libc", "plain", "redox_syscall 0.8.1", @@ -1964,9 +1956,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.31" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "113b30b4cd05f7c06868fdb2854f66a7b9fece9a48425351cd532e810d74024f" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" dependencies = [ "value-bag", ] @@ -1999,9 +1991,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.8.1" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" +checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" [[package]] name = "mime" @@ -2037,6 +2029,76 @@ 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" @@ -2138,6 +2200,7 @@ dependencies = [ "hex", "hkdf", "json", + "mtp", "once_cell", "rand 0.8.6", "rand_core 0.6.4", @@ -2146,12 +2209,10 @@ dependencies = [ "rustls-pemfile", "sha2 0.10.9", "sqlx", - "strum 0.27.2", - "strum_macros 0.27.2", + "strum", + "strum_macros", "thiserror", "tokio", - "ttp-core", - "ttp-native", "uuid", "x448", "zip", @@ -2367,16 +2428,6 @@ 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" @@ -2388,9 +2439,9 @@ dependencies = [ [[package]] name = "quinn" -version = "0.11.9" +version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" dependencies = [ "bytes", "cfg_aliases", @@ -2408,9 +2459,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e" dependencies = [ "aws-lc-rs", "bytes", @@ -2444,9 +2495,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.45" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" dependencies = [ "proc-macro2", ] @@ -2491,7 +2542,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", - "getrandom 0.4.2", + "getrandom 0.4.3", "rand_core 0.10.1", ] @@ -2564,7 +2615,7 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", ] [[package]] @@ -2573,14 +2624,14 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b44b894f2a6e36457d665d1e08c3866add6ed5e70050c1b4ba8a8ddedb02ce7" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", ] [[package]] name = "regex" -version = "1.12.3" +version = "1.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" dependencies = [ "aho-corasick", "memchr", @@ -2607,9 +2658,9 @@ checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" [[package]] name = "regex-syntax" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "reqwest" @@ -2621,8 +2672,8 @@ dependencies = [ "bytes", "encoding_rs", "futures-core", - "h2 0.4.14", - "http 1.4.1", + "h2 0.4.15", + "http 1.4.2", "http-body", "http-body-util", "hyper", @@ -2727,7 +2778,7 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", "errno", "libc", "linux-raw-sys 0.12.1", @@ -2736,9 +2787,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.40" +version = "0.23.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" +checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f" dependencies = [ "aws-lc-rs", "log", @@ -2862,7 +2913,7 @@ version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", "core-foundation 0.10.1", "core-foundation-sys", "libc", @@ -2940,6 +2991,19 @@ 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" @@ -3040,9 +3104,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.15.1" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" dependencies = [ "serde", ] @@ -3189,7 +3253,7 @@ checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" dependencies = [ "atoi", "base64", - "bitflags 2.12.1", + "bitflags 2.13.0", "byteorder", "bytes", "crc", @@ -3231,7 +3295,7 @@ checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" dependencies = [ "atoi", "base64", - "bitflags 2.12.1", + "bitflags 2.13.0", "byteorder", "crc", "dotenvy", @@ -3307,12 +3371,6 @@ 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" @@ -3325,18 +3383,6 @@ 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" @@ -3345,9 +3391,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.117" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -3380,7 +3426,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", "core-foundation 0.9.4", "system-configuration-sys", ] @@ -3417,12 +3463,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.47" +version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +checksum = "85c17d80feb7334b40c484e45ed1a5273dfd8bfda537c3be2e74a06a6686f327" dependencies = [ "deranged", - "itoa", "num-conv", "powerfmt", "serde_core", @@ -3432,15 +3477,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" [[package]] name = "time-macros" -version = "0.2.27" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +checksum = "dcef1a61bdb119096e153208ec5cbec23944ce8bca13be5c7f60c634f7403935" dependencies = [ "num-conv", "time-core", @@ -3543,10 +3588,10 @@ version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" dependencies = [ - "bitflags 2.12.1", + "bitflags 2.13.0", "bytes", "futures-util", - "http 1.4.1", + "http 1.4.2", "http-body", "pin-project-lite", "tower", @@ -3605,33 +3650,6 @@ 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" @@ -3687,6 +3705,12 @@ 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" @@ -3719,11 +3743,11 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.23.2" +version = "1.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7" +checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53" dependencies = [ - "getrandom 0.4.2", + "getrandom 0.4.3", "js-sys", "wasm-bindgen", ] @@ -3779,20 +3803,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.3+wasi-0.2.9" +version = "1.0.4+wasi-0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" dependencies = [ - "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", + "wit-bindgen", ] [[package]] @@ -3803,9 +3818,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.122" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" dependencies = [ "cfg-if", "once_cell", @@ -3816,9 +3831,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.72" +version = "0.4.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" +checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d" dependencies = [ "js-sys", "wasm-bindgen", @@ -3826,9 +3841,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.122" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3836,9 +3851,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.122" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" dependencies = [ "bumpalo", "proc-macro2", @@ -3849,52 +3864,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.122" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" dependencies = [ "unicode-ident", ] -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -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" +version = "0.3.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436" +checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141" dependencies = [ "js-sys", "wasm-bindgen", @@ -3912,9 +3893,9 @@ dependencies = [ [[package]] name = "webpki-root-certs" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31141ce3fc3e300ae89b78c0dd67f9708061d1d2eda54b8209346fd6be9a92c" +checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267" dependencies = [ "rustls-pki-types", ] @@ -4217,100 +4198,12 @@ 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" @@ -4394,9 +4287,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -4417,18 +4310,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.50" +version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" +checksum = "ce1022995ff5ff5d841ad7d994facc23098cd40152f2c1d11cd607c6f530653f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.50" +version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" +checksum = "1ae7f38b72ec2a254e2b87ef277cf2cd4fb97cbebf944faa6f33354da0867930" dependencies = [ "proc-macro2", "quote", @@ -4458,18 +4351,18 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.8.2" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" dependencies = [ "proc-macro2", "quote", @@ -4538,9 +4431,9 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513" +checksum = "977347db8caa080403f6b6b7c1cda9479a8e869316f7e13a59b19076a40f94e3" [[package]] name = "zmij" diff --git a/Cargo.toml b/Cargo.toml index 22ec471..5d4e97e 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -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" } +mtp = { git = "https://git.methanium.net/methanium/mtp", features = ["host"] } 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 c57c26d..8195988 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,7 +20,8 @@ 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 = ttp_native::host( + let mut host: Host = host( + IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port, cert_pem, key_pem, @@ -59,45 +60,41 @@ async fn handle_connection(sender: Sender, receiver: &mut Receiver) { let sender = Arc::new(sender); while let Ok(cv) = receiver.receive().await { - 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(), - }); + 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(), + }); - 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"); - } - } - } - CommunicationType::ping => { let response = - CommunicationValue::new(CommunicationType::pong).with_id(cv.get_id()); - if let Err(_) = sender.send(&response).await { - break; + 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; + } } } @@ -116,8 +113,8 @@ pub async fn send_notification(user_id: i64, sender_id: i64) { }; if let Some(conns) = conns_opt { - let cv = CommunicationValue::new(CommunicationType::push_notification) - .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); + let cv = CommunicationValue::new(CommunicationType::PushNotification) + .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id as i128)); let mut remove_needed = false; for conn in conns.iter() { @@ -141,8 +138,8 @@ pub async fn remove_notification(user_id: i64, sender_id: i64) { }; if let Some(conns) = conns_opt { - let cv = CommunicationValue::new(CommunicationType::read_notification) - .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); + let cv = CommunicationValue::new(CommunicationType::ReadNotification) + .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id as i128)); let mut remove_needed = false; for conn in conns.iter() { diff --git a/src/server/server.rs b/src/server/server.rs index 3c7fc05..c367679 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"http/1.1".to_vec()]; + config.alpn_protocols = vec![b"h2".to_vec(), b"hmtp/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 c0ab51d..b3f91bd 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!( - "https://omega.tensamin.net/direct/{}", + "hmtps://omega.tensamin.net/direct/{}", format_with_dashes(&raw) )) } diff --git a/src/transport/omikron_connection.rs b/src/transport/omikron_connection.rs index 93804fd..cc53520 100644 --- a/src/transport/omikron_connection.rs +++ b/src/transport/omikron_connection.rs @@ -11,6 +11,9 @@ 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, @@ -20,8 +23,6 @@ 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; // ============================================================================ @@ -92,7 +93,7 @@ impl AuthState { } // ============================================================================ -// Omikron Connection (ttp/QUIC-based) +// Omikron Connection (mtp/QUIC-based) // ============================================================================ pub struct OmikronConnection { @@ -180,7 +181,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); } @@ -193,7 +194,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; } @@ -213,22 +214,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::error_not_authenticated) + .send_error_response(cv.get_id(), CommunicationType::ErrorNotAuthenticated) .await; return Err(OmikronError::NotAuthenticated); } // Extract omikron ID let omikron_id = cv - .get_data(DataTypes::omikron_id) + .get_data(DataType::OmikronId) .as_number() .ok_or(OmikronError::InvalidResponse)?; log!("Omikron {:?} connected", omikron_id); // Lookup omikron in database - let (public_key, _) = get_omikron_by_id(omikron_id) + let (public_key, _) = get_omikron_by_id(omikron_id as i64) .await .map_err(|e| OmikronError::Sql(e.to_string()))?; @@ -261,7 +262,9 @@ impl OmikronConnection { log!("Stored Pubkey"); - *self.state.write().await = AuthState::Identified { omikron_id }; + *self.state.write().await = AuthState::Identified { + omikron_id: omikron_id as i64, + }; log!("Stored State"); @@ -279,28 +282,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_data( - DataTypes::public_key, + .add_typed_default( + DataType::PublicKey, DataValue::Str(STANDARD.encode(get_public_key().as_bytes())), ) - .add_data(DataTypes::challenge, DataValue::Str(encrypted)); + .add_typed_default(DataType::Content, DataValue::Str(encrypted)); log!("Sending Challenge"); self.send(&response).await } async fn handle_identified(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - if !cv.is_type(CommunicationType::challenge_response) { + if !cv.is_type(CommunicationType::ChallengeResponse) { let _ = self - .send_error_response(cv.get_id(), CommunicationType::error_not_authenticated) + .send_error_response(cv.get_id(), CommunicationType::ErrorNotAuthenticated) .await; return Err(OmikronError::NotAuthenticated); } let client_response = cv - .get_data(DataTypes::challenge) + .get_data(DataType::Content) .as_str() .ok_or(OmikronError::InvalidResponse)?; @@ -312,16 +315,16 @@ impl OmikronConnection { omikron_manager::add_omikron(self.clone()).await; - let response = CommunicationValue::new(CommunicationType::identification_response) + let response = CommunicationValue::new(CommunicationType::IdentificationResponse) .with_id(cv.get_id()) - .add_data(DataTypes::accepted, DataValue::Bool(true)); + .add_typed_default(DataType::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::error_invalid_challenge) + .send_error_response(cv.get_id(), CommunicationType::ErrorInvalidChallenge) .await; Err(OmikronError::AuthenticationFailed) } @@ -336,52 +339,53 @@ impl OmikronConnection { cv: CommunicationValue, omikron_id: i64, ) -> OmikronResult<()> { - match cv.get_type() { + let comm_type = cv.get_comm_type_enum(); + match comm_type { // Link shortening - CommunicationType::shorten_link => self.handle_shorten_link(cv).await, + Some(CommunicationType::ShortenLink) => self.handle_shorten_link(cv).await, // Online status tracking - CommunicationType::user_connected => { + Some(CommunicationType::UserConnected) => { self.handle_user_connected(cv, omikron_id).await; Ok(()) } - CommunicationType::user_disconnected => { + Some(CommunicationType::UserDisconnected) => { self.handle_user_disconnected(cv, omikron_id).await; Ok(()) } - CommunicationType::iota_connected => { + Some(CommunicationType::IotaConnected) => { self.handle_iota_connected(cv, omikron_id).await; Ok(()) } - CommunicationType::iota_disconnected => { + Some(CommunicationType::IotaDisconnected) => { self.handle_iota_disconnected(cv, omikron_id).await; Ok(()) } - CommunicationType::sync_client_iota_status => { + Some(CommunicationType::SyncClientIotaStatus) => { self.handle_sync_status(cv, omikron_id).await; Ok(()) } - CommunicationType::get_user_data => self.handle_get_user_data(cv).await, - CommunicationType::get_iota_data => self.handle_get_iota_data(cv).await, + Some(CommunicationType::GetUserData) => self.handle_get_user_data(cv).await, + Some(CommunicationType::GetIotaData) => self.handle_get_iota_data(cv).await, - CommunicationType::get_register => self.handle_get_register(cv).await, - CommunicationType::complete_register_iota => { + Some(CommunicationType::GetRegister) => self.handle_get_register(cv).await, + Some(CommunicationType::CompleteRegisterIota) => { self.handle_complete_register_iota(cv).await } - CommunicationType::complete_register_user => { + Some(CommunicationType::CompleteRegisterUser) => { self.handle_complete_register_user(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::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::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, + 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, _ => { log_err!( @@ -401,7 +405,7 @@ impl OmikronConnection { async fn handle_shorten_link(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { let link = cv - .get_data(DataTypes::link) + .get_data(DataType::Link) .as_str() .ok_or(OmikronError::InvalidResponse)?; @@ -409,32 +413,28 @@ impl OmikronConnection { .await .map_err(|_| OmikronError::Sql("Shortend link Error".to_string()))?; - let response = CommunicationValue::new(CommunicationType::shorten_link) + let response = CommunicationValue::new(CommunicationType::ShortenLink) .with_id(cv.get_id()) - .add_data(DataTypes::link, DataValue::Str(short)); + .add_typed_default(DataType::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(DataTypes::user_id).as_number() { + if let Some(user_id) = cv.get_data(DataType::UserId).as_number() { let status = cv - .get_data(DataTypes::user_state) + .get_data(DataType::UserState) .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(DataTypes::user_id).as_number() { + if let Some(user_id) = cv.get_data(DataType::UserId).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(DataTypes::iota_id).as_number() { + let iota_id = match cv.get_data(DataType::IotaId).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::Number(user_id.try_into().unwrap())); + user_ids.push(DataValue::SignedNumber(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::iota_user_data) + let response = CommunicationValue::new(CommunicationType::IotaUserData) .with_id(cv.get_id()) - .add_data(DataTypes::user_ids, DataValue::Array(user_ids)); + .add_typed_default(DataType::UserIds, 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(DataTypes::iota_id).as_number() { + let iota_id = match cv.get_data(DataType::IotaId).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(DataTypes::user_ids) { + if let DataValue::Array(user_ids) = cv.get_data(DataType::UserIds) { for user_id_val in user_ids { - if let DataValue::Number(user_id) = user_id_val { + if let DataValue::SignedNumber(user_id) = user_id_val { user_online_tracker::track_user_status( - *user_id, + *user_id as i64, UserStatus::user_offline, omikron_id, ); @@ -502,10 +502,10 @@ impl OmikronConnection { } } - if let DataValue::Array(iota_ids) = cv.get_data(DataTypes::iota_ids) { + if let DataValue::Array(iota_ids) = cv.get_data(DataType::IotaIds) { for iota_id_val in iota_ids { - if let DataValue::Number(iota_id) = iota_id_val { - user_online_tracker::track_iota_connection(*iota_id, omikron_id, true); + if let DataValue::SignedNumber(iota_id) = iota_id_val { + user_online_tracker::track_iota_connection(*iota_id as i64, 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(DataTypes::user_id).as_number() { + if let Some(user_id) = cv.get_data(DataType::UserId).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(DataTypes::username).as_str() { + if let Some(username) = cv.get_data(DataType::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::error_not_found).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::ErrorNotFound).with_id(cv.get_id()); self.send(&response).await } @@ -573,28 +573,28 @@ impl OmikronConnection { _, ) = user; - let mut response = CommunicationValue::new(CommunicationType::get_user_data) + let mut response = CommunicationValue::new(CommunicationType::GetUserData) .with_id(msg_id) - .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)); + .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())); // Display name (fallback to username) let display_name = display.filter(|d| !d.is_empty()).unwrap_or(username); - response = response.add_data(DataTypes::display, DataValue::Str(display_name)); + response = response.add_typed_default(DataType::Display, DataValue::Str(display_name)); // Optional fields if let Some(s) = status.filter(|s| !s.is_empty()) { - response = response.add_data(DataTypes::status, DataValue::Str(s)); + response = response.add_typed_default(DataType::Status, DataValue::Str(s)); } if let Some(a) = about.filter(|a| !a.is_empty()) { - response = response.add_data(DataTypes::about, DataValue::Str(a)); + response = response.add_typed_default(DataType::About, DataValue::Str(a)); } if let Some(av) = avatar { - response = response.add_data(DataTypes::avatar, DataValue::Str(STANDARD.encode(av))); + response = response.add_typed_default(DataType::Avatar, DataValue::Str(STANDARD.encode(av))); } // Online status @@ -608,24 +608,24 @@ impl OmikronConnection { } else { us.connection_type.clone() }; - response = response.add_data( - DataTypes::online_status, + response = response.add_typed_default( + DataType::OnlineStatus, DataValue::Str(display_status.to_string()), ); - response = response.add_data(DataTypes::omikron_id, DataValue::Number(us.omikron_id)); + response = response.add_typed_default(DataType::OmikronId, DataValue::SignedNumber(us.omikron_id.into())); } else { - response = response.add_data( - DataTypes::online_status, + response = response.add_typed_default( + DataType::OnlineStatus, DataValue::Str(UserStatus::iota_offline.to_string()), ); } - response = response.add_data( - DataTypes::omikron_connections, + response = response.add_typed_default( + DataType::OmikronConnections, DataValue::Array( iota_connections .into_iter() - .map(DataValue::Number) + .map(|id| DataValue::SignedNumber(id as i128)) .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(DataTypes::iota_id).as_number() { + if let Some(iota_id) = cv.get_data(DataType::IotaId).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(DataTypes::user_id).as_number() { + if let Some(user_id) = cv.get_data(DataType::UserId).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(DataTypes::username).as_str() { + if let Some(username) = cv.get_data(DataType::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::error_not_found).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::ErrorNotFound).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::get_iota_data) + let mut response = CommunicationValue::new(CommunicationType::GetIotaData) .with_id(msg_id) - .add_data(DataTypes::public_key, DataValue::Str(public_key)) - .add_data(DataTypes::iota_id, DataValue::Number(iota_id)); + .add_typed_default(DataType::PublicKey, DataValue::Str(public_key)) + .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())); if let Some(uid) = user_id { - response = response.add_data(DataTypes::user_id, DataValue::Number(uid)); + response = response.add_typed_default(DataType::UserId, DataValue::SignedNumber(uid.into())); } if let Some(uname) = username { - response = response.add_data(DataTypes::username, DataValue::Str(uname)); + response = response.add_typed_default(DataType::Username, DataValue::Str(uname)); } let iota_connections = user_online_tracker::get_iota_omikron_connections(iota_id).unwrap_or_default(); - response.add_data( - DataTypes::omikron_connections, + response.add_typed_default( + DataType::OmikronConnections, DataValue::Array( iota_connections .into_iter() - .map(DataValue::Number) + .map(|id| DataValue::SignedNumber(id as i128)) .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::get_register) + let response = CommunicationValue::new(CommunicationType::GetRegister) .with_id(cv.get_id()) - .add_data(DataTypes::user_id, DataValue::Number(register_id as i64)); + .add_typed_default(DataType::UserId, DataValue::SignedNumber(register_id as i128)); self.send(&response).await } @@ -738,24 +738,21 @@ impl OmikronConnection { self: Arc, cv: CommunicationValue, ) -> OmikronResult<()> { - let iota_id_opt = cv - .get_data(DataTypes::iota_id) - .as_number() - .map(|n| n as i64); + let iota_id_opt = cv.get_data(DataType::IotaId).as_number().map(|n| n as i64); - if let Some(public_key) = cv.get_data(DataTypes::public_key).as_str() { + if let Some(public_key) = cv.get_data(DataType::PublicKey).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::error_internal) + let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); + .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); self.send(&response).await } } @@ -764,21 +761,21 @@ impl OmikronConnection { match sql::create_new_iota(public_key.to_string()).await { Ok(new_iota_id) => { let response = - CommunicationValue::new(CommunicationType::complete_register_iota) + CommunicationValue::new(CommunicationType::CompleteRegisterIota) .with_id(cv.get_id()) - .add_data(DataTypes::iota_id, DataValue::Number(new_iota_id)); + .add_typed_default(DataType::IotaId, DataValue::SignedNumber(new_iota_id.into())); self.send(&response).await } Err(e) => { - let response = CommunicationValue::new(CommunicationType::error_internal) + let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); + .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); self.send(&response).await } } } } else { - self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data) + self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidData) .await } } @@ -787,21 +784,18 @@ impl OmikronConnection { self: Arc, cv: CommunicationValue, ) -> OmikronResult<()> { - let user_id = cv - .get_data(DataTypes::user_id) - .as_number() - .map(|n| n as i64); + let user_id = cv.get_data(DataType::UserId).as_number().map(|n| n as i64); let username = cv - .get_data(DataTypes::username) + .get_data(DataType::Username) .as_str() .map(|s| s.to_string()); let public_key = cv - .get_data(DataTypes::public_key) + .get_data(DataType::PublicKey) .as_str() .map(|s| s.to_string()); let iota_id = cv.get_sender(); let reset_token = cv - .get_data(DataTypes::reset_token) + .get_data(DataType::ResetToken) .as_str() .map(|s| s.to_string()); @@ -811,18 +805,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::error_internal) + let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); + .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); self.send(&response).await } } } else { - self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data) + self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidData) .await } } @@ -833,39 +827,39 @@ impl OmikronConnection { let mut error_message = String::new(); // Process each field - if let Some(username) = cv.get_data(DataTypes::username).as_str() { + if let Some(username) = cv.get_data(DataType::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(DataTypes::display).as_str() { + if let Some(display) = cv.get_data(DataType::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(DataTypes::avatar).as_str() { + if let Some(avatar) = cv.get_data(DataType::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(DataTypes::about).as_str() { + if let Some(about) = cv.get_data(DataType::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(DataTypes::status).as_str() { + if let Some(status) = cv.get_data(DataType::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(DataTypes::public_key).as_str(), - cv.get_data(DataTypes::private_key_hash).as_str(), + cv.get_data(DataType::PublicKey).as_str(), + cv.get_data(DataType::PrivateKeyHash).as_str(), ) { if let Err(e) = sql::change_keys( user_id, @@ -880,12 +874,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::error_internal) + let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(error_message)); + .add_typed_default(DataType::ErrorType, DataValue::Str(error_message)); self.send(&response).await } } @@ -895,8 +889,8 @@ impl OmikronConnection { if let (iota_id, Some(reset_token), Some(new_token)) = ( cv.get_sender(), - cv.get_data(DataTypes::reset_token).as_str(), - cv.get_data(DataTypes::new_token).as_str(), + cv.get_data(DataType::ResetToken).as_str(), + cv.get_data(DataType::NewToken).as_str(), ) { match sql::get_by_user_id(user_id).await { Ok(user) => { @@ -918,31 +912,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::error_internal) + CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(error_message)); + .add_typed_default(DataType::ErrorType, DataValue::Str(error_message)); self.send(&response).await } } else { self.send_error_response( cv.get_id(), - CommunicationType::error_invalid_challenge, + CommunicationType::ErrorInvalidChallenge, ) .await } } Err(_) => { - self.send_error_response(cv.get_id(), CommunicationType::error_not_found) + self.send_error_response(cv.get_id(), CommunicationType::ErrorNotFound) .await } } } else { - self.send_error_response(cv.get_id(), CommunicationType::error_invalid_data) + self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidData) .await } } @@ -952,13 +946,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::error_internal) + let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); + .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); self.send(&response).await } } @@ -969,13 +963,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::error_internal) + let response = CommunicationValue::new(CommunicationType::ErrorInternal) .with_id(cv.get_id()) - .add_data(DataTypes::error_type, DataValue::Str(e.to_string())); + .add_typed_default(DataType::ErrorType, DataValue::Str(e.to_string())); self.send(&response).await } } @@ -990,9 +984,10 @@ impl OmikronConnection { Ok(notifications) => notifications .into_iter() .map(|(sender, amount)| { + let tm = mtp::type_map::TypeMap::latest(); DataValue::Container(vec![ - (DataTypes::sender_id, DataValue::Number(sender)), - (DataTypes::amount, DataValue::Number(amount)), + (DataType::SenderId.to_id(&tm), DataValue::SignedNumber(sender.into())), + (DataType::Amount.to_id(&tm), DataValue::SignedNumber(amount.into())), ]) }) .collect(), @@ -1002,9 +997,9 @@ impl OmikronConnection { } }; - let response = CommunicationValue::new(CommunicationType::get_notifications) + let response = CommunicationValue::new(CommunicationType::GetNotifications) .with_id(cv.get_id()) - .add_data(DataTypes::notifications, DataValue::Array(response_array)); + .add_typed_default(DataType::Notifications, DataValue::Array(response_array)); self.send(&response).await } @@ -1014,21 +1009,21 @@ impl OmikronConnection { ) -> OmikronResult<()> { let receiver_id = match cv.get_sender() { s if s > 0 => s as i64, - _ => match cv.get_data(DataTypes::receiver_id).as_number() { + _ => match cv.get_data(DataType::ReceiverId).as_number() { Some(id) => id as i64, None => return Ok(()), }, }; if let Some(other_id) = cv - .get_data(DataTypes::sender_id) + .get_data(DataType::SenderId) .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::read_notification) + let response = CommunicationValue::new(CommunicationType::ReadNotification) .with_id(cv.get_id()); let _ = self.send(&response).await; @@ -1036,9 +1031,9 @@ impl OmikronConnection { crate::notifications::tauri::remove_notification(receiver_id, other_id).await; // Sync with other Omikron clients - let sync_cv = CommunicationValue::new(CommunicationType::read_notification) + let sync_cv = CommunicationValue::new(CommunicationType::ReadNotification) .with_receiver(receiver_id as u64) - .add_data(DataTypes::sender_id, DataValue::Number(other_id)); + .add_typed_default(DataType::SenderId, DataValue::SignedNumber(other_id.into())); crate::transport::omikron_manager::send_to_user(receiver_id, &sync_cv).await; } } @@ -1051,13 +1046,13 @@ impl OmikronConnection { ) -> OmikronResult<()> { let receiver_id = match cv.get_receiver() { r if r > 0 => r as i64, - _ => match cv.get_data(DataTypes::receiver_id).as_number() { + _ => match cv.get_data(DataType::ReceiverId).as_number() { Some(id) => id as i64, None => return Ok(()), }, }; - let sender_id = match cv.get_data(DataTypes::sender_id).as_number() { + let sender_id = match cv.get_data(DataType::SenderId).as_number() { Some(id) => id as i64, None => cv.get_sender() as i64, }; @@ -1066,31 +1061,31 @@ impl OmikronConnection { log!(PrintType::General, "SQL add_notification error: {}", e); } else { let response = - CommunicationValue::new(CommunicationType::push_notification).with_id(cv.get_id()); + CommunicationValue::new(CommunicationType::PushNotification).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::push_notification) + let push_cv = CommunicationValue::new(CommunicationType::PushNotification) .with_receiver(receiver_id as u64) - .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); + .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id.into())); 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(DataTypes::user_ids) { + let user_ids = match cv.get_data(DataType::UserIds) { DataValue::Array(ids) => ids, _ => return Ok(()), }; let mut states = Vec::new(); for id_val in user_ids { - if let DataValue::Number(user_id) = id_val { - let user_id = *user_id; + if let DataValue::SignedNumber(user_id) = id_val { + let user_id = *user_id as i64; let status = user_online_tracker::get_user_status(user_id); let status_str = match status { Some(ref us) => { @@ -1102,25 +1097,26 @@ impl OmikronConnection { } None => UserStatus::iota_offline.to_string(), }; + let tm = mtp::type_map::TypeMap::latest(); let mut map = Vec::new(); - map.push((DataTypes::user_id, DataValue::Number(user_id))); - map.push((DataTypes::user_state, DataValue::Str(status_str))); + map.push((DataType::UserId.to_id(&tm), DataValue::SignedNumber(user_id.into()))); + map.push((DataType::UserState.to_id(&tm), DataValue::Str(status_str))); states.push(DataValue::Container(map)); } } - let response = CommunicationValue::new(CommunicationType::get_states) + let response = CommunicationValue::new(CommunicationType::GetStates) .with_id(cv.get_id()) - .add_data(DataTypes::user_states, DataValue::Array(states)); + .add_typed_default(DataType::UserStates, DataValue::Array(states)); self.send(&response).await } async fn handle_ping(self: Arc, cv: CommunicationValue) -> OmikronResult<()> { - if let DataValue::Number(last_ping) = cv.get_data(DataTypes::last_ping) { - *self.ping.write().await = *last_ping; + if let DataValue::SignedNumber(last_ping) = cv.get_data(DataType::LastPing) { + *self.ping.write().await = *last_ping as i64; } - 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 } @@ -1129,7 +1125,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); } @@ -1196,7 +1192,8 @@ 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 = ttp_native::host( + let mut host: Host = host( + IpAddr::from(Ipv4Addr::new(0, 0, 0, 0)), port, cert_pem, key_pem, diff --git a/src/transport/omikron_manager.rs b/src/transport/omikron_manager.rs index 70c73cd..f98a75c 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 845489f..31606b6 100644 --- a/src/util/logger.rs +++ b/src/util/logger.rs @@ -1,5 +1,4 @@ use std::{ - collections::BTreeMap, fs::{self, OpenOptions}, io::Write, path::Path, @@ -9,7 +8,7 @@ use std::{ }; use ansi_term::Color; -use ttp_core::{CommunicationValue, DataTypes, DataValue}; +use mtp::codec::{CommunicationValue, DataTypeId, DataValue, Version}; use crate::util::file_util::get_directory; @@ -248,17 +247,19 @@ pub fn format_cv(cv: &CommunicationValue) -> String { let comm_type = cv.get_type().to_string(); parts.push(format!("{}", comm_type)); - let data: &BTreeMap = cv.get_data_container(); + let data = cv.data(); - let formated_data = - format_data_container(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); + let formated_data = format_data_container( + data.iter().map(|(k, v)| (*k, v.clone())).collect(), + Version(1, 0), + ); parts.push(format!("{}", formated_data)); parts.join(": ") } -fn format_data_container(data: Vec<(DataTypes, DataValue)>) -> String { +fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) -> String { let parts: Vec = data .into_iter() .map(|(key, value)| { @@ -268,12 +269,13 @@ fn format_data_container(data: Vec<(DataTypes, DataValue)>) -> String { DataValue::Str(s) => format!("{}=\"{}\"", key_str, s), DataValue::Container(inner) => { - let inner_formatted = format_data_container(inner); + let inner_formatted = + format_data_container(inner, version.clone()); format!("{}={{ {} }}", key_str, inner_formatted) } DataValue::Array(arr) => { - let arr_formatted = format_array(arr); + let arr_formatted = format_array(arr, version.clone()); format!("{}=[{}]", key_str, arr_formatted) } @@ -282,7 +284,7 @@ fn format_data_container(data: Vec<(DataTypes, DataValue)>) -> String { DataValue::BoolTrue => format!("{}=true", key_str), DataValue::BoolFalse => format!("{}=false", key_str), - DataValue::Number(num) => format!("{}={}", key_str, num), + DataValue::SignedNumber(num) => format!("{}={}", key_str, num), _ => "".to_string(), } @@ -292,19 +294,19 @@ fn format_data_container(data: Vec<(DataTypes, DataValue)>) -> String { parts.join(", ") } -fn format_array(arr: Vec) -> String { +fn format_array(arr: Vec, version: Version) -> 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); + let inner_formatted = format_data_container(inner, version.clone()); format!("{{ {} }}", inner_formatted) } DataValue::Array(inner_arr) => { - let formatted = format_array(inner_arr); + let formatted = format_array(inner_arr, version.clone()); format!("[{}]", formatted) } @@ -313,7 +315,7 @@ fn format_array(arr: Vec) -> String { DataValue::BoolTrue => "true".to_string(), DataValue::BoolFalse => "false".to_string(), - DataValue::Number(num) => num.to_string(), + DataValue::SignedNumber(num) => num.to_string(), _ => String::new(), }) diff --git a/type-maps.yaml b/type-maps.yaml new file mode 100644 index 0000000..73a15e3 --- /dev/null +++ b/type-maps.yaml @@ -0,0 +1,240 @@ +# 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