From a0457000ff055d43165aa75fc9c04e3d99c7dfbb Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 May 2021 01:54:24 +0200 Subject: [PATCH 1/2] Upgrade Ruma --- Cargo.lock | 183 ++++++++++++++------------------ Cargo.toml | 9 +- src/client_server/account.rs | 5 +- src/client_server/membership.rs | 12 ++- src/client_server/room.rs | 3 +- src/client_server/tag.rs | 4 +- src/database/rooms.rs | 22 ++-- src/pdu.rs | 2 +- src/server_server.rs | 20 ++-- 9 files changed, 117 insertions(+), 143 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60301bb8..e7506203 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,9 +8,9 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -211,7 +211,6 @@ dependencies = [ "serde_json", "serde_yaml", "sled", - "state-res", "thiserror", "tokio", "tracing", @@ -277,9 +276,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" +checksum = "52fb27eab85b17fbb9f6fd667089e07d6a2eb8743d02639ee7f6a7a7729c9c94" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -290,9 +289,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" +checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -359,18 +358,18 @@ dependencies = [ [[package]] name = "directories" -version = "3.0.1" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fed639d60b58d0f53498ab13d26f621fd77569cc6edb031f4cc36a2ad9da0f" +checksum = "e69600ff1703123957937708eb27f7a564e48885c537782722ed0ba3189ce1d7" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" +checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", "redox_users", @@ -583,17 +582,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.2" @@ -602,7 +590,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -623,9 +611,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" +checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" dependencies = [ "bytes", "fnv", @@ -914,9 +902,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "linked-hash-map" @@ -926,9 +914,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" [[package]] name = "lock_api" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" dependencies = [ "scopeguard", ] @@ -993,9 +981,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "memoffset" @@ -1203,7 +1191,7 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.2.6", + "redox_syscall", "smallvec", "winapi", ] @@ -1401,7 +1389,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.2", + "getrandom", ] [[package]] @@ -1415,28 +1403,21 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - -[[package]] -name = "redox_syscall" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" +checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" dependencies = [ "bitflags", ] [[package]] name = "redox_users" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.1.16", - "redox_syscall 0.1.57", - "rust-argon2", + "getrandom", + "redox_syscall", ] [[package]] @@ -1461,9 +1442,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.6" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", @@ -1482,9 +1463,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.23" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "remove_dir_all" @@ -1634,7 +1615,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.0.3" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "assign", "js_int", @@ -1649,12 +1630,13 @@ dependencies = [ "ruma-push-gateway-api", "ruma-serde", "ruma-signatures", + "ruma-state-res", ] [[package]] name = "ruma-api" version = "0.17.0-alpha.4" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "bytes", "http", @@ -1670,7 +1652,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.17.0-alpha.4" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1681,7 +1663,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.2.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "ruma-api", "ruma-common", @@ -1695,7 +1677,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.10.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "assign", "bytes", @@ -1715,11 +1697,10 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.5.0" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "indexmap", "js_int", - "maplit", "ruma-identifiers", "ruma-serde", "serde", @@ -1731,7 +1712,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.22.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "js_int", "ruma-common", @@ -1745,7 +1726,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.22.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1756,7 +1737,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.1.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "js_int", "ruma-api", @@ -1771,7 +1752,7 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.19.0" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "paste", "rand", @@ -1785,9 +1766,8 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" version = "0.19.0" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ - "proc-macro2", "quote", "ruma-identifiers-validation", "syn", @@ -1796,12 +1776,12 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.3.0" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" [[package]] name = "ruma-identity-service-api" version = "0.1.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "js_int", "ruma-api", @@ -1809,13 +1789,12 @@ dependencies = [ "ruma-identifiers", "ruma-serde", "serde", - "serde_json", ] [[package]] name = "ruma-push-gateway-api" version = "0.1.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "js_int", "ruma-api", @@ -1830,7 +1809,7 @@ dependencies = [ [[package]] name = "ruma-serde" version = "0.3.1" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "bytes", "form_urlencoded", @@ -1844,7 +1823,7 @@ dependencies = [ [[package]] name = "ruma-serde-macros" version = "0.3.1" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1855,7 +1834,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.7.0" -source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" dependencies = [ "base64 0.13.0", "ring", @@ -1865,6 +1844,24 @@ dependencies = [ "untrusted", ] +[[package]] +name = "ruma-state-res" +version = "0.1.0" +source = "git+https://github.com/ruma/ruma?rev=71686ce8a4d1770a80de216080718fe9de7bd925#71686ce8a4d1770a80de216080718fe9de7bd925" +dependencies = [ + "itertools 0.10.0", + "js_int", + "maplit", + "ruma-events", + "ruma-identifiers", + "ruma-serde", + "ruma-signatures", + "serde", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "rust-argon2" version = "0.8.3" @@ -2165,20 +2162,6 @@ dependencies = [ "loom", ] -[[package]] -name = "state-res" -version = "0.1.0" -source = "git+https://github.com/ruma/state-res?rev=c20893e536bea4d17a9fe6af28428fb17169b56f#c20893e536bea4d17a9fe6af28428fb17169b56f" -dependencies = [ - "itertools 0.10.0", - "log", - "maplit", - "ruma", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "stdweb" version = "0.4.20" @@ -2230,9 +2213,9 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" [[package]] name = "syn" -version = "1.0.70" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -2248,7 +2231,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "rand", - "redox_syscall 0.2.6", + "redox_syscall", "remove_dir_all", "winapi", ] @@ -2448,9 +2431,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -2471,9 +2454,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" dependencies = [ "lazy_static", ] @@ -2514,9 +2497,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705096c6f83bf68ea5d357a6aa01829ddbdac531b357b45abeca842938085baa" +checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5" dependencies = [ "ansi_term", "chrono", @@ -2646,9 +2629,9 @@ checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "untrusted" @@ -2658,9 +2641,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", @@ -2684,12 +2667,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index f12420e6..13bcd9b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,16 +15,9 @@ edition = "2018" # Used to handle requests # TODO: This can become optional as soon as proper configs are supported rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests -#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } # Used for matrix spec type definitions and helpers -ruma = { git = "https://github.com/ruma/ruma", rev = "8c286e78d41770fe431e7304cc2fe23e383793df", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } -#ruma = { git = "https://github.com/timokoesters/ruma", rev = "220d5b4a76b3b781f7f8297fbe6b14473b04214b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } -#ruma = { path = "../ruma/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } - -# Used when doing state resolution -state-res = { git = "https://github.com/ruma/state-res", rev = "c20893e536bea4d17a9fe6af28428fb17169b56f", features = ["unstable-pre-spec"] } -#state-res = { path = "../state-res", features = ["unstable-pre-spec"] } +ruma = { git = "https://github.com/ruma/ruma", rev = "71686ce8a4d1770a80de216080718fe9de7bd925", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } # Used for long polling and federation sender, should be the same as rocket::tokio tokio = "1.2.0" diff --git a/src/client_server/account.rs b/src/client_server/account.rs index 6554277e..24b04d59 100644 --- a/src/client_server/account.rs +++ b/src/client_server/account.rs @@ -1,7 +1,4 @@ -use std::{ - collections::BTreeMap, - convert::{TryFrom, TryInto}, -}; +use std::{collections::BTreeMap, convert::TryInto}; use super::{State, DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH}; use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma}; diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index 05501bdb..e31e5826 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -25,9 +25,9 @@ use ruma::{ EventType, }, serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw}, + state_res::{self, EventMap, RoomVersion}, uint, EventId, RoomId, RoomVersionId, ServerName, UserId, }; -use state_res::EventMap; use std::{ collections::{BTreeMap, HashSet}, convert::{TryFrom, TryInto}, @@ -765,9 +765,11 @@ pub async fn invite_helper( }; // If there was no create event yet, assume we are creating a version 6 room right now - let room_version = create_event_content.map_or(RoomVersionId::Version6, |create_event| { - create_event.room_version - }); + let room_version_id = create_event_content + .map_or(RoomVersionId::Version6, |create_event| { + create_event.room_version + }); + let room_version = RoomVersion::new(&room_version_id).expect("room version is supported"); let content = serde_json::to_value(MemberEventContent { avatar_url: None, @@ -863,7 +865,7 @@ pub async fn invite_helper( db.globals.server_name().as_str(), db.globals.keypair(), &mut pdu_json, - &room_version, + &room_version_id, ) .expect("event is valid, we just created it"); diff --git a/src/client_server/room.rs b/src/client_server/room.rs index f8d6ab21..658dfb8b 100644 --- a/src/client_server/room.rs +++ b/src/client_server/room.rs @@ -1,6 +1,5 @@ use super::State; -use crate::client_server::invite_helper; -use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Ruma}; +use crate::{client_server::invite_helper, pdu::PduBuilder, ConduitResult, Database, Error, Ruma}; use log::info; use ruma::{ api::client::{ diff --git a/src/client_server/tag.rs b/src/client_server/tag.rs index 21264a17..63e70ffb 100644 --- a/src/client_server/tag.rs +++ b/src/client_server/tag.rs @@ -31,7 +31,7 @@ pub async fn update_tag_route( tags_event .content .tags - .insert(body.tag.to_string(), body.tag_info.clone()); + .insert(body.tag.clone().into(), body.tag_info.clone()); db.account_data.update( Some(&body.room_id), @@ -65,7 +65,7 @@ pub async fn delete_tag_route( tags: BTreeMap::new(), }, }); - tags_event.content.tags.remove(&body.tag); + tags_event.content.tags.remove(&body.tag.clone().into()); db.account_data.update( Some(&body.room_id), diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 7cee9440..c3599971 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -16,10 +16,10 @@ use ruma::{ }, push::{self, Action, Tweak}, serde::{CanonicalJsonObject, CanonicalJsonValue, Raw}, + state_res::{self, Event, RoomVersion, StateMap}, uint, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, }; use sled::IVec; -use state_res::{Event, StateMap}; use std::{ collections::{BTreeMap, HashMap, HashSet}, @@ -1236,9 +1236,11 @@ impl Rooms { }; // If there was no create event yet, assume we are creating a version 6 room right now - let room_version = create_event_content.map_or(RoomVersionId::Version6, |create_event| { - create_event.room_version - }); + let room_version_id = create_event_content + .map_or(RoomVersionId::Version6, |create_event| { + create_event.room_version + }); + let room_version = RoomVersion::new(&room_version_id).expect("room version is supported"); let auth_events = self.get_auth_events( &room_id, @@ -1326,14 +1328,14 @@ impl Rooms { db.globals.server_name().as_str(), db.globals.keypair(), &mut pdu_json, - &room_version, + &room_version_id, ) .expect("event is valid, we just created it"); // Generate event id pdu.event_id = EventId::try_from(&*format!( "${}", - ruma::signatures::reference_hash(&pdu_json, &room_version) + ruma::signatures::reference_hash(&pdu_json, &room_version_id) .expect("ruma can calculate reference hashes") )) .expect("ruma's reference hashes are valid event ids"); @@ -1868,8 +1870,8 @@ impl Rooms { let (make_leave_response, remote_server) = make_leave_response_and_server?; - let room_version = match make_leave_response.room_version { - Some(room_version) if room_version == RoomVersionId::Version6 => room_version, + let room_version_id = match make_leave_response.room_version { + Some(id @ RoomVersionId::Version6) => id, _ => return Err(Error::BadServerResponse("Room version is not supported")), }; @@ -1900,14 +1902,14 @@ impl Rooms { db.globals.server_name().as_str(), db.globals.keypair(), &mut leave_event_stub, - &room_version, + &room_version_id, ) .expect("event is valid, we just created it"); // Generate event id let event_id = EventId::try_from(&*format!( "${}", - ruma::signatures::reference_hash(&leave_event_stub, &room_version) + ruma::signatures::reference_hash(&leave_event_stub, &room_version_id) .expect("ruma can calculate reference hashes") )) .expect("ruma's reference hashes are valid event ids"); diff --git a/src/pdu.rs b/src/pdu.rs index d66247f7..a593f0b5 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -6,7 +6,7 @@ use ruma::{ AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent, }, serde::{CanonicalJsonObject, CanonicalJsonValue, Raw}, - EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId, + state_res, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId, }; use serde::{Deserialize, Serialize}; use serde_json::json; diff --git a/src/server_server.rs b/src/server_server.rs index 3899239e..fa460bfe 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -35,9 +35,9 @@ use ruma::{ }, serde::Raw, signatures::{CanonicalJsonObject, CanonicalJsonValue}, + state_res::{self, Event, EventMap, RoomVersion, StateMap}, uint, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId, }; -use state_res::{Event, EventMap, StateMap}; use std::{ collections::{btree_map::Entry, BTreeMap, BTreeSet, HashSet}, convert::{TryFrom, TryInto}, @@ -745,12 +745,13 @@ pub fn handle_incoming_pdu<'a>( .deserialize() .map_err(|_| "Invalid PowerLevels event in db.".to_owned())?; - let room_version = create_event_content.room_version; + let room_version_id = &create_event_content.room_version; + let room_version = RoomVersion::new(room_version_id).expect("room version is supported"); let mut val = match ruma::signatures::verify_event( &*pub_key_map.read().map_err(|_| "RwLock is poisoned.")?, &value, - &room_version, + room_version_id, ) { Err(e) => { // Drop @@ -760,7 +761,7 @@ pub fn handle_incoming_pdu<'a>( Ok(ruma::signatures::Verified::Signatures) => { // Redact warn!("Calculated hash does not match: {}", event_id); - match ruma::signatures::redact(&value, &room_version) { + match ruma::signatures::redact(&value, room_version_id) { Ok(obj) => obj, Err(_) => return Err("Redaction failed".to_string()), } @@ -1162,7 +1163,7 @@ pub fn handle_incoming_pdu<'a>( match state_res::StateResolution::resolve( &room_id, - &room_version, + room_version_id, &fork_states .into_iter() .map(|map| { @@ -1718,9 +1719,12 @@ pub fn create_join_event_template_route<'a>( }; // If there was no create event yet, assume we are creating a version 6 room right now - let room_version = create_event_content.map_or(RoomVersionId::Version6, |create_event| { - create_event.room_version - }); + let room_version = RoomVersion::new( + &create_event_content.map_or(RoomVersionId::Version6, |create_event| { + create_event.room_version + }), + ) + .expect("room version is supported"); let content = serde_json::to_value(MemberEventContent { avatar_url: None, From af6fea3d4e75b28c17d9c8a5e00d1d7bf55737a0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 8 May 2021 02:13:01 +0200 Subject: [PATCH 2/2] Refactor some canonical JSON code --- src/pdu.rs | 5 +++- src/ruma_wrapper.rs | 56 +++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/pdu.rs b/src/pdu.rs index a593f0b5..84756bc2 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -213,7 +213,10 @@ impl PduEvent { pub fn convert_to_outgoing_federation_event( mut pdu_json: CanonicalJsonObject, ) -> Raw { - if let Some(CanonicalJsonValue::Object(unsigned)) = pdu_json.get_mut("unsigned") { + if let Some(unsigned) = pdu_json + .get_mut("unsigned") + .and_then(|val| val.as_object_mut()) + { unsigned.remove("transaction_id"); } diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index e4eda870..9143999f 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -271,41 +271,33 @@ where http_request = http_request.header(header.name.as_str(), &*header.value); } - match &mut json_body { - Some(CanonicalJsonValue::Object(json_body)) => { - let user_id = sender_user.clone().unwrap_or_else(|| { - UserId::parse_with_server_name("", db.globals.server_name()) - .expect("we know this is valid") - }); + if let Some(json_body) = json_body.as_mut().and_then(|val| val.as_object_mut()) { + let user_id = sender_user.clone().unwrap_or_else(|| { + UserId::parse_with_server_name("", db.globals.server_name()) + .expect("we know this is valid") + }); - if let Some(initial_request) = json_body - .get("auth") - .and_then(|auth| auth.as_object()) - .and_then(|auth| auth.get("session")) - .and_then(|session| session.as_str()) - .and_then(|session| { - db.uiaa - .get_uiaa_request( - &user_id, - &sender_device.clone().unwrap_or_else(|| "".into()), - session, - ) - .ok() - .flatten() - }) - { - match initial_request { - CanonicalJsonValue::Object(initial_request) => { - for (key, value) in initial_request.into_iter() { - json_body.entry(key).or_insert(value); - } - } - _ => {} - } + if let Some(CanonicalJsonValue::Object(initial_request)) = json_body + .get("auth") + .and_then(|auth| auth.as_object()) + .and_then(|auth| auth.get("session")) + .and_then(|session| session.as_str()) + .and_then(|session| { + db.uiaa + .get_uiaa_request( + &user_id, + &sender_device.clone().unwrap_or_else(|| "".into()), + session, + ) + .ok() + .flatten() + }) + { + for (key, value) in initial_request { + json_body.entry(key).or_insert(value); } - body = serde_json::to_vec(json_body).expect("value to bytes can't fail"); } - _ => {} + body = serde_json::to_vec(json_body).expect("value to bytes can't fail"); } let http_request = http_request.body(&*body).unwrap();