Update state-res, use the new Event trait

This also bumps ruma to latest and removes js_int infavor of the ruma
re-export
next
Devin Ragotzy 2020-12-31 08:40:49 -05:00
parent 4a92a29b56
commit 4b9976aa74
11 changed files with 252 additions and 183 deletions

140
Cargo.lock generated
View File

@ -212,8 +212,8 @@ dependencies = [
"js_int", "js_int",
"jsonwebtoken", "jsonwebtoken",
"log", "log",
"rand",
"regex", "regex",
"rand 0.7.3",
"reqwest", "reqwest",
"ring", "ring",
"rocket", "rocket",
@ -585,6 +585,17 @@ dependencies = [
"wasi 0.9.0+wasi-snapshot-preview1", "wasi 0.9.0+wasi-snapshot-preview1",
] ]
[[package]]
name = "getrandom"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4"
dependencies = [
"cfg-if 0.1.10",
"libc",
"wasi",
]
[[package]] [[package]]
name = "gif" name = "gif"
version = "0.11.1" version = "0.11.1"
@ -847,9 +858,9 @@ dependencies = [
[[package]] [[package]]
name = "js_int" name = "js_int"
version = "0.1.9" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b96797f53235a1d6dc985f244a69de54b04c45b7e0e357a35c85a45a847d92f2" checksum = "fcae89e078a96b781b38f36225bb3a174b8f6e905dfec550dd16a13539c82acc"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@ -1396,11 +1407,23 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [ dependencies = [
"getrandom", "getrandom 0.1.15",
"libc", "libc",
"rand_chacha", "rand_chacha 0.2.2",
"rand_core", "rand_core 0.5.1",
"rand_hc", "rand_hc 0.2.0",
]
[[package]]
name = "rand"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a76330fb486679b4ace3670f117bbc9e16204005c4bde9c4bd372f45bed34f12"
dependencies = [
"libc",
"rand_chacha 0.3.0",
"rand_core 0.6.0",
"rand_hc 0.3.0",
] ]
[[package]] [[package]]
@ -1410,7 +1433,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core", "rand_core 0.5.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core 0.6.0",
] ]
[[package]] [[package]]
@ -1419,7 +1452,16 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [ dependencies = [
"getrandom", "getrandom 0.1.15",
]
[[package]]
name = "rand_core"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8b34ba8cfb21243bd8df91854c830ff0d785fff2e82ebd4434c2644cb9ada18"
dependencies = [
"getrandom 0.2.0",
] ]
[[package]] [[package]]
@ -1428,7 +1470,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [ dependencies = [
"rand_core", "rand_core 0.5.1",
]
[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core 0.6.0",
] ]
[[package]] [[package]]
@ -1443,7 +1494,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
dependencies = [ dependencies = [
"getrandom", "getrandom 0.1.15",
"redox_syscall", "redox_syscall",
"rust-argon2", "rust-argon2",
] ]
@ -1571,7 +1622,7 @@ dependencies = [
"memchr", "memchr",
"num_cpus", "num_cpus",
"parking_lot", "parking_lot",
"rand", "rand 0.7.3",
"ref-cast", "ref-cast",
"rocket_codegen", "rocket_codegen",
"rocket_http", "rocket_http",
@ -1625,7 +1676,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -1643,7 +1694,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.0-alpha.1" version = "0.17.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding", "percent-encoding",
@ -1658,7 +1709,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.0-alpha.1" version = "0.17.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1669,7 +1720,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.2.0-alpha.1" version = "0.2.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1683,7 +1734,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.10.0-alpha.1" version = "0.10.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"assign", "assign",
"http", "http",
@ -1702,7 +1753,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"js_int", "js_int",
"maplit", "maplit",
@ -1715,7 +1766,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.22.0-alpha.1" version = "0.22.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -1729,7 +1780,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.22.0-alpha.1" version = "0.22.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1740,7 +1791,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.0.3" version = "0.0.3"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1755,21 +1806,21 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.17.4" version = "0.17.4"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"paste", "paste",
"rand", "rand 0.8.0",
"ruma-identifiers-macros", "ruma-identifiers-macros",
"ruma-identifiers-validation", "ruma-identifiers-validation",
"ruma-serde", "ruma-serde",
"ruma-serde-macros",
"serde", "serde",
"strum",
] ]
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.17.4" version = "0.17.4"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1780,7 +1831,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.1.1" version = "0.1.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@ -1788,7 +1839,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.2.3" version = "0.2.3"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
@ -1800,8 +1851,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde-macros" name = "ruma-serde-macros"
version = "0.2.0" version = "0.2.3"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1812,9 +1863,9 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.6.0-dev.1" version = "0.6.0-dev.1"
source = "git+https://github.com/ruma/ruma?rev=45d01011554f9d07739e9a5edf5498d8ac16f273#45d01011554f9d07739e9a5edf5498d8ac16f273" source = "git+https://github.com/ruma/ruma?rev=210b6dd823ba89c5a44c3c9d913d377c4b54c896#210b6dd823ba89c5a44c3c9d913d377c4b54c896"
dependencies = [ dependencies = [
"base64 0.12.3", "base64 0.13.0",
"ring", "ring",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
@ -2076,7 +2127,7 @@ checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483"
[[package]] [[package]]
name = "state-res" name = "state-res"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/ruma/state-res?branch=conflict#e2c5bb401263e1b2fde60313acf5fc4ef072c74d" source = "git+https://github.com/ruma/state-res?branch=event-trait#9b96204571521e216a618d102459d662c52a2210"
dependencies = [ dependencies = [
"itertools", "itertools",
"maplit", "maplit",
@ -2136,27 +2187,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "strum"
version = "0.19.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b89a286a7e3b5720b9a477b23253bc50debac207c8d21505f8e70b36792f11b5"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.19.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e61bb0be289045cb80bfce000512e32d09f8337e54c186725da381377ad1f8d5"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.55" version = "1.0.55"
@ -2176,7 +2206,7 @@ checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
"libc", "libc",
"rand", "rand 0.7.3",
"redox_syscall", "redox_syscall",
"remove_dir_all", "remove_dir_all",
"winapi 0.3.9", "winapi 0.3.9",
@ -2416,7 +2446,7 @@ dependencies = [
"idna", "idna",
"lazy_static", "lazy_static",
"log", "log",
"rand", "rand 0.7.3",
"smallvec", "smallvec",
"thiserror", "thiserror",
"tokio", "tokio",

View File

@ -18,13 +18,14 @@ rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "1f1f44f33
#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } #rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks", "unstable-exhaustive-types"], rev = "45d01011554f9d07739e9a5edf5498d8ac16f273" } ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks", "unstable-exhaustive-types"], rev = "210b6dd823ba89c5a44c3c9d913d377c4b54c896" }
# ruma = { git = "https://github.com/DevinR528/ruma", features = ["rand", "client-api", "federation-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "verified-export" } # ruma = { git = "https://github.com/DevinR528/ruma", features = ["rand", "client-api", "federation-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "verified-export" }
# ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] } # ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"] }
# Used when doing state resolution # Used when doing state resolution
# state-res = { git = "https://github.com/timokoesters/state-res", branch = "timo-spec-comp", features = ["unstable-pre-spec"] } # state-res = { git = "https://github.com/timokoesters/state-res", branch = "timo-spec-comp", features = ["unstable-pre-spec"] }
state-res = { git = "https://github.com/ruma/state-res", branch = "conflict", features = ["unstable-pre-spec", "gen-eventid"] } # TODO: remove the gen-eventid feature
state-res = { git = "https://github.com/ruma/state-res", branch = "event-trait", features = ["unstable-pre-spec", "gen-eventid"] }
# state-res = { path = "../../state-res", features = ["unstable-pre-spec", "gen-eventid"] } # state-res = { path = "../../state-res", features = ["unstable-pre-spec", "gen-eventid"] }
# Used for long polling and federation sender, should be the same as rocket::tokio # Used for long polling and federation sender, should be the same as rocket::tokio
@ -37,8 +38,7 @@ log = "0.4.11"
http = "0.2.1" http = "0.2.1"
# Used to find data directory for default db path # Used to find data directory for default db path
directories = "3.0.1" directories = "3.0.1"
# Used for number types for ruma
js_int = "0.1.9"
# Used for ruma wrapper # Used for ruma wrapper
serde_json = { version = "1.0.60", features = ["raw_value"] } serde_json = { version = "1.0.60", features = ["raw_value"] }
# Used for appservice registration files # Used for appservice registration files

View File

@ -124,7 +124,7 @@ pub async fn get_room_visibility_route(
pub async fn get_public_rooms_filtered_helper( pub async fn get_public_rooms_filtered_helper(
db: &Database, db: &Database,
server: Option<&ServerName>, server: Option<&ServerName>,
limit: Option<js_int::UInt>, limit: Option<ruma::UInt>,
since: Option<&str>, since: Option<&str>,
filter: &IncomingFilter, filter: &IncomingFilter,
_network: &IncomingRoomNetwork, _network: &IncomingRoomNetwork,

View File

@ -131,7 +131,7 @@ pub async fn get_content_thumbnail_route(
allow_remote: false, allow_remote: false,
height: body.height, height: body.height,
width: body.width, width: body.width,
method: body.method, method: body.method.clone(),
server_name: &body.server_name, server_name: &body.server_name,
media_id: &body.media_id, media_id: &body.media_id,
}, },

View File

@ -21,7 +21,7 @@ use ruma::{
serde::{to_canonical_value, CanonicalJsonObject, Raw}, serde::{to_canonical_value, CanonicalJsonObject, Raw},
EventId, RoomId, RoomVersionId, ServerName, UserId, EventId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use state_res::StateEvent; use state_res::Event;
use std::{ use std::{
collections::{BTreeMap, HashMap, HashSet}, collections::{BTreeMap, HashMap, HashSet},
convert::TryFrom, convert::TryFrom,
@ -594,19 +594,19 @@ async fn join_room_by_id_helper(
.chain(iter::once(Ok((event_id, join_event)))) // Add join event we just created .chain(iter::once(Ok((event_id, join_event)))) // Add join event we just created
.map(|r| { .map(|r| {
let (event_id, value) = r?; let (event_id, value) = r?;
state_res::StateEvent::from_id_canon_obj(event_id.clone(), value.clone()) PduEvent::from_id_val(&event_id, value.clone())
.map(|ev| (event_id, Arc::new(ev))) .map(|ev| (event_id, Arc::new(ev)))
.map_err(|e| { .map_err(|e| {
warn!("{:?}: {}", value, e); warn!("{:?}: {}", value, e);
Error::BadServerResponse("Invalid PDU in send_join response.") Error::BadServerResponse("Invalid PDU in send_join response.")
}) })
}) })
.collect::<Result<BTreeMap<EventId, Arc<StateEvent>>>>()?; .collect::<Result<BTreeMap<EventId, Arc<PduEvent>>>>()?;
let control_events = event_map let control_events = event_map
.values() .values()
.filter(|pdu| pdu.is_power_event()) .filter(|pdu| state_res::is_power_event(pdu))
.map(|pdu| pdu.event_id()) .map(|pdu| pdu.event_id.clone())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// These events are not guaranteed to be sorted but they are resolved according to spec // These events are not guaranteed to be sorted but they are resolved according to spec
@ -646,7 +646,8 @@ async fn join_room_by_id_helper(
.cloned() .cloned()
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let power_level = resolved_control_events.get(&(EventType::RoomPowerLevels, "".into())); let power_level =
resolved_control_events.get(&(EventType::RoomPowerLevels, Some("".to_string())));
// Sort the remaining non control events // Sort the remaining non control events
let sorted_event_ids = state_res::StateResolution::mainline_sort( let sorted_event_ids = state_res::StateResolution::mainline_sort(
room_id, room_id,
@ -685,8 +686,13 @@ async fn join_room_by_id_helper(
pdu_id.push(0xff); pdu_id.push(0xff);
pdu_id.extend_from_slice(&count.to_be_bytes()); pdu_id.extend_from_slice(&count.to_be_bytes());
db.rooms.append_pdu( db.rooms.append_pdu(
<<<<<<< HEAD
&PduEvent::from(&**pdu), &PduEvent::from(&**pdu),
utils::to_canonical_object(&**pdu).expect("Pdu is valid canonical object"), utils::to_canonical_object(&**pdu).expect("Pdu is valid canonical object"),
=======
&pdu,
&utils::to_canonical_object(&**pdu).expect("Pdu is valid canonical object"),
>>>>>>> 6232d1f (Update state-res, use the new Event trait)
count, count,
pdu_id.clone().into(), pdu_id.clone().into(),
&db.globals, &db.globals,
@ -695,7 +701,9 @@ async fn join_room_by_id_helper(
)?; )?;
if state_events.contains(ev_id) { if state_events.contains(ev_id) {
state.insert((pdu.kind(), pdu.state_key()), pdu_id); if let Some(key) = &pdu.state_key {
state.insert((pdu.kind(), key.to_string()), pdu_id);
}
} }
} }

View File

@ -8,7 +8,10 @@ use ruma::{
events::EventContent, events::EventContent,
EventId, EventId,
}; };
use std::convert::{TryFrom, TryInto}; use std::{
collections::BTreeMap,
convert::{TryFrom, TryInto},
};
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
use rocket::{get, put}; use rocket::{get, put};
@ -46,7 +49,7 @@ pub async fn send_message_event_route(
return Ok(send_message_event::Response { event_id }.into()); return Ok(send_message_event::Response { event_id }.into());
} }
let mut unsigned = serde_json::Map::new(); let mut unsigned = BTreeMap::new();
unsigned.insert("transaction_id".to_owned(), body.txn_id.clone().into()); unsigned.insert("transaction_id".to_owned(), body.txn_id.clone().into());
let event_id = db.rooms.build_and_append_pdu( let event_id = db.rooms.build_and_append_pdu(

View File

@ -20,7 +20,7 @@ use ruma::{
EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use sled::IVec; use sled::IVec;
use state_res::{event_auth, Error as StateError, Requester, StateEvent, StateMap, StateStore}; use state_res::{event_auth, Error as StateError, Event, StateMap, StateStore};
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},
@ -67,12 +67,8 @@ pub struct Rooms {
pub(super) stateid_pduid: sled::Tree, // StateId = StateHash + Short, PduId = Count (without roomid) pub(super) stateid_pduid: sled::Tree, // StateId = StateHash + Short, PduId = Count (without roomid)
} }
impl StateStore for Rooms { impl StateStore<PduEvent> for Rooms {
fn get_event( fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> state_res::Result<Arc<PduEvent>> {
&self,
room_id: &RoomId,
event_id: &EventId,
) -> state_res::Result<Arc<StateEvent>> {
let pid = self let pid = self
.get_pdu_id(event_id) .get_pdu_id(event_id)
.map_err(StateError::custom)? .map_err(StateError::custom)?
@ -91,7 +87,7 @@ impl StateStore for Rooms {
.ok_or_else(|| StateError::NotFound("PDU via pduid not found in db.".into()))?, .ok_or_else(|| StateError::NotFound("PDU via pduid not found in db.".into()))?,
) )
.map_err(Into::into) .map_err(Into::into)
.and_then(|pdu: StateEvent| { .and_then(|pdu: PduEvent| {
// conduit's PDU's always contain a room_id but some // conduit's PDU's always contain a room_id but some
// of ruma's do not so this must be an Option // of ruma's do not so this must be an Option
if pdu.room_id() == room_id { if pdu.room_id() == room_id {
@ -112,7 +108,7 @@ impl Rooms {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
state_hash: &StateHashId, state_hash: &StateHashId,
) -> Result<StateMap<PduEvent>> { ) -> Result<BTreeMap<(EventType, String), PduEvent>> {
self.stateid_pduid self.stateid_pduid
.scan_prefix(&state_hash) .scan_prefix(&state_hash)
.values() .values()
@ -141,7 +137,7 @@ impl Rooms {
pdu, pdu,
)) ))
}) })
.collect::<Result<StateMap<_>>>() .collect()
} }
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
@ -181,7 +177,7 @@ impl Rooms {
))) )))
}) })
} else { } else {
return Ok(None); Ok(None)
} }
} }
@ -205,7 +201,7 @@ impl Rooms {
content: serde_json::Value, content: serde_json::Value,
) -> Result<StateMap<PduEvent>> { ) -> Result<StateMap<PduEvent>> {
let auth_events = state_res::auth_types_for_event( let auth_events = state_res::auth_types_for_event(
kind.clone(), kind,
sender, sender,
state_key.map(|s| s.to_string()), state_key.map(|s| s.to_string()),
content, content,
@ -213,7 +209,13 @@ impl Rooms {
let mut events = StateMap::new(); let mut events = StateMap::new();
for (event_type, state_key) in auth_events { for (event_type, state_key) in auth_events {
if let Some((_, pdu)) = self.room_state_get(room_id, &event_type, &state_key)? { if let Some((_, pdu)) = self.room_state_get(
room_id,
&event_type,
&state_key
.as_deref()
.expect("found a non state event in auth events"),
)? {
events.insert((event_type, state_key), pdu); events.insert((event_type, state_key), pdu);
} }
} }
@ -290,7 +292,10 @@ impl Rooms {
} }
/// Returns the full room state. /// Returns the full room state.
pub fn room_state_full(&self, room_id: &RoomId) -> Result<StateMap<PduEvent>> { pub fn room_state_full(
&self,
room_id: &RoomId,
) -> Result<BTreeMap<(EventType, String), PduEvent>> {
if let Some(current_state_hash) = self.current_state_hash(room_id)? { if let Some(current_state_hash) = self.current_state_hash(room_id)? {
self.state_full(&room_id, &current_state_hash) self.state_full(&room_id, &current_state_hash)
} else { } else {
@ -795,23 +800,40 @@ impl Rooms {
ErrorKind::Unknown, ErrorKind::Unknown,
"Membership can't be the first event", "Membership can't be the first event",
))?)? ))?)?
.map(|pdu| pdu.convert_for_state_res()); .map(Arc::new);
event_auth::valid_membership_change( event_auth::valid_membership_change(
// TODO this is a bit of a hack but not sure how to have a type // TODO this is a bit of a hack but not sure how to have a type
// declared in `state_res` crate easily convert to/from conduit::PduEvent // declared in `state_res` crate easily convert to/from conduit::PduEvent
Requester { &Arc::new(PduEvent {
prev_event_ids: prev_events.to_owned(), event_id: ruma::event_id!("$thiswillbefilledinlater"),
room_id: &room_id, room_id: room_id.clone(),
content: &content, sender: sender.clone(),
state_key: Some(state_key.to_owned()), origin_server_ts: utils::millis_since_unix_epoch()
sender: &sender, .try_into()
}, .expect("time is valid"),
kind: event_type,
content,
state_key: Some(state_key.clone()),
prev_events,
depth: (prev_events.len() as u32).into(),
auth_events: auth_events
.into_iter()
.map(|(_, pdu)| pdu.event_id)
.collect(),
redacts,
unsigned: unsigned
.map_or_else(BTreeMap::new, |m| m.into_iter().collect()),
hashes: ruma::events::pdu::EventHash {
sha256: "aaa".to_owned(),
},
signatures: BTreeMap::new(),
}),
prev_event, prev_event,
None, // TODO: third party invite None, // TODO: third party invite
&auth_events &auth_events
.iter() .iter()
.map(|((ty, key), pdu)| { .map(|((ty, key), pdu)| {
Ok(((ty.clone(), key.clone()), pdu.convert_for_state_res())) Ok(((ty.clone(), key.clone()), Arc::new(pdu.clone())))
}) })
.collect::<Result<StateMap<_>>>()?, .collect::<Result<StateMap<_>>>()?,
) )

View File

@ -1,5 +1,4 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use js_int::UInt;
use ruma::{ use ruma::{
events::{ events::{
presence::{PresenceEvent, PresenceEventContent}, presence::{PresenceEvent, PresenceEventContent},
@ -7,7 +6,7 @@ use ruma::{
}, },
presence::PresenceState, presence::PresenceState,
serde::Raw, serde::Raw,
RoomId, UserId, RoomId, UInt, UserId,
}; };
use std::{ use std::{
collections::HashMap, collections::HashMap,

View File

@ -1,5 +1,4 @@
use crate::{utils, Error, Result}; use crate::{utils, Error, Result};
use js_int::UInt;
use ruma::{ use ruma::{
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
@ -11,7 +10,7 @@ use ruma::{
encryption::DeviceKeys, encryption::DeviceKeys,
events::{AnyToDeviceEvent, EventType}, events::{AnyToDeviceEvent, EventType},
serde::Raw, serde::Raw,
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UInt, UserId,
}; };
use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime}; use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime};

View File

@ -1,12 +1,11 @@
use crate::Error; use crate::Error;
use js_int::UInt;
use ruma::{ use ruma::{
events::{ events::{
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent, pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
}, },
serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw}, serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw},
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
@ -33,8 +32,8 @@ pub struct PduEvent {
pub auth_events: Vec<EventId>, pub auth_events: Vec<EventId>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub redacts: Option<EventId>, pub redacts: Option<EventId>,
#[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub unsigned: serde_json::Map<String, serde_json::Value>, pub unsigned: BTreeMap<String, serde_json::Value>,
pub hashes: EventHash, pub hashes: EventHash,
pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>, pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>,
} }
@ -227,61 +226,66 @@ impl PduEvent {
) )
.expect("Raw::from_value always works") .expect("Raw::from_value always works")
} }
}
impl From<&state_res::StateEvent> for PduEvent { pub fn from_id_val(
fn from(pdu: &state_res::StateEvent) -> Self { event_id: &EventId,
Self { json: CanonicalJsonObject,
event_id: pdu.event_id(), ) -> Result<Self, serde_json::Error> {
room_id: pdu.room_id().clone(), json.insert(
sender: pdu.sender().clone(), "event_id".to_string(),
origin_server_ts: (pdu ruma::serde::to_canonical_value(event_id).expect("event_id is a valid Value"),
.origin_server_ts() );
.duration_since(UNIX_EPOCH)
.expect("time is valid") serde_json::from_value(serde_json::to_value(json).expect("valid JSON"))
.as_millis() as u64)
.try_into()
.expect("time is valid"),
kind: pdu.kind(),
content: pdu.content().clone(),
state_key: Some(pdu.state_key()),
prev_events: pdu.prev_event_ids(),
depth: *pdu.depth(),
auth_events: pdu.auth_events(),
redacts: pdu.redacts().cloned(),
unsigned: pdu.unsigned().clone().into_iter().collect(),
hashes: pdu.hashes().clone(),
signatures: pdu.signatures(),
}
} }
} }
impl PduEvent { impl state_res::Event for PduEvent {
pub fn convert_for_state_res(&self) -> Arc<state_res::StateEvent> { fn event_id(&self) -> &EventId {
Arc::new( &self.event_id
// For consistency of eventId (just in case) we use the one }
// generated by conduit for everything.
state_res::StateEvent::from_id_value( fn room_id(&self) -> &RoomId {
self.event_id.clone(), &self.room_id
json!({ }
"event_id": self.event_id,
"room_id": self.room_id, fn sender(&self) -> &UserId {
"sender": self.sender, &self.sender
"origin_server_ts": self.origin_server_ts, }
"type": self.kind, fn kind(&self) -> EventType {
"content": self.content, self.kind.clone()
"state_key": self.state_key, }
"prev_events": self.prev_events,
"depth": self.depth, fn content(&self) -> serde_json::Value {
"auth_events": self.auth_events, self.content.clone()
"redacts": self.redacts, }
"unsigned": self.unsigned, fn origin_server_ts(&self) -> std::time::SystemTime {
"hashes": self.hashes, UNIX_EPOCH + std::time::Duration::from_millis(self.origin_server_ts.into())
"signatures": self.signatures, }
}),
) fn state_key(&self) -> Option<String> {
.expect("all conduit PDUs are state events"), self.state_key.clone()
) }
fn prev_events(&self) -> Vec<EventId> {
self.prev_events.to_vec()
}
fn depth(&self) -> &UInt {
&self.depth
}
fn auth_events(&self) -> Vec<EventId> {
self.auth_events.to_vec()
}
fn redacts(&self) -> Option<&EventId> {
self.redacts.as_ref()
}
fn hashes(&self) -> &EventHash {
&self.hashes
}
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> {
self.signatures.clone()
}
fn unsigned(&self) -> &BTreeMap<String, serde_json::Value> {
&self.unsigned
} }
} }
@ -315,7 +319,7 @@ pub struct PduBuilder {
#[serde(rename = "type")] #[serde(rename = "type")]
pub event_type: EventType, pub event_type: EventType,
pub content: serde_json::Value, pub content: serde_json::Value,
pub unsigned: Option<serde_json::Map<String, serde_json::Value>>, pub unsigned: Option<BTreeMap<String, serde_json::Value>>,
pub state_key: Option<String>, pub state_key: Option<String>,
pub redacts: Option<EventId>, pub redacts: Option<EventId>,
} }

