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 6567e4d..c3f935a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,9 +66,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 = "asn1-rs" @@ -298,6 +298,12 @@ dependencies = [ "fs_extra", ] +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.21.7" @@ -310,6 +316,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bit-vec" version = "0.9.1" @@ -321,9 +333,9 @@ dependencies = [ [[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" [[package]] name = "block-buffer" @@ -336,9 +348,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", ] @@ -379,15 +391,15 @@ 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 = "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", @@ -415,9 +427,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.45" +version = "0.4.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" dependencies = [ "num-traits", ] @@ -466,6 +478,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-oid" version = "0.10.2" @@ -536,6 +554,18 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -574,6 +604,33 @@ dependencies = [ "cmov", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto 0.2.9", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dashmap" version = "6.2.1" @@ -594,6 +651,17 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid 0.9.6", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "der-parser" version = "10.0.0" @@ -613,6 +681,9 @@ name = "deranged" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] [[package]] name = "device-info" @@ -636,6 +707,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", + "const-oid 0.9.6", "crypto-common 0.1.7", "subtle", ] @@ -646,8 +718,8 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer 0.12.1", - "const-oid", + "block-buffer 0.12.0", + "const-oid 0.10.2", "crypto-common 0.2.2", "ctutils", ] @@ -685,13 +757,51 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2 0.10.9", + "subtle", + "zeroize", +] + [[package]] name = "ed448-goldilocks" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87b5fa9e9e3dd5fe1369f380acd3dcdfa766dbd0a1cd5b048fb40e38a6a78e79" dependencies = [ - "fiat-crypto", + "fiat-crypto 0.1.20", "hex", "subtle", ] @@ -702,6 +812,27 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "hkdf 0.12.4", + "pem-rfc7468", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "enum-as-inner" version = "0.6.1" @@ -763,12 +894,28 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fiat-crypto" version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -781,6 +928,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -920,6 +1073,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -951,13 +1105,15 @@ 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", + "wasip2", + "wasip3", ] [[package]] @@ -982,12 +1138,32 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.17.1" @@ -1064,6 +1240,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac 0.12.1", +] + [[package]] name = "hkdf" version = "0.13.0" @@ -1099,9 +1284,9 @@ checksum = "1a9fcbcc408c5526c3ab80d534e5c86e7967c1fb7aa0a8c76abd1edc27deb877" [[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", @@ -1138,9 +1323,9 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[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", ] @@ -1286,6 +1471,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" @@ -1315,6 +1506,8 @@ checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", "hashbrown 0.17.1", + "serde", + "serde_core", ] [[package]] @@ -1425,12 +1618,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", ] @@ -1447,10 +1641,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eba32bfb4ffdeaca3e34431072faf01745c9b26d25504aa7a6cf5684334fc4fc" dependencies = [ "base64 0.22.1", + "ed25519-dalek", "getrandom 0.2.17", + "hmac 0.12.1", "js-sys", + "p256", + "p384", + "rand 0.8.6", + "rsa", "serde", "serde_json", + "sha2 0.10.9", "signature", "zeroize", ] @@ -1469,6 +1670,15 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" @@ -1476,6 +1686,12 @@ version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -1490,14 +1706,13 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "livekit-api" -version = "0.5.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2150a76435ae6129101ab74e75d8fd0bc24fc57d71477f59c67fad9b0541d85" +checksum = "c53d6335323ed9e4fd0c3ede761478fc607d147c6e3f2c29dc71ca73bcf18723" dependencies = [ "async-tungstenite", "base64 0.21.7", "device-info", - "hmac 0.12.1", "http", "jsonwebtoken", "livekit-protocol", @@ -1512,7 +1727,6 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.9", - "signature", "thiserror 2.0.18", "tokio-tungstenite", "url", @@ -1520,9 +1734,9 @@ dependencies = [ [[package]] name = "livekit-protocol" -version = "0.7.9" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35609e3b2a077801c198f4f3de70f6cee4f2ba189d02b8876b99b96be43d0284" +checksum = "565d83442aa99684dba5d0841fa342eb572fbd916ba2aa5e92801ecf76620026" dependencies = [ "pbjson", "pbjson-types", @@ -1541,9 +1755,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", ] @@ -1556,9 +1770,9 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" [[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 = "minimal-lexical" @@ -1594,89 +1808,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "mtp" -version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -dependencies = [ - "mtp-client", - "mtp-codec", - "mtp-common", - "mtp-host", - "mtp-transport", - "mtp-type-map", -] - -[[package]] -name = "mtp-client" -version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -dependencies = [ - "mtp-codec", - "mtp-common", - "mtp-transport", - "rand 0.8.6", - "tokio", -] - -[[package]] -name = "mtp-codec" -version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -dependencies = [ - "base64 0.22.1", - "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.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -dependencies = [ - "quinn", - "rustls", - "thiserror 2.0.18", - "wtransport", -] - -[[package]] -name = "mtp-host" -version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -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.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -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.git#15cc1d4c5e6a917f197ebf6685c8cea4e3ab668f" -dependencies = [ - "serde", - "serde_yaml", -] - [[package]] name = "multimap" version = "0.10.1" @@ -1732,6 +1863,22 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.6", + "smallvec", + "zeroize", +] + [[package]] name = "num-conv" version = "0.2.2" @@ -1747,6 +1894,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1754,6 +1912,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -1942,12 +2101,11 @@ dependencies = [ "futures", "hex", "hickory-resolver", - "hkdf", + "hkdf 0.13.0", "json", "livekit-api", "livekit-protocol", "log", - "mtp", "once_cell", "rand 0.8.6", "rand_core 0.6.4", @@ -1959,6 +2117,8 @@ dependencies = [ "strum_macros", "thiserror 2.0.18", "tokio", + "ttp-core", + "ttp-native", "uuid", "x448", ] @@ -1981,9 +2141,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.81" +version = "0.10.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45" +checksum = "a45fa2aa886c42762255da344f0a0d313e254066c46aad76f300c3d3da62d967" dependencies = [ "bitflags", "cfg-if", @@ -2012,9 +2172,9 @@ checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" [[package]] name = "openssl-sys" -version = "0.9.117" +version = "0.9.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695" +checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" dependencies = [ "cc", "libc", @@ -2038,6 +2198,30 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2 0.10.9", +] + +[[package]] +name = "p384" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe42f1670a52a47d448f14b6a5c61dd78fce51856e68edaa38f7ae3a46b8d6b6" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2 0.10.9", +] + [[package]] name = "parking" version = "2.2.1" @@ -2114,6 +2298,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.2" @@ -2153,6 +2346,27 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.33" @@ -2225,6 +2439,15 @@ dependencies = [ "syn", ] +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -2289,9 +2512,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", @@ -2309,9 +2532,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", @@ -2345,9 +2568,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", ] @@ -2453,9 +2676,9 @@ dependencies = [ [[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", @@ -2476,9 +2699,9 @@ dependencies = [ [[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" @@ -2522,6 +2745,16 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7" +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac 0.12.1", + "subtle", +] + [[package]] name = "ring" version = "0.17.14" @@ -2536,12 +2769,41 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid 0.9.6", + "digest 0.10.7", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustc-hash" version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rusticata-macros" version = "4.1.0" @@ -2566,9 +2828,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", @@ -2650,6 +2912,20 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "security-framework" version = "3.7.0" @@ -2673,6 +2949,12 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.228" @@ -2728,19 +3010,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" @@ -2796,6 +3065,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ + "digest 0.10.7", "rand_core 0.6.4", ] @@ -2807,9 +3077,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" [[package]] name = "socket2" @@ -2821,6 +3091,22 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -2853,9 +3139,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", @@ -2895,7 +3181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom 0.4.2", "once_cell", "rustix", "windows-sys 0.61.2", @@ -2943,11 +3229,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", @@ -2957,15 +3244,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", @@ -3130,6 +3417,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 0.22.1", + "byteorder", + "rand 0.8.6", + "serde_json", + "strum", + "strum_macros", +] + +[[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 2.0.18", + "tokio", + "ttp-core", + "wtransport", +] + [[package]] name = "tungstenite" version = "0.26.2" @@ -3179,6 +3493,12 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "universal-hash" version = "0.5.1" @@ -3189,12 +3509,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" @@ -3233,11 +3547,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", ] @@ -3287,18 +3601,27 @@ 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]] 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", @@ -3309,9 +3632,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", @@ -3319,9 +3642,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", @@ -3329,9 +3652,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", @@ -3342,18 +3665,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", + "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", @@ -3672,12 +4029,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 0.5.0", + "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 0.5.0", + "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", + "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" @@ -3761,9 +4206,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", @@ -3784,18 +4229,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", @@ -3825,18 +4270,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", diff --git a/Cargo.toml b/Cargo.toml index 665c0a6..d31b956 100644 --- 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.git", features = ["host", "client"] } +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" } ansi_term = "*" uuid = { version = "*", features = ["v4"] } diff --git a/src/anonymous_clients/anonymous_client_connection.rs b/src/anonymous_clients/anonymous_client_connection.rs index 39776a4..1378af9 100644 --- a/src/anonymous_clients/anonymous_client_connection.rs +++ b/src/anonymous_clients/anonymous_client_connection.rs @@ -1,9 +1,9 @@ -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue, TypeMap}; -use mtp::transport::{Receiver, Sender}; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; use tokio::sync::RwLock; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; +use ttp_native::{Receiver, Sender}; use uuid::Uuid; use crate::anonymous_clients::anonymous_manager::{self, generate_username}; @@ -88,7 +88,7 @@ impl AnonymousClientConnection { ); return; } - if !cv.is_type(CommunicationType::Pong) { + if !cv.is_type(CommunicationType::pong) { log_cv_out!(PrintType::Client, &cv); } if let Err(e) = self.sender.send(&cv).await { @@ -104,15 +104,16 @@ impl AnonymousClientConnection { /// Handle incoming message from client pub async fn handle_message(self: Arc, cv: CommunicationValue) { tokio::spawn(async move { - if cv.is_type(CommunicationType::Ping) { + if cv.is_type(CommunicationType::ping) { self.handle_ping(cv).await; return; } log_cv_in!(PrintType::Client, &cv); - if cv.is_type(CommunicationType::Identification) { - let call_id = Uuid::parse_str(cv.get_data(DataType::CallId).as_str().unwrap_or("")) - .unwrap_or(Uuid::new_v4()); + if cv.is_type(CommunicationType::identification) { + let call_id = + Uuid::parse_str(cv.get_data(DataTypes::call_id).as_str().unwrap_or("")) + .unwrap_or(Uuid::new_v4()); let call = if let Some(call) = call_manager::get_call(call_id).await { if call.is_anonymous().await { @@ -120,7 +121,7 @@ impl AnonymousClientConnection { } else { self.send_error_response( &cv.get_id(), - CommunicationType::ErrorNotAuthenticated, + CommunicationType::error_not_authenticated, ) .await; return; @@ -128,7 +129,7 @@ impl AnonymousClientConnection { } else { self.send_error_response( &cv.get_id(), - CommunicationType::ErrorNotAuthenticated, + CommunicationType::error_not_authenticated, ) .await; return; @@ -138,9 +139,9 @@ impl AnonymousClientConnection { for call_invitee in call.members.read().await.clone() { let call_invitee_cv = get_omega_connection() .await_response( - &CommunicationValue::new(CommunicationType::GetUserData).add_typed_default( - DataType::UserId, - DataValue::SignedNumber(call_invitee.user_id.into()), + &CommunicationValue::new(CommunicationType::get_user_data).add_data( + DataTypes::user_id, + DataValue::Number(call_invitee.user_id as i64), ), Some(Duration::from_secs(2)), ) @@ -148,122 +149,120 @@ impl AnonymousClientConnection { .unwrap(); let mut json_invitee = Vec::new(); let _ = json_invitee.push(( - DataType::UserId, - call_invitee_cv.get_data(DataType::UserId).clone(), + DataTypes::user_id, + call_invitee_cv.get_data(DataTypes::user_id).clone(), )); let _ = json_invitee.push(( - DataType::Username, - call_invitee_cv.get_data(DataType::Username).clone(), + DataTypes::username, + call_invitee_cv.get_data(DataTypes::username).clone(), )); let _ = json_invitee.push(( - DataType::Display, - call_invitee_cv.get_data(DataType::Display).clone(), + DataTypes::display, + call_invitee_cv.get_data(DataTypes::display).clone(), )); let _ = json_invitee.push(( - DataType::Avatar, - call_invitee_cv.get_data(DataType::Avatar).clone(), + DataTypes::avatar, + call_invitee_cv.get_data(DataTypes::avatar).clone(), )); - let _ = invited.push(DataValue::Container(json_invitee.iter().map(|(k, v)| (k.to_id(&TypeMap::latest()), v.clone())).collect())); + let _ = invited.push(DataValue::Container(json_invitee)); } let token = call.create_anonymous_token(self.get_user_id()).await; let mut serialized = Vec::new(); - let _ = serialized.push((DataType::CallId, DataValue::Str(call_id.to_string()))); - let _ = serialized.push((DataType::CallInvited, DataValue::Array(invited.clone()))); - let _ = serialized.push((DataType::CallMembers, DataValue::Array(invited))); - let _ = serialized.push((DataType::CallToken, DataValue::Str(token.unwrap()))); + let _ = serialized.push((DataTypes::call_id, DataValue::Str(call_id.to_string()))); + let _ = + serialized.push((DataTypes::call_invited, DataValue::Array(invited.clone()))); + let _ = serialized.push((DataTypes::call_members, DataValue::Array(invited))); + let _ = serialized.push((DataTypes::call_token, DataValue::Str(token.unwrap()))); self.clone() .send_message( - &&CommunicationValue::new(CommunicationType::IdentificationResponse) + &&CommunicationValue::new(CommunicationType::identification_response) .with_id(cv.get_id()) - .add_typed_default( - DataType::UserId, - DataValue::SignedNumber(self.user_id.into()), - ) - .add_typed_default( - DataType::Username, + .add_data(DataTypes::user_id, DataValue::Number(self.user_id as i64)) + .add_data( + DataTypes::username, DataValue::Str(self.clone().get_user_name().await), ) - .add_typed_default( - DataType::Display, + .add_data( + DataTypes::display, DataValue::Str(self.get_display_name().await), ) - .add_typed_default(DataType::Avatar, DataValue::Str(self.get_avatar().await)) - .add_typed_default(DataType::CallState, DataValue::Container(serialized.iter().map(|(k, v)| (k.to_id(&TypeMap::latest()), v.clone())).collect())), + .add_data(DataTypes::avatar, DataValue::Str(self.get_avatar().await)) + .add_data(DataTypes::call_state, DataValue::Container(serialized)), ) .await; } // Handle ping - if cv.is_type(CommunicationType::Ping) { + if cv.is_type(CommunicationType::ping) { self.handle_ping(cv).await; return; } // Handle client status changes - if cv.is_type(CommunicationType::ClientChanged) { + if cv.is_type(CommunicationType::client_changed) { self.handle_client_changed(cv).await; return; } // Handle call invites - if cv.is_type(CommunicationType::CallInvite) { + if cv.is_type(CommunicationType::call_invite) { self.handle_call_invite(cv).await; return; } // Handle get call requests - if cv.is_type(CommunicationType::CallToken) { + if cv.is_type(CommunicationType::call_token) { self.handle_get_call(cv).await; return; } - if cv.is_type(CommunicationType::CallDisconnectUser) { + if cv.is_type(CommunicationType::call_disconnect_user) { self.handle_call_disconnect_user(cv).await; return; } - if cv.is_type(CommunicationType::CallTimeoutUser) { + if cv.is_type(CommunicationType::call_timeout_user) { self.handle_call_timeout_user(cv).await; return; } - if cv.is_type(CommunicationType::ChangeUserData) { - if let Some(display_name) = cv.get_data(DataType::Display).as_str() { + if cv.is_type(CommunicationType::change_user_data) { + if let Some(display_name) = cv.get_data(DataTypes::display).as_str() { let _ = self.set_display_name(display_name.to_string()).await; } return; } - if cv.is_type(CommunicationType::GetUserData) { + if cv.is_type(CommunicationType::get_user_data) { if let Some(anonymous) = { - if let Some(user_id) = cv.get_data(DataType::UserId).as_signed_number() { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { anonymous_manager::get_anonymous_user(user_id as u64).await - } else if let Some(username) = cv.get_data(DataType::Username).as_str() { + } else if let Some(username) = cv.get_data(DataTypes::username).as_str() { anonymous_manager::get_anonymous_user_by_name(username.to_string()).await } else { None } } { - let response = CommunicationValue::new(CommunicationType::GetUserData) + let response = CommunicationValue::new(CommunicationType::get_user_data) .with_id(cv.get_id()) - .add_typed_default( - DataType::Username, + .add_data( + DataTypes::username, DataValue::Str(anonymous.get_user_name().await), ) - .add_typed_default( - DataType::UserId, - DataValue::SignedNumber(anonymous.user_id.into()), + .add_data( + DataTypes::user_id, + DataValue::Number(anonymous.user_id as i64), ) - .add_typed_default( - DataType::Display, + .add_data( + DataTypes::display, DataValue::Str(anonymous.get_display_name().await), ) - .add_typed_default(DataType::UserState, DataValue::Str("online".to_string())) - .add_typed_default( - DataType::Avatar, + .add_data(DataTypes::user_state, DataValue::Str("online".to_string())) + .add_data( + DataTypes::avatar, DataValue::Str(anonymous.get_avatar().await), ); @@ -273,9 +272,9 @@ impl AnonymousClientConnection { } } - if cv.is_type(CommunicationType::GetUserData) - || cv.is_type(CommunicationType::GetIotaData) - || cv.is_type(CommunicationType::DeleteUser) + if cv.is_type(CommunicationType::get_user_data) + || cv.is_type(CommunicationType::get_iota_data) + || cv.is_type(CommunicationType::delete_user) { self.handle_omega_forward(cv).await; return; @@ -297,7 +296,7 @@ impl AnonymousClientConnection { /// Handle ping message async fn handle_ping(self: Arc, cv: CommunicationValue) { // Update our ping if provided - if let DataValue::SignedNumber(last_ping) = cv.get_data(DataType::LastPing) { + if let DataValue::Number(last_ping) = cv.get_data(DataTypes::last_ping) { if let Ok(ping_val) = last_ping.to_string().parse::() { let mut ping_guard = self.ping.write().await; *ping_guard = ping_val; @@ -305,14 +304,14 @@ impl AnonymousClientConnection { } // Send pong response - let response = CommunicationValue::new(CommunicationType::Pong).with_id(cv.get_id()); + let response = CommunicationValue::new(CommunicationType::pong).with_id(cv.get_id()); self.send_message(&response).await; } /// Handle client status change async fn handle_client_changed(self: Arc, cv: CommunicationValue) { - if let DataValue::Str(status_str) = cv.get_data(DataType::UserState) { + if let DataValue::Str(status_str) = cv.get_data(DataTypes::user_state) { let user_status = UserStatus::from_str(&status_str).unwrap_or(UserStatus::user_online); OmegaConnection::client_changed(self.user_id as i64, self.user_id as i64, user_status) .await; @@ -321,37 +320,40 @@ impl AnonymousClientConnection { /// Handle call invite async fn handle_call_invite(self: Arc, cv: CommunicationValue) { - let receiver_id: i64 = cv.get_data(DataType::ReceiverId).as_signed_number().unwrap_or(0) as i64; + let receiver_id: i64 = cv.get_data(DataTypes::receiver_id).as_number().unwrap_or(0); if receiver_id == 0 { - self.send_error_response(&cv.get_id(), CommunicationType::ErrorNoUserId) + self.send_error_response(&cv.get_id(), CommunicationType::error_no_user_id) .await; return; } - let call_id = match cv.get_data(DataType::CallId) { + let call_id = match cv.get_data(DataTypes::call_id) { DataValue::Str(id_str) => match Uuid::parse_str(&id_str.to_string()) { Ok(id) => id, Err(_) => { - self.send_error_response(&cv.get_id(), CommunicationType::ErrorInvalidCallId) - .await; + self.send_error_response( + &cv.get_id(), + CommunicationType::error_invalid_call_id, + ) + .await; return; } }, _ => { - self.send_error_response(&cv.get_id(), CommunicationType::ErrorNoCallId) + self.send_error_response(&cv.get_id(), CommunicationType::error_no_call_id) .await; return; } }; let secret = cv - .get_data(DataType::CallSecret) + .get_data(DataTypes::call_secret) .as_str() .map(|s| s.to_string()); let invited = call_manager::add_invite(call_id, self.user_id, receiver_id as u64, secret).await; if !invited { - self.send_error_response(&cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; } @@ -364,15 +366,12 @@ impl AnonymousClientConnection { let sender_id = self.get_user_id(); // User is offline - send push notification for call invite - 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_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())) - .add_typed_default( - DataType::Notifications, + .add_data(DataTypes::sender_id, DataValue::Number(sender_id as i64)) + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())) + .add_data( + DataTypes::notifications, DataValue::Str("call_invite".to_string()), ); @@ -382,9 +381,9 @@ impl AnonymousClientConnection { let _ = omega_conn.send_message(&push_cv).await; }); - let error_cv = CommunicationValue::new(CommunicationType::ErrorNotFound) + let error_cv = CommunicationValue::new(CommunicationType::error_not_found) .with_id(cv.get_id()) - .add_typed_default(DataType::ReceiverId, DataValue::SignedNumber(receiver_id.into())); + .add_data(DataTypes::receiver_id, DataValue::Number(receiver_id)); self.send_message(&error_cv).await; return; } @@ -394,19 +393,19 @@ impl AnonymousClientConnection { let sender_id = self.get_user_id(); // Create and send call distribution message - let forward = CommunicationValue::new(CommunicationType::CallInvite) + let forward = CommunicationValue::new(CommunicationType::call_invite) .with_receiver(receiver_id as u64) .with_sender(sender_id) - .add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())) - .add_typed_default( - DataType::ReceiverId, + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())) + .add_data( + DataTypes::receiver_id, DataValue::Str(receiver_id.to_string()), ) - .add_typed_default(DataType::SenderId, DataValue::Str(sender_id.to_string())); + .add_data(DataTypes::sender_id, DataValue::Str(sender_id.to_string())); target_rho.message_to_client(forward).await; - let response = CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); + let response = CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); self.send_message(&response).await; } @@ -414,40 +413,44 @@ impl AnonymousClientConnection { async fn handle_get_call(self: Arc, cv: CommunicationValue) { let user_id = self.get_user_id(); - let call_id = match cv.get_data(DataType::CallId) { + let call_id = match cv.get_data(DataTypes::call_id) { DataValue::Str(id_str) => match Uuid::parse_str(&id_str.to_string()) { Ok(id) => id, Err(_) => { - self.send_error_response(&cv.get_id(), CommunicationType::ErrorInvalidCallId) - .await; + self.send_error_response( + &cv.get_id(), + CommunicationType::error_invalid_call_id, + ) + .await; return; } }, _ => { - self.send_error_response(&cv.get_id(), CommunicationType::ErrorNoCallId) + self.send_error_response(&cv.get_id(), CommunicationType::error_no_call_id) .await; return; } }; if let Some(token) = call_manager::get_call_token(user_id, call_id).await { - let response = CommunicationValue::new(CommunicationType::CallToken) + let response = CommunicationValue::new(CommunicationType::call_token) .with_id(cv.get_id()) .with_receiver(user_id) - .add_typed_default(DataType::CallToken, DataValue::Str(token.to_string())); + .add_data(DataTypes::call_token, DataValue::Str(token.to_string())); self.send_message(&response).await; } else { - let error_cv = CommunicationValue::new(CommunicationType::ErrorNoCallId) + let error_cv = CommunicationValue::new(CommunicationType::error_no_call_id) .with_id(cv.get_id()) - .add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())); + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())); self.send_message(&error_cv).await; return; } } async fn handle_call_timeout_user(self: Arc, cv: CommunicationValue) { - let call_id = Uuid::from_str(cv.get_data(DataType::CallId).as_str().unwrap_or("")).unwrap(); - let user_id = cv.get_data(DataType::UserId).as_signed_number().unwrap_or(0); - let untill = cv.get_data(DataType::Untill).as_signed_number().unwrap_or(0); + let call_id = + Uuid::from_str(cv.get_data(DataTypes::call_id).as_str().unwrap_or("")).unwrap(); + let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0); + let untill = cv.get_data(DataTypes::untill).as_number().unwrap_or(0); let call = call_manager::get_call(call_id).await; if let Some(call) = call { @@ -460,14 +463,15 @@ impl AnonymousClientConnection { call.get_caller(user_id as u64) .await .unwrap() - .set_timeout(untill.try_into().unwrap()) + .set_timeout(untill) .await; } } } async fn handle_call_disconnect_user(self: Arc, cv: CommunicationValue) { - let call_id = Uuid::from_str(cv.get_data(DataType::CallId).as_str().unwrap_or("")).unwrap(); - let user_id = cv.get_data(DataType::UserId).as_signed_number().unwrap_or(0); + let call_id = + Uuid::from_str(cv.get_data(DataTypes::call_id).as_str().unwrap_or("")).unwrap(); + let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0); let call = call_manager::get_call(call_id).await; if let Some(call) = call { @@ -521,9 +525,9 @@ impl AnonymousClientConnection { } else { user_status }; - let notification = CommunicationValue::new(CommunicationType::ClientChanged) - .add_typed_default(DataType::UserId, DataValue::Str(user_id.to_string())) - .add_typed_default(DataType::UserState, DataValue::Str(status.to_string())); + let notification = CommunicationValue::new(CommunicationType::client_changed) + .add_data(DataTypes::user_id, DataValue::Str(user_id.to_string())) + .add_data(DataTypes::user_state, DataValue::Str(status.to_string())); self.send_message(¬ification).await; } diff --git a/src/calls/call_group.rs b/src/calls/call_group.rs index d751802..22a0751 100755 --- a/src/calls/call_group.rs +++ b/src/calls/call_group.rs @@ -1,5 +1,5 @@ -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; use serde_json::Map; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; use std::{collections::BTreeMap, env, sync::Arc, time::Duration}; use tokio::sync::RwLock; @@ -111,15 +111,15 @@ impl CallGroup { ); let response_cv = get_omega_connection() .await_response( - &CommunicationValue::new(CommunicationType::ShortenLink) - .add_typed_default(DataType::Link, DataValue::Str(long_link)), + &CommunicationValue::new(CommunicationType::shorten_link) + .add_data(DataTypes::link, DataValue::Str(long_link)), Some(Duration::from_secs(20)), ) .await; if let Ok(response) = response_cv { *self.short_link.write().await = Some( response - .get_data(DataType::Link) + .get_data(DataTypes::link) .as_str() .unwrap() .to_string(), diff --git a/src/omega/omega_connection.rs b/src/omega/omega_connection.rs index 5c6c66f..563d6a8 100644 --- a/src/omega/omega_connection.rs +++ b/src/omega/omega_connection.rs @@ -9,8 +9,6 @@ use crate::{ }, }; use dashmap::DashMap; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; -use mtp::transport::{Policy, Receiver, SendMode, Sender}; use once_cell::sync::Lazy; use std::{collections::HashMap, env, sync::Arc, time::Duration}; use tokio::{ @@ -18,6 +16,8 @@ use tokio::{ task::JoinHandle, time::{Instant, sleep}, }; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32}; +use ttp_native::{Policy, Receiver, SendMode, Sender}; use uuid::Uuid; // ============================================================================ @@ -264,7 +264,7 @@ impl OmegaConnection { let addr_str = format!("https://{}:{}", self.host, self.port); - let (sender, mut receiver) = mtp::transport::client::connect( + let (sender, mut receiver) = ttp_native::client::connect( &addr_str, None, Policy { @@ -347,22 +347,22 @@ impl OmegaConnection { // ------------------------------------------------------------------------- async fn send_identification(&self) { - let id = rand::random::(); + let id = rand_u32(); let omikron_id = env::var("ID") .unwrap_or("0".to_string()) .parse::() .unwrap_or(0); - let identify_msg = CommunicationValue::new(CommunicationType::Identification) + let identify_msg = CommunicationValue::new(CommunicationType::identification) .with_id(id) - .add_typed_default(DataType::OmikronId, DataValue::SignedNumber(omikron_id.into())); + .add_data(DataTypes::omikron_id, DataValue::Number(omikron_id)); WAITING_TASKS.insert( id, WaitingTask { task: Box::new(|selfc, cv| { - if cv.is_type(CommunicationType::ErrorNotFound) { + if cv.is_type(CommunicationType::error_not_found) { log_err!( 0, PrintType::Omega, @@ -370,7 +370,7 @@ impl OmegaConnection { ); return false; } - if !cv.is_type(CommunicationType::Challenge) { + if !cv.is_type(CommunicationType::challenge) { return false; } @@ -390,12 +390,12 @@ impl OmegaConnection { async fn handle_challenge(&self, cv: CommunicationValue) -> Result<(), String> { let challenge = cv - .get_data(DataType::Challenge) + .get_data(DataTypes::challenge) .as_str() .ok_or("Challenge not found")?; let server_pub_key = cv - .get_data(DataType::PublicKey) + .get_data(DataTypes::public_key) .as_str() .ok_or("Public key not found")?; @@ -406,9 +406,9 @@ impl OmegaConnection { ) .map_err(|e| format!("Decryption failed: {:?}", e))?; - let response_msg = CommunicationValue::new(CommunicationType::ChallengeResponse) + let response_msg = CommunicationValue::new(CommunicationType::challenge_response) .with_id(cv.get_id()) - .add_typed_default(DataType::Challenge, DataValue::Str(decrypted_challenge)); + .add_data(DataTypes::challenge, DataValue::Str(decrypted_challenge)); let response_id = response_msg.get_id(); @@ -416,13 +416,13 @@ impl OmegaConnection { response_id, WaitingTask { task: Box::new(|selfc, final_cv| { - if !final_cv.is_type(CommunicationType::IdentificationResponse) { + if !final_cv.is_type(CommunicationType::identification_response) { log_err!(0, PrintType::Omega, "Expected identification_response"); return false; } let accepted = final_cv - .get_data(DataType::Accepted) + .get_data(DataTypes::accepted) .as_bool() .unwrap_or(false); @@ -459,25 +459,23 @@ impl OmegaConnection { let rho_connections_reader = RHO_CONNECTIONS.read().await; for iota_id in rho_connections_reader.keys() { - connected_iota_ids.push(DataValue::SignedNumber((*iota_id).into())); + connected_iota_ids.push(DataValue::Number(*iota_id)); } for rho in rho_connections_reader.values() { for client_conn in rho.get_client_connections().await { - connected_user_ids.push(DataValue::SignedNumber( - client_conn.get_user_id().await.into(), - )); + connected_user_ids.push(DataValue::Number(client_conn.get_user_id().await as i64)); } } drop(rho_connections_reader); - let sync_msg = CommunicationValue::new(CommunicationType::SyncClientIotaStatus) - .add_typed_default(DataType::IotaIds, DataValue::Array(connected_iota_ids)) - .add_typed_default(DataType::UserIds, DataValue::Array(connected_user_ids)) - .add_typed_default( - DataType::RhoConnections, - DataValue::SignedNumber(connection_count().await as i128), + let sync_msg = CommunicationValue::new(CommunicationType::sync_client_iota_status) + .add_data(DataTypes::iota_ids, DataValue::Array(connected_iota_ids)) + .add_data(DataTypes::user_ids, DataValue::Array(connected_user_ids)) + .add_data( + DataTypes::rho_connections, + DataValue::Number(connection_count().await as i64), ); self.send_message(&sync_msg).await; @@ -490,7 +488,7 @@ impl OmegaConnection { async fn read_loop( self: Arc, receiver: &mut Receiver, - sender_handle: Arc, + sender_handle: Arc, ) { // Monitor both receiver and sender handle for close let mut close_rx = sender_handle.subscribe_close(); @@ -500,11 +498,11 @@ impl OmegaConnection { result = receiver.receive() => { match result { Ok(cv) => { - 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::Omega, &cv); } - if cv.is_type(CommunicationType::Pong) || cv.is_type(CommunicationType::Ping) { + if cv.is_type(CommunicationType::pong) || cv.is_type(CommunicationType::ping) { self.handle_pong(&cv).await; continue; } @@ -516,17 +514,17 @@ impl OmegaConnection { } } - if cv.is_type(CommunicationType::IotaUserData) { - if let DataValue::Array(users) = cv.get_data(DataType::UserIds) { + if cv.is_type(CommunicationType::iota_user_data) { + if let DataValue::Array(users) = cv.get_data(DataTypes::user_ids) { let mut user_ids: Vec = Vec::new(); for value in users { - if let DataValue::SignedNumber(user_id) = value { + if let DataValue::Number(user_id) = value { user_ids.push(*user_id as u64); } } let connections = crate::rho::rho_manager::RHO_CONNECTIONS.read().await; - if let Some(iota_id) = cv.get_data(DataType::IotaId).as_number() { - if let Some(rho) = connections.get(&(iota_id as i64)) { + if let Some(iota_id) = cv.get_data(DataTypes::iota_id).as_number() { + if let Some(rho) = connections.get(&iota_id) { rho.get_iota_connection().set_user_ids(user_ids).await; } } else { @@ -580,13 +578,13 @@ impl OmegaConnection { } async fn send_ping(&self) { - let ping = CommunicationValue::new(CommunicationType::Ping).add_typed_default( - DataType::SendTime, - DataValue::SignedNumber( + let ping = CommunicationValue::new(CommunicationType::ping).add_data( + DataTypes::send_time, + DataValue::Number( std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap_or_default() - .as_secs() as i128, + .as_secs() as i64, ), ); self.send_message(&ping).await; @@ -594,16 +592,16 @@ impl OmegaConnection { async fn handle_pong(&self, cv: &CommunicationValue) { let timestamp = cv - .get_data(DataType::SendTime) + .get_data(DataTypes::send_time) .as_number() .unwrap_or_else(|| { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap_or_default() - .as_secs() as i128 + .as_secs() as i64 }); - *self.last_ping.lock().await = timestamp.try_into().unwrap(); + *self.last_ping.lock().await = timestamp; } // ------------------------------------------------------------------------- @@ -611,7 +609,7 @@ impl OmegaConnection { // ------------------------------------------------------------------------- pub async fn send_message(&self, cv: &CommunicationValue) { - 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::Omega, &cv); } @@ -712,33 +710,30 @@ impl OmegaConnection { #[allow(dead_code)] pub async fn close_iota(iota_id: i64) { - let cv = CommunicationValue::new(CommunicationType::IotaDisconnected) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())); + let cv = CommunicationValue::new(CommunicationType::iota_disconnected) + .add_data(DataTypes::iota_id, DataValue::Number(iota_id)); OMEGA_CONNECTION.send_message(&cv).await; } pub async fn client_changed(_iota_id: i64, user_id: i64, state: UserStatus) { let msg_type = match state { - UserStatus::iota_offline => CommunicationType::UserDisconnected, - UserStatus::user_offline => CommunicationType::UserDisconnected, - UserStatus::user_invisible => CommunicationType::UserDisconnected, - _ => CommunicationType::UserConnected, + UserStatus::iota_offline => CommunicationType::user_disconnected, + UserStatus::user_offline => CommunicationType::user_disconnected, + UserStatus::user_invisible => CommunicationType::user_disconnected, + _ => CommunicationType::user_connected, }; let cv = CommunicationValue::new(msg_type) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id.into())) - .add_typed_default(DataType::UserState, DataValue::Str(state.to_string())); + .add_data(DataTypes::user_id, DataValue::Number(user_id)) + .add_data(DataTypes::user_state, DataValue::Str(state.to_string())); OMEGA_CONNECTION.send_message(&cv).await; } pub async fn user_states(user_id: i64, user_ids: Vec) { - let user_ids = user_ids - .iter() - .map(|v| DataValue::SignedNumber((*v).into())) - .collect(); + let user_ids = user_ids.iter().map(|v| DataValue::Number(*v)).collect(); - let cv = CommunicationValue::new(CommunicationType::GetStates) - .add_typed_default(DataType::UserIds, DataValue::Array(user_ids)); + let cv = CommunicationValue::new(CommunicationType::get_states) + .add_data(DataTypes::user_ids, DataValue::Array(user_ids)); let msg_id = cv.get_id(); WAITING_TASKS.insert( diff --git a/src/omega/ping_pong_task.rs b/src/omega/ping_pong_task.rs index a4e4687..c7fc0b9 100644 --- a/src/omega/ping_pong_task.rs +++ b/src/omega/ping_pong_task.rs @@ -1,6 +1,6 @@ -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; use std::time::Duration; use tokio::time::Instant; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32}; use crate::omega::omega_connection::OmegaConnection; @@ -8,7 +8,7 @@ const PING_TIMEOUT: Duration = Duration::from_secs(30); impl OmegaConnection { pub async fn send_ping(&self) { - let id = rand::random::(); + let id = rand_u32(); let send_time = Instant::now(); let mut message_send_times = self.message_send_times.lock().await; @@ -19,11 +19,11 @@ impl OmegaConnection { } pub async fn send_ping_message(&self, id: u32) { - let ping_message = CommunicationValue::new(CommunicationType::Ping) + let ping_message = CommunicationValue::new(CommunicationType::ping) .with_id(id) .add_data( - DataType::LastPing, - DataValue::SignedNumber(self.last_ping.lock().await.unwrap()), + DataTypes::last_ping, + DataValue::Number(self.last_ping.lock().await.unwrap()), ); self.send_message(&ping_message).await; diff --git a/src/rho/app_connection.rs b/src/rho/app_connection.rs index af13453..973a9de 100644 --- a/src/rho/app_connection.rs +++ b/src/rho/app_connection.rs @@ -4,18 +4,17 @@ use crate::rho::connection::GeneralConnection; use crate::rho::{rho_connection::RhoConnection, rho_manager}; use crate::util::logger::PrintType; use crate::{log_cv_in, log_cv_out, log_err, log_in, log_out}; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; -use mtp::transport::{Receiver, Sender}; use std::sync::Arc; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use tokio::sync::RwLock; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; +use ttp_native::{Receiver, Sender}; use uuid::Uuid; pub struct AppConnection { pub user_id: u64, pub app_identifier: String, pub app_session: Uuid, - pub client_version: String, pub sender: Arc, pub receiver: Arc, @@ -37,7 +36,6 @@ impl AppConnection { user_id: user_id, app_identifier: general.app_identifier.read().await.clone().unwrap(), app_session: general.app_session.read().await.clone().unwrap(), - client_version: general.client_version.read().await.clone(), }) } pub fn start(self: Arc) { @@ -54,7 +52,7 @@ impl AppConnection { tokio::time::sleep(Duration::from_millis(50)).await; if self_clone2.get_rho_connection().await.is_none() { self_clone2 - .send_error_response(0, CommunicationType::ErrorNoIota) + .send_error_response(0, CommunicationType::error_no_iota) .await; } }); @@ -86,7 +84,7 @@ impl AppConnection { ); return; } - 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::App, &cv); } let _ = self.sender.send(&cv).await; @@ -95,41 +93,41 @@ impl AppConnection { /// Handle incoming message from app pub async fn handle_message(self: Arc, cv: CommunicationValue) { tokio::spawn(async move { - if cv.is_type(CommunicationType::Ping) { + if cv.is_type(CommunicationType::ping) { self.handle_ping(cv).await; return; } log_cv_in!(PrintType::App, cv); - if cv.is_type(CommunicationType::GetUserData) { + if cv.is_type(CommunicationType::get_user_data) { if let Some(anonymous) = { - 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() { anonymous_manager::get_anonymous_user(user_id as u64).await - } else if let Some(username) = cv.get_data(DataType::Username).as_str() { + } else if let Some(username) = cv.get_data(DataTypes::username).as_str() { anonymous_manager::get_anonymous_user_by_name(username.to_string()).await } else { None } } { - let response = CommunicationValue::new(CommunicationType::GetUserData) + let response = CommunicationValue::new(CommunicationType::get_user_data) .with_id(cv.get_id()) - .add_typed_default( - DataType::Username, + .add_data( + DataTypes::username, DataValue::Str(anonymous.get_user_name().await), ) - .add_typed_default( - DataType::UserId, - DataValue::SignedNumber(anonymous.get_user_id().into()), + .add_data( + DataTypes::user_id, + DataValue::Number(anonymous.get_user_id() as i64), ) - .add_typed_default( - DataType::Display, + .add_data( + DataTypes::display, DataValue::Str(anonymous.get_display_name().await), ) - .add_typed_default( - DataType::Avatar, + .add_data( + DataTypes::avatar, DataValue::Str(anonymous.get_avatar().await), ) - .add_typed_default(DataType::UserState, DataValue::Str("online".to_string())); + .add_data(DataTypes::user_state, DataValue::Str("online".to_string())); self.send_message(&response).await; @@ -137,8 +135,8 @@ impl AppConnection { } } - if cv.is_type(CommunicationType::GetUserData) - || cv.is_type(CommunicationType::GetIotaData) + if cv.is_type(CommunicationType::get_user_data) + || cv.is_type(CommunicationType::get_iota_data) { let sender = self.get_user_id().await; self.handle_omega_forward(cv.with_sender(sender as u64)) @@ -164,13 +162,13 @@ impl AppConnection { /// Handle ping message async fn handle_ping(self: Arc, cv: CommunicationValue) { // Update our ping if provided - if let DataValue::SignedNumber(last_ping) = cv.get_data(DataType::LastPing) { + if let DataValue::Number(last_ping) = cv.get_data(DataTypes::last_ping) { let current = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_millis(); let mut ping_guard = self.ping.write().await; - *ping_guard = (current as i128 - *last_ping) as i64; + *ping_guard = current as i64 - last_ping; } // Get Iota ping from RhoConnection @@ -181,9 +179,9 @@ impl AppConnection { }; // Send pong response - let response = CommunicationValue::new(CommunicationType::Pong) + let response = CommunicationValue::new(CommunicationType::pong) .with_id(cv.get_id()) - .add_typed_default(DataType::PingIota, DataValue::SignedNumber(iota_ping.into())); + .add_data(DataTypes::ping_iota, DataValue::Number(iota_ping)); self.send_message(&response).await; } @@ -204,11 +202,14 @@ impl AppConnection { cv.get_receiver() ); - if cv.is_type(CommunicationType::AddConversation) - && cv.get_data(DataType::ChatPartnerId).as_number().is_none() + if cv.is_type(CommunicationType::add_conversation) + && cv + .get_data(DataTypes::chat_partner_id) + .as_number() + .is_none() { let chat_partner_name = cv - .get_data(DataType::ChatPartnerName) + .get_data(DataTypes::chat_partner_name) .as_str() .unwrap_or("") .to_string(); @@ -217,17 +218,17 @@ impl AppConnection { .await .is_some() { - self.send_error_response(cv.get_id(), CommunicationType::ErrorAnonymous) + self.send_error_response(cv.get_id(), CommunicationType::error_anonymous) .await; return; } let load_uuid_response = get_omega_connection() .await_response( - &CommunicationValue::new(CommunicationType::GetUserData) + &CommunicationValue::new(CommunicationType::get_user_data) .with_id(cv.clone().get_id()) - .add_typed_default( - DataType::Username, + .add_data( + DataTypes::username, DataValue::Str(chat_partner_name.clone()), ), Some(Duration::from_secs(20)), @@ -235,7 +236,7 @@ impl AppConnection { .await; let chat_partner_id = { if let Ok(load_uuid_response) = load_uuid_response { - load_uuid_response.get_data(DataType::UserId).clone() + load_uuid_response.get_data(DataTypes::user_id).clone() } else { DataValue::Null } @@ -254,7 +255,7 @@ impl AppConnection { let updated_cv = cv .with_sender(sender_user_id as u64) - .add_typed_default(DataType::ChatPartnerId, chat_partner_id); + .add_data(DataTypes::chat_partner_id, chat_partner_id); rho_conn.message_to_iota(updated_cv).await; } else { log_err!( @@ -292,12 +293,9 @@ impl AppConnection { msg_type, msg_id ); - let error_cv = CommunicationValue::new(CommunicationType::ErrorNoIota) + let error_cv = CommunicationValue::new(CommunicationType::error_no_iota) .with_id(msg_id) - .add_typed_default( - DataType::UserId, - DataValue::SignedNumber(sender_user_id.into()), - ); + .add_data(DataTypes::user_id, DataValue::Number(sender_user_id as i64)); self.send_message(&error_cv).await; } } @@ -338,7 +336,6 @@ impl Clone for AppConnection { user_id: self.user_id, app_identifier: self.app_identifier.clone(), app_session: self.app_session, - client_version: self.client_version.clone(), ping: Arc::clone(&self.ping), pub_key: Arc::clone(&self.pub_key), rho_connection: Arc::clone(&self.rho_connection), diff --git a/src/rho/client_connection.rs b/src/rho/client_connection.rs index d7fe244..e3d11fa 100644 --- a/src/rho/client_connection.rs +++ b/src/rho/client_connection.rs @@ -6,18 +6,17 @@ use crate::rho::{rho_connection::RhoConnection, rho_manager}; use crate::util::logger::PrintType; use crate::{data::user::UserStatus, omega::omega_connection::OmegaConnection}; use crate::{log_cv_in, log_cv_out, log_err, log_in, log_out}; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; -use mtp::transport::{Receiver, Sender}; use std::str::FromStr; use std::sync::Arc; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use tokio::sync::RwLock; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; +use ttp_native::{Receiver, Sender}; use uuid::Uuid; pub struct ClientConnection { pub user_id: u64, pub session_id: u64, - pub client_version: String, pub sender: Arc, pub receiver: Arc, @@ -40,7 +39,6 @@ impl ClientConnection { receiver: general.receiver.clone(), user_id: user_id, session_id: general.session_id.read().await.clone(), - client_version: general.client_version.read().await.clone(), }) } pub fn start(self: Arc) { @@ -57,7 +55,7 @@ impl ClientConnection { tokio::time::sleep(Duration::from_millis(50)).await; if self_clone2.get_rho_connection().await.is_none() { self_clone2 - .send_error_response(0, CommunicationType::ErrorNoIota) + .send_error_response(0, CommunicationType::error_no_iota) .await; } }); @@ -88,7 +86,7 @@ impl ClientConnection { ); return; } - 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::Client, &cv); } let _ = self.sender.send(&cv).await; @@ -97,7 +95,7 @@ impl ClientConnection { /// Handle incoming message from client pub async fn handle_message(self: Arc, cv: CommunicationValue) { tokio::spawn(async move { - if cv.is_type(CommunicationType::Ping) { + if cv.is_type(CommunicationType::ping) { self.handle_ping(cv).await; return; } @@ -106,63 +104,75 @@ impl ClientConnection { let mut cv = cv; // Handle client status changes - if cv.is_type(CommunicationType::ClientChanged) { + if cv.is_type(CommunicationType::client_changed) { self.handle_client_changed(cv).await; return; } // Handle call invites - if cv.is_type(CommunicationType::CallInvite) { + if cv.is_type(CommunicationType::call_invite) { self.handle_call_invite(cv).await; return; } // Handle get call requests - if cv.is_type(CommunicationType::CallToken) { + if cv.is_type(CommunicationType::call_token) { self.handle_get_call(cv).await; return; } - if cv.is_type(CommunicationType::CallData) { + if cv.is_type(CommunicationType::call_data) { self.handle_get_call_data(cv).await; return; } - if cv.is_type(CommunicationType::CallDisconnectUser) { + if cv.is_type(CommunicationType::call_disconnect_user) { self.handle_call_disconnect_user(cv).await; return; } - if cv.is_type(CommunicationType::CallTimeoutUser) { + if cv.is_type(CommunicationType::call_timeout_user) { self.handle_call_timeout_user(cv).await; return; } - if cv.is_type(CommunicationType::CallSetAnonymousJoining) { + if cv.is_type(CommunicationType::call_set_anonymous_joining) { self.handle_call_set_anonymous_joining(cv).await; return; } - if cv.is_type(CommunicationType::LoadTxtRecord) { + if cv.is_type(CommunicationType::load_txt_record) { self.handle_load_txt_record(cv).await; return; } - if cv.is_type(CommunicationType::GetUserData) { + if cv.is_type(CommunicationType::get_user_data) { if let Some(anonymous) = { - if let Some(user_id) = cv.get_data(DataType::UserId).as_signed_number() { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { anonymous_manager::get_anonymous_user(user_id as u64).await - } else if let Some(username) = cv.get_data(DataType::Username).as_str() { + } else if let Some(username) = cv.get_data(DataTypes::username).as_str() { anonymous_manager::get_anonymous_user_by_name(username.to_string()).await } else { None } } { - let response = CommunicationValue::new(CommunicationType::GetUserData) + let response = CommunicationValue::new(CommunicationType::get_user_data) .with_id(cv.get_id()) - .add_typed_default(DataType::Username, DataValue::Str(anonymous.get_user_name().await)) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(anonymous.get_user_id().into())) - .add_typed_default(DataType::Display, DataValue::Str(anonymous.get_display_name().await)) - .add_typed_default(DataType::Avatar, DataValue::Str(anonymous.get_avatar().await)) - .add_typed_default(DataType::UserState, DataValue::Str("online".to_string())); + .add_data( + DataTypes::username, + DataValue::Str(anonymous.get_user_name().await), + ) + .add_data( + DataTypes::user_id, + DataValue::Number(anonymous.get_user_id() as i64), + ) + .add_data( + DataTypes::display, + DataValue::Str(anonymous.get_display_name().await), + ) + .add_data( + DataTypes::avatar, + DataValue::Str(anonymous.get_avatar().await), + ) + .add_data(DataTypes::user_state, DataValue::Str("online".to_string())); self.send_message(&response).await; @@ -170,12 +180,12 @@ impl ClientConnection { } } - if cv.is_type(CommunicationType::ChangeUserData) - || cv.is_type(CommunicationType::ReadNotification) - || cv.is_type(CommunicationType::GetNotifications) - || cv.is_type(CommunicationType::GetUserData) - || cv.is_type(CommunicationType::GetIotaData) - || cv.is_type(CommunicationType::DeleteUser) + if cv.is_type(CommunicationType::change_user_data) + || cv.is_type(CommunicationType::read_notification) + || cv.is_type(CommunicationType::get_notifications) + || cv.is_type(CommunicationType::get_user_data) + || cv.is_type(CommunicationType::get_iota_data) + || cv.is_type(CommunicationType::delete_user) { let sender = self.get_user_id().await; self.handle_omega_forward(cv.with_sender(sender as u64)) @@ -183,48 +193,72 @@ impl ClientConnection { return; } - let is_per_device_settings = cv.is_type(CommunicationType::SettingsSave) - || cv.is_type(CommunicationType::SettingsLoad) - || cv.is_type(CommunicationType::SettingsList); - let is_global_settings = cv.is_type(CommunicationType::GlobalSettingsSave) - || cv.is_type(CommunicationType::GlobalSettingsLoad); + let is_per_device_settings = cv.is_type(CommunicationType::settings_save) + || cv.is_type(CommunicationType::settings_load) + || cv.is_type(CommunicationType::settings_list); + let is_global_settings = cv.is_type(CommunicationType::global_settings_save) + || cv.is_type(CommunicationType::global_settings_load); if is_per_device_settings || is_global_settings { - let expected_session_id: i128 = self.session_id.into(); - let session_id = cv.get_data(DataType::SessionId).as_signed_number(); + let expected_session_id = self.session_id as i64; + let session_id = cv.get_data(DataTypes::session_id).as_number(); if is_per_device_settings { let Some(session_id) = session_id else { - let response = CommunicationValue::new(CommunicationType::ErrorInvalidData) - .with_id(cv.get_id()) - .with_receiver(self.user_id) - .add_typed_default(DataType::Message, DataValue::Str("Missing session_id".to_string())) - .add_typed_default(DataType::SessionId, DataValue::SignedNumber(expected_session_id)); + let response = + CommunicationValue::new(CommunicationType::error_invalid_data) + .with_id(cv.get_id()) + .with_receiver(self.user_id) + .add_data( + DataTypes::message, + DataValue::Str("Missing session_id".to_string()), + ) + .add_data( + DataTypes::session_id, + DataValue::Number(expected_session_id), + ); self.send_message(&response).await; return; }; if session_id != expected_session_id { - let response = CommunicationValue::new(CommunicationType::ErrorInvalidData) - .with_id(cv.get_id()) - .with_receiver(self.user_id) - .add_typed_default(DataType::Message, DataValue::Str("session_id mismatch".to_string())) - .add_typed_default(DataType::SessionId, DataValue::SignedNumber(expected_session_id)); + let response = + CommunicationValue::new(CommunicationType::error_invalid_data) + .with_id(cv.get_id()) + .with_receiver(self.user_id) + .add_data( + DataTypes::message, + DataValue::Str("session_id mismatch".to_string()), + ) + .add_data( + DataTypes::session_id, + DataValue::Number(expected_session_id), + ); self.send_message(&response).await; return; } } else if let Some(session_id) = session_id { if session_id != expected_session_id { - let response = CommunicationValue::new(CommunicationType::ErrorInvalidData) - .with_id(cv.get_id()) - .with_receiver(self.user_id) - .add_typed_default(DataType::Message, DataValue::Str("session_id mismatch".to_string())) - .add_typed_default(DataType::SessionId, DataValue::SignedNumber(expected_session_id)); + let response = + CommunicationValue::new(CommunicationType::error_invalid_data) + .with_id(cv.get_id()) + .with_receiver(self.user_id) + .add_data( + DataTypes::message, + DataValue::Str("session_id mismatch".to_string()), + ) + .add_data( + DataTypes::session_id, + DataValue::Number(expected_session_id), + ); self.send_message(&response).await; return; } } else { - cv = cv.add_typed_default(DataType::SessionId, DataValue::SignedNumber(expected_session_id)); + cv = cv.add_data( + DataTypes::session_id, + DataValue::Number(expected_session_id), + ); } } @@ -247,13 +281,13 @@ impl ClientConnection { /// Handle ping message async fn handle_ping(self: Arc, cv: CommunicationValue) { // Update our ping if provided - if let DataValue::SignedNumber(last_ping) = cv.get_data(DataType::LastPing) { + if let DataValue::Number(last_ping) = cv.get_data(DataTypes::last_ping) { let current = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_millis(); let mut ping_guard = self.ping.write().await; - *ping_guard = (current as i128 - *last_ping) as i64; + *ping_guard = current as i64 - last_ping; } // Get Iota ping from RhoConnection @@ -264,9 +298,9 @@ impl ClientConnection { }; // Send pong response - let response = CommunicationValue::new(CommunicationType::Pong) + let response = CommunicationValue::new(CommunicationType::pong) .with_id(cv.get_id()) - .add_typed_default(DataType::PingIota, DataValue::SignedNumber(iota_ping.into())); + .add_data(DataTypes::ping_iota, DataValue::Number(iota_ping)); self.send_message(&response).await; } @@ -274,7 +308,7 @@ impl ClientConnection { /// Handle client status change async fn handle_client_changed(self: Arc, cv: CommunicationValue) { let user_id = self.get_user_id().await; - if let DataValue::Str(status_str) = cv.get_data(DataType::UserState) { + if let DataValue::Str(status_str) = cv.get_data(DataTypes::user_state) { let user_status = UserStatus::from_str(&status_str).unwrap_or(UserStatus::user_online); if let Some(rho_conn) = self.get_rho_connection().await { OmegaConnection::client_changed( @@ -289,54 +323,57 @@ impl ClientConnection { /// Handle call invite async fn handle_call_invite(self: Arc, cv: CommunicationValue) { - let receiver_id: i128 = cv.get_data(DataType::ReceiverId).as_signed_number().unwrap_or(0); + let receiver_id: i64 = cv.get_data(DataTypes::receiver_id).as_number().unwrap_or(0); if receiver_id == 0 { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNoUserId) + self.send_error_response(cv.get_id(), CommunicationType::error_no_user_id) .await; return; } - let call_id = match cv.get_data(DataType::CallId) { + let call_id = match cv.get_data(DataTypes::call_id) { DataValue::Str(id_str) => match Uuid::parse_str(id_str.as_str()) { Ok(id) => id, Err(_) => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; } }, _ => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNoCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_no_call_id) .await; return; } }; let secret = cv - .get_data(DataType::CallSecret) + .get_data(DataTypes::call_secret) .as_str() .map(|s| s.to_string()); let invited = call_manager::add_invite(call_id, self.user_id, receiver_id as u64, secret).await; if !invited { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; } // Find target RhoConnection - let target_rho = match rho_manager::get_rho_con_for_user(receiver_id as i64).await { + let target_rho = match rho_manager::get_rho_con_for_user(receiver_id).await { Some(rho) => rho, _ => { // Get sender user ID let sender_id = self.get_user_id().await; // User is offline - send push notification for call invite - 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_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())) - .add_typed_default(DataType::Notifications, DataValue::Str("call_invite".to_string())); + .add_data(DataTypes::sender_id, DataValue::Number(sender_id as i64)) + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())) + .add_data( + DataTypes::notifications, + DataValue::Str("call_invite".to_string()), + ); let omega_conn = get_omega_connection(); // Send fire-and-forget, don't await to avoid blocking @@ -344,9 +381,9 @@ impl ClientConnection { let _ = omega_conn.send_message(&push_cv).await; }); - let error_cv = CommunicationValue::new(CommunicationType::ErrorNotFound) + let error_cv = CommunicationValue::new(CommunicationType::error_not_found) .with_id(cv.get_id()) - .add_typed_default(DataType::ReceiverId, DataValue::SignedNumber(receiver_id.into())); + .add_data(DataTypes::receiver_id, DataValue::Number(receiver_id)); self.send_message(&error_cv).await; return; } @@ -356,17 +393,20 @@ impl ClientConnection { let sender_id = self.get_user_id().await as i64; // Create and send call distribution message - let forward = CommunicationValue::new(CommunicationType::CallInvite) + let forward = CommunicationValue::new(CommunicationType::call_invite) .with_receiver(receiver_id as u64) .with_sender(sender_id as u64) - .add_typed_default(DataType::CallSecret, cv.get_data(DataType::CallSecret).clone()) - .add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())) - .add_typed_default(DataType::ReceiverId, DataValue::SignedNumber(receiver_id.into())) - .add_typed_default(DataType::SenderId, DataValue::SignedNumber(sender_id.into())); + .add_data( + DataTypes::call_secret, + cv.get_data(DataTypes::call_secret).clone(), + ) + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())) + .add_data(DataTypes::receiver_id, DataValue::Number(receiver_id)) + .add_data(DataTypes::sender_id, DataValue::Number(sender_id)); target_rho.message_to_client(forward).await; - let response = CommunicationValue::new(CommunicationType::Success).with_id(cv.get_id()); + let response = CommunicationValue::new(CommunicationType::success).with_id(cv.get_id()); self.send_message(&response).await; } @@ -374,32 +414,32 @@ impl ClientConnection { async fn handle_get_call(self: Arc, cv: CommunicationValue) { let user_id = self.get_user_id().await; - let call_id = match cv.get_data(DataType::CallId) { + let call_id = match cv.get_data(DataTypes::call_id) { DataValue::Str(id_str) => match Uuid::parse_str(id_str.as_str()) { Ok(id) => id, Err(_) => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; } }, _ => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNoCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_no_call_id) .await; return; } }; if let Some(token) = call_manager::get_call_token(user_id, call_id).await { - let response = CommunicationValue::new(CommunicationType::CallToken) + let response = CommunicationValue::new(CommunicationType::call_token) .with_id(cv.get_id()) .with_receiver(user_id as u64) - .add_typed_default(DataType::CallToken, DataValue::Str(token)); + .add_data(DataTypes::call_token, DataValue::Str(token)); self.send_message(&response).await; } else { - let error_cv = CommunicationValue::new(CommunicationType::ErrorNoCallId) + let error_cv = CommunicationValue::new(CommunicationType::error_no_call_id) .with_id(cv.get_id()) - .add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())); + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())); self.send_message(&error_cv).await; return; } @@ -407,17 +447,17 @@ impl ClientConnection { async fn handle_get_call_data(self: Arc, cv: CommunicationValue) { let user_id = self.get_user_id().await; - let call_id = match cv.get_data(DataType::CallId) { + let call_id = match cv.get_data(DataTypes::call_id) { DataValue::Str(id_str) => match Uuid::parse_str(id_str.as_str()) { Ok(id) => id, Err(_) => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; } }, _ => { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNoCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_no_call_id) .await; return; } @@ -429,75 +469,75 @@ impl ClientConnection { let members = call.members.read().await.clone(); for member in members { if member.user_id == user_id { - user_ids.push(DataValue::SignedNumber(member.user_id.into())); + user_ids.push(DataValue::Number(member.user_id as i64)); } } - let response = CommunicationValue::new(CommunicationType::CallData) + let response = CommunicationValue::new(CommunicationType::call_data) .with_id(cv.get_id()) .with_receiver(user_id as u64) - .add_typed_default(DataType::UserIds, DataValue::Array(user_ids)); + .add_data(DataTypes::user_ids, DataValue::Array(user_ids)); self.send_message(&response).await; } else { - let error_cv = CommunicationValue::new(CommunicationType::ErrorInvalidUserId) + let error_cv = CommunicationValue::new(CommunicationType::error_invalid_user_id) .with_id(cv.get_id()) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id.into())); + .add_data(DataTypes::user_id, DataValue::Number(user_id as i64)); self.send_message(&error_cv).await; return; } } else { - let error_cv = CommunicationValue::new(CommunicationType::ErrorNotFound) + let error_cv = CommunicationValue::new(CommunicationType::error_not_found) .with_id(cv.get_id()) - .add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())); + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())); self.send_message(&error_cv).await; return; } } async fn handle_call_timeout_user(self: Arc, cv: CommunicationValue) { - let Ok(call_id) = Uuid::from_str(cv.get_data(DataType::CallId).as_str().unwrap_or("")) + let Ok(call_id) = Uuid::from_str(cv.get_data(DataTypes::call_id).as_str().unwrap_or("")) else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; }; - let user_id = cv.get_data(DataType::UserId).as_signed_number().unwrap_or(0); - let untill = cv.get_data(DataType::Untill).as_signed_number().unwrap_or(0); + let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0); + let untill = cv.get_data(DataTypes::untill).as_number().unwrap_or(0); let Some(call) = call_manager::get_call(call_id).await else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNotFound) + self.send_error_response(cv.get_id(), CommunicationType::error_not_found) .await; return; }; let Some(caller) = call.get_caller(self.get_user_id().await).await else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidUserId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_user_id) .await; return; }; if caller.has_admin() { let _ = call_util::remove_participant(call_id, user_id as u64).await; if let Some(target) = call.get_caller(user_id as u64).await { - target.set_timeout(untill as i64).await; + target.set_timeout(untill).await; } } } async fn handle_call_disconnect_user(self: Arc, cv: CommunicationValue) { - let Ok(call_id) = Uuid::from_str(cv.get_data(DataType::CallId).as_str().unwrap_or("")) + let Ok(call_id) = Uuid::from_str(cv.get_data(DataTypes::call_id).as_str().unwrap_or("")) else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; }; - let user_id = cv.get_data(DataType::UserId).as_signed_number().unwrap_or(0); + let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0); let Some(call) = call_manager::get_call(call_id).await else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorNotFound) + self.send_error_response(cv.get_id(), CommunicationType::error_not_found) .await; return; }; let Some(caller) = call.get_caller(self.get_user_id().await).await else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidUserId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_user_id) .await; return; }; @@ -506,13 +546,13 @@ impl ClientConnection { } } async fn handle_call_set_anonymous_joining(self: Arc, cv: CommunicationValue) { - let Ok(call_id) = Uuid::from_str(cv.get_data(DataType::CallId).as_str().unwrap_or("")) + let Ok(call_id) = Uuid::from_str(cv.get_data(DataTypes::call_id).as_str().unwrap_or("")) else { - self.send_error_response(cv.get_id(), CommunicationType::ErrorInvalidCallId) + self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) .await; return; }; - let enable = cv.get_data(DataType::Enabled).as_bool().unwrap_or(true); + let enable = cv.get_data(DataTypes::enabled).as_bool().unwrap_or(true); let call = call_manager::get_call(call_id).await; @@ -525,18 +565,19 @@ impl ClientConnection { } short_link = call.get_short_link().await; } - let mut response_cv = CommunicationValue::new(CommunicationType::CallSetAnonymousJoining) - .with_id(cv.get_id()) - .add_typed_default(DataType::CallId, DataValue::Str(call_id.to_string())) - .add_typed_default(DataType::Enabled, DataValue::Bool(enable)); + let mut response_cv = + CommunicationValue::new(CommunicationType::call_set_anonymous_joining) + .with_id(cv.get_id()) + .add_data(DataTypes::call_id, DataValue::Str(call_id.to_string())) + .add_data(DataTypes::enabled, DataValue::Bool(enable)); if let Some(short_link) = short_link { - response_cv = response_cv.add_typed_default(DataType::Link, DataValue::Str(short_link)); + response_cv = response_cv.add_data(DataTypes::link, DataValue::Str(short_link)); } self.send_message(&response_cv).await; } async fn handle_load_txt_record(self: Arc, cv: CommunicationValue) { - if let Some(path) = cv.get_data(DataType::Path).as_str() { + if let Some(path) = cv.get_data(DataTypes::path).as_str() { if let Ok(builder) = hickory_resolver::Resolver::builder_tokio() { let resolver = builder.build(); if let Ok(lookup) = resolver.txt_lookup(path).await { @@ -544,9 +585,12 @@ impl ClientConnection { for txt_data in record.txt_data() { if let Ok(s) = std::str::from_utf8(txt_data) { let response = - CommunicationValue::new(CommunicationType::LoadTxtRecord) + CommunicationValue::new(CommunicationType::load_txt_record) .with_id(cv.get_id()) - .add_typed_default(DataType::Content, DataValue::Str(s.to_string())); + .add_data( + DataTypes::content, + DataValue::Str(s.to_string()), + ); self.send_message(&response).await; return; } @@ -555,10 +599,10 @@ impl ClientConnection { } } } - let path_data = cv.get_data(DataType::Path).clone(); - let error_cv = CommunicationValue::new(CommunicationType::ErrorNotFound) + let path_data = cv.get_data(DataTypes::path).clone(); + let error_cv = CommunicationValue::new(CommunicationType::error_not_found) .with_id(cv.get_id()) - .add_typed_default(DataType::Path, path_data); + .add_data(DataTypes::path, path_data); self.send_message(&error_cv).await; } @@ -578,11 +622,14 @@ impl ClientConnection { cv.get_receiver() ); - if cv.is_type(CommunicationType::AddConversation) - && cv.get_data(DataType::ChatPartnerId).as_signed_number().is_none() + if cv.is_type(CommunicationType::add_conversation) + && cv + .get_data(DataTypes::chat_partner_id) + .as_number() + .is_none() { let chat_partner_name = cv - .get_data(DataType::ChatPartnerName) + .get_data(DataTypes::chat_partner_name) .as_str() .unwrap_or("") .to_string(); @@ -591,22 +638,25 @@ impl ClientConnection { .await .is_some() { - self.send_error_response(cv.get_id(), CommunicationType::ErrorAnonymous) + self.send_error_response(cv.get_id(), CommunicationType::error_anonymous) .await; return; } let load_uuid_response = get_omega_connection() .await_response( - &CommunicationValue::new(CommunicationType::GetUserData) + &CommunicationValue::new(CommunicationType::get_user_data) .with_id(cv.clone().get_id()) - .add_typed_default(DataType::Username, DataValue::Str(chat_partner_name.clone())), + .add_data( + DataTypes::username, + DataValue::Str(chat_partner_name.clone()), + ), Some(Duration::from_secs(20)), ) .await; let chat_partner_id = { if let Ok(load_uuid_response) = load_uuid_response { - load_uuid_response.get_data(DataType::UserId).clone() + load_uuid_response.get_data(DataTypes::user_id).clone() } else { DataValue::Null } @@ -625,7 +675,7 @@ impl ClientConnection { let updated_cv = cv .with_sender(sender_user_id as u64) - .add_typed_default(DataType::ChatPartnerId, chat_partner_id); + .add_data(DataTypes::chat_partner_id, chat_partner_id); rho_conn.message_to_iota(updated_cv).await; } else { log_err!( @@ -663,9 +713,9 @@ impl ClientConnection { msg_type, msg_id ); - let error_cv = CommunicationValue::new(CommunicationType::ErrorNoIota) + let error_cv = CommunicationValue::new(CommunicationType::error_no_iota) .with_id(msg_id) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(sender_user_id.into())); + .add_data(DataTypes::user_id, DataValue::Number(sender_user_id as i64)); self.send_message(&error_cv).await; } } @@ -708,9 +758,9 @@ impl ClientConnection { } else { user_status }; - let notification = CommunicationValue::new(CommunicationType::ClientChanged) - .add_typed_default(DataType::UserId, DataValue::Str(user_id.to_string())) - .add_typed_default(DataType::UserState, DataValue::Str(status.to_string())); + let notification = CommunicationValue::new(CommunicationType::client_changed) + .add_data(DataTypes::user_id, DataValue::Str(user_id.to_string())) + .add_data(DataTypes::user_state, DataValue::Str(status.to_string())); self.send_message(¬ification).await; } @@ -735,7 +785,6 @@ impl Clone for ClientConnection { receiver: Arc::clone(&self.receiver), user_id: self.user_id, session_id: self.session_id, - client_version: self.client_version.clone(), ping: Arc::clone(&self.ping), pub_key: Arc::clone(&self.pub_key), rho_connection: Arc::clone(&self.rho_connection), diff --git a/src/rho/connection.rs b/src/rho/connection.rs index f6aeeda..5cac1fa 100755 --- a/src/rho/connection.rs +++ b/src/rho/connection.rs @@ -1,8 +1,8 @@ -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataTypeId, DataValue}; -use mtp::transport::{Receiver, Sender}; use rand::{Rng, distributions::Alphanumeric}; use std::{collections::BTreeMap, collections::HashMap, sync::Arc, time::Duration}; use tokio::sync::RwLock; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; +use ttp_native::{Receiver, Sender}; use uuid::Uuid; use crate::{ @@ -45,7 +45,6 @@ pub struct GeneralConnection { pub session_id: Arc>, pub app_identifier: Arc>>, pub app_session: Arc>>, - pub client_version: Arc>, pub_key: Arc>>>, } @@ -64,7 +63,6 @@ impl GeneralConnection { session_id: Arc::new(RwLock::new(0)), app_identifier: Arc::new(RwLock::new(None)), app_session: Arc::new(RwLock::new(None)), - client_version: Arc::new(RwLock::new(mtp::codec::PROTOCOL_VERSION.to_string())), pub_key: Arc::new(RwLock::new(None)), }) } @@ -97,31 +95,26 @@ impl GeneralConnection { log_out!(0, PrintType::General, "General connection handler stopped"); } async fn handle_identification(self: &Arc, cv: CommunicationValue) { - if let Some(version) = cv.get_data(DataType::Version).as_str() { - *self.client_version.write().await = version.to_string(); - } - - if cv.is_type(CommunicationType::RegisterIota) { - if let DataValue::Str(pub_key) = cv.get_data(DataType::PublicKey) { - let msg = CommunicationValue::new(CommunicationType::CompleteRegisterIota) - .add_typed_default(DataType::PublicKey, DataValue::Str(pub_key.clone())); + if cv.is_type(CommunicationType::register_iota) { + if let DataValue::Str(pub_key) = cv.get_data(DataTypes::public_key) { + let msg = CommunicationValue::new(CommunicationType::complete_register_iota) + .add_data(DataTypes::public_key, DataValue::Str(pub_key.clone())); let response = get_omega_connection() .await_response(&msg, Some(Duration::from_secs(20))) .await; if let Ok(response_cv) = response { - if let DataValue::SignedNumber(iota_id) = response_cv.get_data(DataType::IotaId) - { - let success_msg = CommunicationValue::new(CommunicationType::Success) + if let DataValue::Number(iota_id) = response_cv.get_data(DataTypes::iota_id) { + let success_msg = CommunicationValue::new(CommunicationType::success) .with_id(cv.get_id()) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(*iota_id)); + .add_data(DataTypes::iota_id, DataValue::Number(*iota_id)); log_cv_out!(success_msg); let _ = self.sender.send(&success_msg).await; } else { let err_msg = - CommunicationValue::new(CommunicationType::ErrorInvalidOmikronId) + CommunicationValue::new(CommunicationType::error_invalid_omikron_id) .with_id(cv.get_id()); let _ = self.sender.send(&err_msg).await; } @@ -130,16 +123,19 @@ impl GeneralConnection { return; } - if cv.is_type(CommunicationType::AppIdentification) { + if cv.is_type(CommunicationType::app_identification) { let app_identifier = cv - .get_data(DataType::AppIdentifier) + .get_data(DataTypes::app_identifier) .as_str() .unwrap_or("") .to_string(); - let app_session_id_str = cv.get_data(DataType::AppSession).as_str().unwrap_or(""); + let app_session_id_str = cv.get_data(DataTypes::app_session).as_str().unwrap_or(""); let app_session_id = Uuid::parse_str(app_session_id_str).unwrap_or(Uuid::new_v4()); - let pub_key_str = cv.get_data(DataType::AppPublicKey).as_str().unwrap_or(""); - let user_id = cv.get_data(DataType::UserId).as_number().unwrap_or(0); + let pub_key_str = cv + .get_data(DataTypes::app_public_key) + .as_str() + .unwrap_or(""); + let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0); *self.id.write().await = user_id as u64; *self.app_identifier.write().await = Some(app_identifier); @@ -168,29 +164,29 @@ impl GeneralConnection { .unwrap() .export(DataFormat::Base64); - let response = CommunicationValue::new(CommunicationType::AppChallenge) + let response = CommunicationValue::new(CommunicationType::app_challenge) .with_id(cv.get_id()) - .add_typed_default( - DataType::PublicKey, + .add_data( + DataTypes::public_key, DataValue::Str(public_key_to_base64(&get_public_key())), ) - .add_typed_default(DataType::Challenge, DataValue::Str(encrypted_challenge)); + .add_data(DataTypes::challenge, DataValue::Str(encrypted_challenge)); log_cv_out!(response); let _ = self.sender.send(&response).await; return; } - if !cv.is_type(CommunicationType::Identification) { + if !cv.is_type(CommunicationType::identification) { return; } - if let DataValue::SignedNumber(iota_id) = cv.get_data(DataType::IotaId) { + if let DataValue::Number(iota_id) = cv.get_data(DataTypes::iota_id) { *self.id.write().await = *iota_id as u64; *self.connection_kind.write().await = Some(ConnectionKind::Iota); - let get_pub_key_msg = CommunicationValue::new(CommunicationType::GetIotaData) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(*iota_id)); + let get_pub_key_msg = CommunicationValue::new(CommunicationType::get_iota_data) + .add_data(DataTypes::iota_id, DataValue::Number(*iota_id)); let response_cv = get_omega_connection() .await_response(&get_pub_key_msg, Some(Duration::from_secs(20))) @@ -200,7 +196,7 @@ impl GeneralConnection { Ok(r) => r, Err(_) => { log_err!( - *iota_id as i64, + *iota_id, PrintType::Iota, "Failed to get Iota data from Omega for iota_id={}", iota_id @@ -210,7 +206,7 @@ impl GeneralConnection { }; let base64_pub = response_cv - .get_data(DataType::PublicKey) + .get_data(DataTypes::public_key) .as_str() .unwrap_or(""); @@ -218,7 +214,7 @@ impl GeneralConnection { Some(pk) => pk, None => { log_err!( - *iota_id as i64, + *iota_id, PrintType::Iota, "Failed to load public key for iota_id={}", iota_id @@ -245,48 +241,48 @@ impl GeneralConnection { .unwrap() .export(DataFormat::Base64); - 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(public_key_to_base64(&get_public_key())), ) - .add_typed_default(DataType::Challenge, DataValue::Str(encrypted_challenge)); + .add_data(DataTypes::challenge, DataValue::Str(encrypted_challenge)); log_cv_out!(response); let _ = self.sender.send(&response).await; - } else if let DataValue::SignedNumber(user_id) = cv.get_data(DataType::UserId) { + } else if let DataValue::Number(user_id) = cv.get_data(DataTypes::user_id) { *self.id.write().await = *user_id as u64; - *self.session_id.write().await = match cv.get_data(DataType::SessionId) { - DataValue::SignedNumber(s) => *s as u64, + *self.session_id.write().await = match cv.get_data(DataTypes::session_id) { + DataValue::Number(s) => *s as u64, _ => cv.get_sender(), }; #[allow(unused_assignments)] let mut base64_pub = String::new(); - if cv.is_type(CommunicationType::AppIdentification) { + if cv.is_type(CommunicationType::app_identification) { *self.connection_kind.write().await = Some(ConnectionKind::Phi); - if let DataValue::Str(app_id) = cv.get_data(DataType::AppIdentifier) { + if let DataValue::Str(app_id) = cv.get_data(DataTypes::app_identifier) { *self.app_identifier.write().await = Some(app_id.clone()); } - if let DataValue::Str(app_sess) = cv.get_data(DataType::AppSession) { + if let DataValue::Str(app_sess) = cv.get_data(DataTypes::app_session) { if let Ok(uuid) = uuid::Uuid::parse_str(&app_sess) { *self.app_session.write().await = Some(uuid); } } base64_pub = cv - .get_data(DataType::AppPublicKey) + .get_data(DataTypes::app_public_key) .as_str() .unwrap_or("") .to_string(); } else { *self.connection_kind.write().await = Some(ConnectionKind::Client); - let get_pub_key_msg = CommunicationValue::new(CommunicationType::GetUserData) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(*user_id)); + let get_pub_key_msg = CommunicationValue::new(CommunicationType::get_user_data) + .add_data(DataTypes::user_id, DataValue::Number(*user_id)); let response_cv = get_omega_connection() .await_response(&get_pub_key_msg, Some(Duration::from_secs(20))) @@ -300,7 +296,7 @@ impl GeneralConnection { }; base64_pub = response_cv - .get_data(DataType::PublicKey) + .get_data(DataTypes::public_key) .as_str() .unwrap_or("") .to_string(); @@ -331,20 +327,20 @@ impl GeneralConnection { .unwrap() .export(DataFormat::Base64); - let challenge_type = if cv.is_type(CommunicationType::AppIdentification) { - CommunicationType::AppChallenge + let challenge_type = if cv.is_type(CommunicationType::app_identification) { + CommunicationType::app_challenge } else { - CommunicationType::Challenge + CommunicationType::challenge }; let response = CommunicationValue::new(challenge_type) .with_id(cv.get_id()) .with_receiver(*self.session_id.read().await) - .add_typed_default( - DataType::PublicKey, + .add_data( + DataTypes::public_key, DataValue::Str(public_key_to_base64(&get_public_key())), ) - .add_typed_default(DataType::Challenge, DataValue::Str(encrypted_challenge)); + .add_data(DataTypes::challenge, DataValue::Str(encrypted_challenge)); log_cv_out!(response); let _ = self.sender.send(&response).await; @@ -353,13 +349,13 @@ impl GeneralConnection { async fn handle_challenge_response(self: &Arc, cv: CommunicationValue) { let id = *self.id.read().await as i64; - if !cv.is_type(CommunicationType::ChallengeResponse) - && !cv.is_type(CommunicationType::AppChallengeResponse) + if !cv.is_type(CommunicationType::challenge_response) + && !cv.is_type(CommunicationType::app_challenge_response) { return; } - if let DataValue::Str(response) = cv.get_data(DataType::Challenge) { + if let DataValue::Str(response) = cv.get_data(DataTypes::challenge) { let expected = self.challenge.read().await.clone(); if *response == expected { @@ -373,10 +369,10 @@ impl GeneralConnection { expected, response ); - let err_msg = CommunicationValue::new(CommunicationType::ErrorInvalidChallenge) + let err_msg = CommunicationValue::new(CommunicationType::error_invalid_challenge) .with_id(cv.get_id()) - .add_typed_default( - DataType::Message, + .add_data( + DataTypes::message, DataValue::Str( "Challenge response mismatch; authentication rejected".to_string(), ), @@ -403,8 +399,8 @@ impl GeneralConnection { match kind { ConnectionKind::Client => { - let notify = CommunicationValue::new(CommunicationType::UserConnected) - .add_typed_default(DataType::UserId, DataValue::SignedNumber((id as i64).into())); + let notify = CommunicationValue::new(CommunicationType::user_connected) + .add_data(DataTypes::user_id, DataValue::Number(id as i64)); get_omega_connection().send_message(¬ify).await; let user_id = id as i64; @@ -414,18 +410,18 @@ impl GeneralConnection { let mut rho = rho_manager::get_rho_con_for_user(user_id).await; if rho.is_none() { - let get_user_msg = CommunicationValue::new(CommunicationType::GetUserData) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id.into())); + let get_user_msg = CommunicationValue::new(CommunicationType::get_user_data) + .add_data(DataTypes::user_id, DataValue::Number(user_id)); if let Ok(user_data_cv) = get_omega_connection() .await_response(&get_user_msg, Some(Duration::from_secs(20))) .await { - if let DataValue::SignedNumber(iota_id) = - user_data_cv.get_data(DataType::IotaId) + if let DataValue::Number(iota_id) = + user_data_cv.get_data(DataTypes::iota_id) { if let Some(bound_rho) = - rho_manager::bind_user_to_iota(user_id, *iota_id as i64).await + rho_manager::bind_user_to_iota(user_id, *iota_id).await { bound_rho.bind_user_id(user_id).await; rho = Some(bound_rho); @@ -438,9 +434,9 @@ impl GeneralConnection { if let Some(rho_conn) = rho { let session_id = *self.session_id.read().await as i64; - let iota_msg = CommunicationValue::new(CommunicationType::ClientConnected) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id.into())) - .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id.into())); + let iota_msg = CommunicationValue::new(CommunicationType::client_connected) + .add_data(DataTypes::user_id, DataValue::Number(user_id)) + .add_data(DataTypes::session_id, DataValue::Number(session_id)); if let Ok(resp) = rho_conn .get_iota_connection() @@ -449,11 +445,10 @@ impl GeneralConnection { .await { let mut ident_resp = - CommunicationValue::new(CommunicationType::IdentificationResponse) + CommunicationValue::new(CommunicationType::identification_response) .with_id(*self.challenge_cv_id.read().await); - let tm = mtp::codec::TypeMap::latest(); - for (k, v) in resp.iter_typed_data() { - let value_to_add = if k == Some(DataType::Contacts) { + for (k, v) in resp.get_data_container() { + let value_to_add = if k == &DataTypes::contacts { if let Some(contacts) = v.as_array() { let call_groups = call_manager::get_call_groups(user_id as u64).await; @@ -473,30 +468,30 @@ impl GeneralConnection { // List of all members in the call let member_ids: Vec = members .iter() - .map(|m| DataValue::SignedNumber(m.user_id.into())) + .map(|m| DataValue::Number(m.user_id as i64)) .collect(); - let mut base_call_map: BTreeMap = + let mut base_call_map: BTreeMap = BTreeMap::new(); base_call_map.insert( - DataType::CallId.to_id(&tm), + DataTypes::call_id, DataValue::Str(call.call_id.to_string()), ); base_call_map.insert( - DataType::CallMembers.to_id(&tm), + DataTypes::call_members, DataValue::Array(member_ids), ); if timeout > 0 { base_call_map.insert( - DataType::Timeout.to_id(&tm), - DataValue::SignedNumber((timeout as i64).into()), + DataTypes::timeout, + DataValue::Number(timeout as i64), ); } if admin { base_call_map.insert( - DataType::HasAdmin.to_id(&tm), + DataTypes::has_admin, DataValue::Bool(true), ); } @@ -521,7 +516,7 @@ impl GeneralConnection { .get(&(member_id, user_id as u64)) { contact_call_map.insert( - DataType::CallSecret.to_id(&tm), + DataTypes::call_secret, DataValue::Str(secret.clone()), ); } @@ -539,12 +534,12 @@ impl GeneralConnection { let mut new_contacts: Vec = Vec::new(); for contact in contacts { if let Some(mut contact_map) = contact.as_map() { - if let Some(DataValue::SignedNumber(id)) = - contact_map.get(&DataType::UserId.to_id(&tm)) + if let Some(DataValue::Number(id)) = + contact_map.get(&DataTypes::user_id) { - if let Some(call_list) = invites.get(&(*id as i64)) { + if let Some(call_list) = invites.get(id) { contact_map.insert( - DataType::Calls.to_id(&tm), + DataTypes::calls, DataValue::Array(call_list.clone()), ); } @@ -557,7 +552,7 @@ impl GeneralConnection { } ident_resp = ident_resp - .add_typed_default(DataType::Calls, DataValue::Array(global_calls)); + .add_data(DataTypes::calls, DataValue::Array(global_calls)); DataValue::Array(new_contacts) } else { v.clone() @@ -566,9 +561,7 @@ impl GeneralConnection { v.clone() }; - if let Some(dt) = k { - ident_resp = ident_resp.add_typed_default(dt, value_to_add); - } + ident_resp = ident_resp.add_data(k.clone(), value_to_add); } log_cv_out!(ident_resp); let _ = self.sender.send(&ident_resp).await; @@ -587,8 +580,8 @@ impl GeneralConnection { client.start(); } ConnectionKind::Iota => { - let notify = CommunicationValue::new(CommunicationType::IotaConnected) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(id.into())); + let notify = CommunicationValue::new(CommunicationType::iota_connected) + .add_data(DataTypes::iota_id, DataValue::Number(id as i64)); get_omega_connection().send_message(¬ify).await; let iota = IotaConnection::from_general(self.clone(), id).await; @@ -599,17 +592,17 @@ impl GeneralConnection { rho_manager::add_rho(rho).await; - let get_iota_msg = CommunicationValue::new(CommunicationType::GetIotaData) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(id.into())); + let get_iota_msg = CommunicationValue::new(CommunicationType::get_iota_data) + .add_data(DataTypes::iota_id, DataValue::Number(id as i64)); if let Ok(iota_data_cv) = get_omega_connection() .await_response(&get_iota_msg, Some(Duration::from_secs(20))) .await { - if let DataValue::Array(users) = iota_data_cv.get_data(DataType::UserIds) { + if let DataValue::Array(users) = iota_data_cv.get_data(DataTypes::user_ids) { let mut user_ids: Vec = Vec::new(); for value in users { - if let DataValue::SignedNumber(user_id) = value { + if let DataValue::Number(user_id) = value { user_ids.push(*user_id as u64); } } @@ -617,9 +610,10 @@ impl GeneralConnection { } } - let ident_resp = CommunicationValue::new(CommunicationType::IdentificationResponse) - .with_id(*self.challenge_cv_id.read().await) - .add_typed_default(DataType::Accepted, DataValue::Bool(true)); + let ident_resp = + CommunicationValue::new(CommunicationType::identification_response) + .with_id(*self.challenge_cv_id.read().await) + .add_data(DataTypes::accepted, DataValue::Bool(true)); log_cv_out!(ident_resp); let _ = self.sender.send(&ident_resp).await; @@ -635,18 +629,18 @@ impl GeneralConnection { let mut rho = rho_manager::get_rho_con_for_user(user_id).await; if rho.is_none() { - let get_user_msg = CommunicationValue::new(CommunicationType::GetUserData) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id.into())); + let get_user_msg = CommunicationValue::new(CommunicationType::get_user_data) + .add_data(DataTypes::user_id, DataValue::Number(user_id)); if let Ok(user_data_cv) = get_omega_connection() .await_response(&get_user_msg, Some(Duration::from_secs(20))) .await { - if let DataValue::SignedNumber(iota_id) = - user_data_cv.get_data(DataType::IotaId) + if let DataValue::Number(iota_id) = + user_data_cv.get_data(DataTypes::iota_id) { if let Some(bound_rho) = - rho_manager::bind_user_to_iota(user_id, *iota_id as i64).await + rho_manager::bind_user_to_iota(user_id, *iota_id).await { bound_rho.bind_user_id(user_id).await; rho = Some(bound_rho); @@ -665,7 +659,7 @@ impl GeneralConnection { } let response = - CommunicationValue::new(CommunicationType::AppIdentificationResponse) + CommunicationValue::new(CommunicationType::app_identification_response) .with_id(*self.challenge_cv_id.read().await) .with_receiver(*self.session_id.read().await); diff --git a/src/rho/iota_connection.rs b/src/rho/iota_connection.rs index 6839f1f..187c584 100755 --- a/src/rho/iota_connection.rs +++ b/src/rho/iota_connection.rs @@ -8,18 +8,16 @@ use crate::omega::omega_connection::get_omega_connection; use crate::rho::connection::GeneralConnection; use crate::util::logger::PrintType; use dashmap::DashMap; -use mtp::codec::CommunicationType; -use mtp::codec::CommunicationValue; -use mtp::codec::DataType; -use mtp::codec::DataTypeId; -use mtp::codec::DataValue; -use mtp::codec::TypeMap; -use mtp::transport::Receiver; -use mtp::transport::Sender; use std::collections::BTreeMap; use std::{collections::HashMap, sync::Arc, time::Duration}; use tokio::sync::RwLock; use tokio::sync::mpsc; +use ttp_core::CommunicationType; +use ttp_core::CommunicationValue; +use ttp_core::DataTypes; +use ttp_core::DataValue; +use ttp_native::Receiver; +use ttp_native::Sender; use x448::PublicKey; use super::{rho_connection::RhoConnection, rho_manager}; @@ -28,7 +26,6 @@ use crate::omega::omega_connection::OmegaConnection; #[allow(dead_code)] pub struct IotaConnection { pub iota_id: u64, - pub client_version: String, pub sender: Arc, pub receiver: Arc, pub user_ids: Arc>>, @@ -49,7 +46,6 @@ impl IotaConnection { sender: general.sender.clone(), receiver: general.receiver.clone(), iota_id: iota_id, - client_version: general.client_version.read().await.clone(), waiting_tasks: DashMap::new(), }) } @@ -145,7 +141,7 @@ impl IotaConnection { /// Send a CommunicationValue to the Iota pub async fn send_message(&self, cv: &CommunicationValue) { - if !cv.is_type(CommunicationType::Pong) { + if !cv.is_type(CommunicationType::pong) { log_cv_out!(PrintType::Iota, cv); } if let Err(e) = self.sender.send(&cv).await { @@ -168,7 +164,7 @@ impl IotaConnection { } // Handle ping - if cv.is_type(CommunicationType::Ping) || cv.is_type(CommunicationType::Pong) { + if cv.is_type(CommunicationType::ping) || cv.is_type(CommunicationType::pong) { self.handle_ping(cv).await; return; } @@ -176,7 +172,7 @@ impl IotaConnection { log_cv_in!(PrintType::Iota, cv); // Handle GET_CHATS - if cv.is_type(CommunicationType::GetChats) { + if cv.is_type(CommunicationType::get_chats) { self.handle_get_chats(cv).await; return; } @@ -184,14 +180,14 @@ impl IotaConnection { // Handle forwarding to other Iotas or clients let receiver_id = cv.get_receiver(); if (receiver_id != 0 && !self.get_user_ids().await.contains(&(receiver_id as u64))) - || cv.is_type(CommunicationType::MessageOtherIota) - || cv.is_type(CommunicationType::SendChat) + || cv.is_type(CommunicationType::message_other_iota) + || cv.is_type(CommunicationType::send_chat) { self.handle_forward_message(cv).await; return; } - if cv.is_type(CommunicationType::CompleteRegisterUser) { + if cv.is_type(CommunicationType::complete_register_user) { let response_cv = get_omega_connection() .await_response( &cv.clone().with_sender(self.iota_id), @@ -199,8 +195,8 @@ impl IotaConnection { ) .await; if let Ok(response_cv) = response_cv { - if response_cv.is_type(CommunicationType::Success) { - if let Some(user_id) = cv.get_data(DataType::UserId).as_number() { + if response_cv.is_type(CommunicationType::success) { + if let Some(user_id) = cv.get_data(DataTypes::user_id).as_number() { self.add_user_id(user_id as u64).await; } } @@ -209,12 +205,12 @@ impl IotaConnection { return; } - if cv.is_type(CommunicationType::ChangeIotaData) - || cv.is_type(CommunicationType::PushNotification) - || cv.is_type(CommunicationType::GetUserData) - || cv.is_type(CommunicationType::GetIotaData) - || cv.is_type(CommunicationType::GetRegister) - || cv.is_type(CommunicationType::DeleteIota) + if cv.is_type(CommunicationType::change_iota_data) + || cv.is_type(CommunicationType::push_notification) + || cv.is_type(CommunicationType::get_user_data) + || cv.is_type(CommunicationType::get_iota_data) + || cv.is_type(CommunicationType::get_register) + || cv.is_type(CommunicationType::delete_iota) { let sender = self.get_iota_id().await; @@ -247,7 +243,7 @@ impl IotaConnection { } /// Handle ping message async fn handle_ping(&self, cv: CommunicationValue) { - if let DataValue::SignedNumber(last_ping) = cv.get_data(DataType::LastPing) { + if let DataValue::Number(last_ping) = cv.get_data(DataTypes::last_ping) { if let Ok(ping_val) = last_ping.to_string().parse::() { let mut ping_guard = self.ping.write().await; *ping_guard = ping_val; @@ -260,21 +256,13 @@ impl IotaConnection { HashMap::new() }; - let tm = TypeMap::latest(); - let pings: Vec = client_pings + let pings: Vec<(DataTypes, DataValue)> = client_pings .into_iter() - .map(|(k, v)| { - let mut map = BTreeMap::new(); - if let Ok(uid) = k.parse::() { - map.insert(DataType::UserId.to_id(&tm), DataValue::SignedNumber(uid)); - } - map.insert(DataType::LastPing.to_id(&tm), DataValue::SignedNumber(v.into())); - DataValue::container_from_map(&map) - }) + .map(|(k, v)| (DataTypes::parse(k), DataValue::Number(v))) .collect(); - let response = CommunicationValue::new(CommunicationType::Pong) + let response = CommunicationValue::new(CommunicationType::pong) .with_id(cv.get_id()) - .add_typed_default(DataType::PingClients, DataValue::Array(pings)); + .add_data(DataTypes::ping_clients, DataValue::Container(pings)); self.send_message(&response).await; } @@ -300,7 +288,7 @@ impl IotaConnection { if let Some(target_rho) = rho_manager::get_rho_con_for_user(receiver_id as i64).await { target_rho.message_to_iota(cv).await; } else { - let error = CommunicationValue::new(CommunicationType::ErrorNoIota) + let error = CommunicationValue::new(CommunicationType::error_no_iota) .with_id(cv.get_id()) .with_sender(cv.get_sender()); self.send_message(&error).await; @@ -315,8 +303,8 @@ impl IotaConnection { ); self.send_message( - &CommunicationValue::new(CommunicationType::ErrorInvalidUserId).add_typed_default( - DataType::ErrorType, + &CommunicationValue::new(CommunicationType::error_invalid_user_id).add_data( + DataTypes::error_type, DataValue::Str( "You are sending to another User without authority.".to_string(), ), @@ -342,7 +330,6 @@ impl IotaConnection { } let mut interested_ids: Vec = Vec::new(); - let tm = TypeMap::latest(); // ============================ // Load Calls @@ -366,21 +353,20 @@ impl IotaConnection { // List of all members in the call let member_ids: Vec = members .iter() - .map(|m| DataValue::SignedNumber(m.user_id.into())) + .map(|m| DataValue::Number(m.user_id as i64)) .collect(); // Build base call container - let mut base_call_map: BTreeMap = BTreeMap::new(); - base_call_map.insert(DataType::CallId.to_id(&tm), DataValue::Str(call.call_id.to_string())); - base_call_map.insert(DataType::CallMembers.to_id(&tm), DataValue::Array(member_ids)); + let mut base_call_map: BTreeMap = BTreeMap::new(); + base_call_map.insert(DataTypes::call_id, DataValue::Str(call.call_id.to_string())); + base_call_map.insert(DataTypes::call_members, DataValue::Array(member_ids)); if timeout > 0 { - base_call_map - .insert(DataType::Timeout.to_id(&tm), DataValue::SignedNumber(timeout.into())); + base_call_map.insert(DataTypes::timeout, DataValue::Number(timeout as i64)); } if admin { - base_call_map.insert(DataType::HasAdmin.to_id(&tm), DataValue::Bool(true)); + base_call_map.insert(DataTypes::has_admin, DataValue::Bool(true)); } // Add to global calls (without contact-specific secret) @@ -398,7 +384,7 @@ impl IotaConnection { // Add secret if it exists for this pairing if let Some(secret) = call.secrets.read().await.get(&(member_id, user_id)) { contact_call_map - .insert(DataType::CallSecret.to_id(&tm), DataValue::Str(secret.clone())); + .insert(DataTypes::call_secret, DataValue::Str(secret.clone())); } invites @@ -413,27 +399,27 @@ impl IotaConnection { // Enrich Contacts // ============================ let enriched_contacts = if empty { - match cv.get_data(DataType::UserIds) { + match cv.get_data(DataTypes::user_ids) { DataValue::Array(arr) => DataValue::Array(arr.clone()), _ => DataValue::Array(vec![]), } } else { let mut enriched: Vec = Vec::new(); - if let DataValue::Array(users) = cv.get_data(DataType::UserIds) { + if let DataValue::Array(users) = cv.get_data(DataTypes::user_ids) { for user_val in users { if let DataValue::Container(entries) = user_val { - let mut user_map: BTreeMap = + let mut user_map: BTreeMap = entries.iter().cloned().collect(); - if let Some(DataValue::SignedNumber(id)) = user_map.get(&DataType::UserId.to_id(&tm)) { - interested_ids.push(*id as i64); + if let Some(DataValue::Number(id)) = user_map.get(&DataTypes::user_id) { + interested_ids.push(*id); - if let Some(call_list) = invites.get(&(*id as i64)) + if let Some(call_list) = invites.get(id) && !call_list.is_empty() { user_map - .insert(DataType::Calls.to_id(&tm), DataValue::Array(call_list.clone())); + .insert(DataTypes::calls, DataValue::Array(call_list.clone())); } } @@ -463,8 +449,8 @@ impl IotaConnection { // Forward to client // ============================ self.forward_to_client( - cv.add_typed_default(DataType::UserIds, enriched_contacts) - .add_typed_default(DataType::Calls, DataValue::Array(global_calls)), + cv.add_data(DataTypes::user_ids, enriched_contacts) + .add_data(DataTypes::calls, DataValue::Array(global_calls)), ) .await; } diff --git a/src/rho/rho_connection.rs b/src/rho/rho_connection.rs index e0023a8..d1f192a 100644 --- a/src/rho/rho_connection.rs +++ b/src/rho/rho_connection.rs @@ -2,10 +2,10 @@ use super::{client_connection::ClientConnection, iota_connection::IotaConnection use crate::omega::omega_connection::OmegaConnection; use crate::{data::user::UserStatus, rho::app_connection::AppConnection}; -use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue}; use std::collections::HashMap; use std::sync::Arc; use tokio::sync::RwLock; +use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; use uuid::Uuid; pub struct RhoConnection { @@ -125,8 +125,8 @@ impl RhoConnection { let user_id = connection.user_id as i64; let session_id = connection.session_id as i64; - let notification = CommunicationValue::new(CommunicationType::ClientConnected) - .add_typed_default(DataType::UserId, DataValue::SignedNumber(user_id.into())); + let notification = CommunicationValue::new(CommunicationType::client_connected) + .add_data(DataTypes::user_id, DataValue::Number(user_id)); self.iota_connection.send_message(¬ification).await; @@ -216,14 +216,14 @@ impl RhoConnection { pub async fn message_to_client(&self, cv: CommunicationValue) { let connections = self.client_connections.read().await; let receiver_id = cv.get_receiver(); - let session_id = cv.get_data(DataType::SessionId).as_number(); + let session_id = cv.get_data(DataTypes::session_id).as_number(); for connection in connections.iter() { if connection.user_id != receiver_id { continue; } if let Some(session_id) = session_id { - if connection.session_id as i128 != session_id { + if connection.session_id as i64 != session_id { continue; } } diff --git a/src/rho/server.rs b/src/rho/server.rs index ee3a837..caaf371 100644 --- a/src/rho/server.rs +++ b/src/rho/server.rs @@ -1,4 +1,3 @@ -use std::net::{IpAddr, Ipv4Addr}; use std::time::Duration; use crate::{ @@ -6,7 +5,7 @@ use crate::{ rho::connection::GeneralConnection, util::{file_util::load_file_vec, logger::PrintType}, }; -use mtp::transport::{Host, Policy, SendMode, host}; +use ttp_native::{Host, Policy, SendMode, host}; pub async fn start(port: u16) -> Result<(), Box> { let cert_pem = load_file_vec("certs", "cert.pem").expect("Error loading Pemfile"); @@ -14,7 +13,6 @@ pub async fn start(port: u16) -> Result<(), Box> { let key_pem = load_file_vec("certs", "key.pem").expect("Error loading Keyfile"); let mut host: Host = host( - IpAddr::V4(Ipv4Addr::UNSPECIFIED), port, cert_pem, key_pem, diff --git a/src/util/logger.rs b/src/util/logger.rs index f908151..66f3e8c 100644 --- a/src/util/logger.rs +++ b/src/util/logger.rs @@ -1,4 +1,5 @@ use std::{ + collections::BTreeMap, fs::{self, OpenOptions}, io::Write, sync::{OnceLock, mpsc}, @@ -7,7 +8,7 @@ use std::{ }; use ansi_term::Color; -use mtp::codec::{CommunicationValue, DataTypeId, DataValue, Version}; +use ttp_core::{CommunicationValue, DataTypes, DataValue}; static LOGGER: OnceLock> = OnceLock::new(); @@ -176,19 +177,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)| { @@ -198,12 +197,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) } @@ -212,7 +211,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(), } @@ -222,19 +221,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) } @@ -243,7 +242,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 5cd196f..0000000 --- a/type-maps.yaml +++ /dev/null @@ -1,241 +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 - Challenge: 133