View File

@ -20,12 +20,13 @@ use ruma::{
directory::{IncomingFilter, IncomingRoomNetwork}, directory::{IncomingFilter, IncomingRoomNetwork},
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
}; };
use state_res::StateMap; use state_res::{Event, StateMap};
use std::{ use std::{
collections::{BTreeMap, BTreeSet}, collections::{BTreeMap, BTreeSet},
convert::TryFrom, convert::TryFrom,
fmt::Debug, fmt::Debug,
net::{IpAddr, SocketAddr}, net::{IpAddr, SocketAddr},
sync::Arc,
time::{Duration, SystemTime}, time::{Duration, SystemTime},
}; };
@ -610,17 +611,12 @@ pub async fn send_transaction_message_route<'a>(
continue; continue;
} }
// TODO: remove the need to convert to state_res let event = Arc::new(pdu.clone());
let event = pdu.convert_for_state_res();
let previous = pdu let previous = pdu
.prev_events .prev_events
.first() .first()
.map(|id| { .map(|id| db.rooms.get_pdu(id).expect("todo").map(Arc::new))
db.rooms
.get_pdu(id)
.expect("todo")
.map(|ev| ev.convert_for_state_res())
})
.flatten(); .flatten();
// 4. // 4.
@ -637,27 +633,32 @@ pub async fn send_transaction_message_route<'a>(
previous.clone(), previous.clone(),
auth_events auth_events
.into_iter() .into_iter()
.map(|(k, v)| (k, v.convert_for_state_res())) .map(|(k, v)| (k, Arc::new(v)))
.collect(), .collect(),
None, None,
) )
.map_err(|_e| Error::Conflict("Auth check failed"))? .map_err(|_e| Error::Conflict("Auth check failed"))?
{ {
resolved_map.insert( resolved_map.insert(
event.event_id(), pdu.event_id,
Err("Event has failed auth check with auth events".into()), Err("Event has failed auth check with auth events".into()),
); );
continue; continue;
} }
let mut previous_states = vec![]; let mut previous_states: Vec<StateMap<Arc<PduEvent>>> = vec![];
for id in &pdu.prev_events { for id in &pdu.prev_events {
if let Some(id) = db.rooms.get_pdu_id(id)? { if let Some(id) = db.rooms.get_pdu_id(id)? {
let state_hash = db let state_hash = db
.rooms .rooms
.pdu_state_hash(&id)? .pdu_state_hash(&id)?
.expect("found pdu with no statehash"); .expect("found pdu with no statehash");
let state = db.rooms.state_full(&pdu.room_id, &state_hash)?; let state = db
.rooms
.state_full(&pdu.room_id, &state_hash)?
.into_iter()
.map(|((et, sk), ev)| ((et, Some(sk)), Arc::new(ev)))
.collect();
previous_states.push(state); previous_states.push(state);
} else { } else {
// fetch the state // fetch the state
@ -693,7 +694,7 @@ pub async fn send_transaction_message_route<'a>(
.into_iter() .into_iter()
.map(|map| { .map(|map| {
map.into_iter() map.into_iter()
.map(|(k, v)| (k, v.event_id)) .map(|(k, v)| (k, v.event_id.clone()))
.collect::<StateMap<_>>() .collect::<StateMap<_>>()
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
@ -702,7 +703,7 @@ pub async fn send_transaction_message_route<'a>(
) { ) {
Ok(res) => res Ok(res) => res
.into_iter() .into_iter()
.map(|(k, v)| (k, db.rooms.get_pdu(&v).unwrap().unwrap())) .map(|(k, v)| (k, Arc::new(db.rooms.get_pdu(&v).unwrap().unwrap())))
.collect(), .collect(),
Err(e) => panic!("{:?}", e), Err(e) => panic!("{:?}", e),
} }
@ -712,17 +713,14 @@ pub async fn send_transaction_message_route<'a>(
&RoomVersionId::Version6, &RoomVersionId::Version6,
&event, &event,
previous.clone(), previous.clone(),
state_at_event state_at_event,
.into_iter()
.map(|(k, v)| (k, v.convert_for_state_res()))
.collect(),
None, None,
) )
.map_err(|_e| Error::Conflict("Auth check failed"))? .map_err(|_e| Error::Conflict("Auth check failed"))?
{ {
// Event failed auth with state_at // Event failed auth with state_at
resolved_map.insert( resolved_map.insert(
event.event_id(), pdu.event_id,
Err("Event has failed auth check with state at the event".into()), Err("Event has failed auth check with state at the event".into()),
); );
continue; continue;
@ -733,14 +731,20 @@ pub async fn send_transaction_message_route<'a>(
// Gather the forward extremities and resolve // Gather the forward extremities and resolve
let forward_extrems = forward_extremity_ids(&db, &pdu.room_id)?; let forward_extrems = forward_extremity_ids(&db, &pdu.room_id)?;
let mut fork_states = vec![]; let mut fork_states: Vec<StateMap<Arc<PduEvent>>> = vec![];
for id in &forward_extrems { for id in &forward_extrems {
if let Some(id) = db.rooms.get_pdu_id(id)? { if let Some(id) = db.rooms.get_pdu_id(id)? {
let state_hash = db let state_hash = db
.rooms .rooms
.pdu_state_hash(&id)? .pdu_state_hash(&id)?
.expect("found pdu with no statehash"); .expect("found pdu with no statehash");
let state = db.rooms.state_full(&pdu.room_id, &state_hash)?; let state = db
.rooms
.state_full(&pdu.room_id, &state_hash)?
.into_iter()
.map(|(k, v)| ((k.0, Some(k.1)), Arc::new(v)))
.collect();
fork_states.push(state); fork_states.push(state);
} else { } else {
// This is probably an error?? // This is probably an error??
@ -776,7 +780,7 @@ pub async fn send_transaction_message_route<'a>(
.into_iter() .into_iter()
.map(|map| { .map(|map| {
map.into_iter() map.into_iter()
.map(|(k, v)| (k, v.event_id)) .map(|(k, v)| (k, v.event_id.clone()))
.collect::<StateMap<_>>() .collect::<StateMap<_>>()
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
@ -785,7 +789,7 @@ pub async fn send_transaction_message_route<'a>(
) { ) {
Ok(res) => res Ok(res) => res
.into_iter() .into_iter()
.map(|(k, v)| (k, db.rooms.get_pdu(&v).unwrap().unwrap())) .map(|(k, v)| (k, Arc::new(db.rooms.get_pdu(&v).unwrap().unwrap())))
.collect(), .collect(),
Err(e) => panic!("{:?}", e), Err(e) => panic!("{:?}", e),
} }
@ -795,20 +799,20 @@ pub async fn send_transaction_message_route<'a>(
&RoomVersionId::Version6, &RoomVersionId::Version6,
&event, &event,
previous, previous,
state_at_forks state_at_forks,
.into_iter()
.map(|(k, v)| (k, v.convert_for_state_res()))
.collect(),
None, None,
) )
.map_err(|_e| Error::Conflict("Auth check failed"))? .map_err(|_e| Error::Conflict("Auth check failed"))?
{ {
// Soft fail // Soft fail
resolved_map.insert(event.event_id(), Err("Event has been soft failed".into())); resolved_map.insert(
event.event_id().clone(),
Err("Event has been soft failed".into()),
);
} else { } else {
append_state(&db, &pdu)?; append_state(&db, &pdu)?;
// Event has passed all auth/stateres checks // Event has passed all auth/stateres checks
resolved_map.insert(event.event_id(), Ok(())); resolved_map.insert(event.event_id().clone(), Ok(()));
} }
} }