From 979ec6b4fa5cd5b415f56ebc8c59ba742f835eb6 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 1 Sep 2021 15:28:02 +0200 Subject: [PATCH] Upgrade ruma --- Cargo.lock | 54 ++++++++++------------------- Cargo.toml | 4 +-- src/client_server/membership.rs | 6 ++-- src/database/rooms.rs | 13 +++---- src/pdu.rs | 30 ++++++++++------ src/server_server.rs | 61 ++++++++++++++++----------------- 6 files changed, 76 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86ef48c..70d7f4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1968,8 +1968,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668031e3108d6a2cfbe6eca271d8698f4593440e71a44afdadcf67ce3cb93c1f" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "assign", "js_int", @@ -1990,8 +1989,7 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f1843792b6749ec1ece62595cf99ad30bf9589c96bb237515235e71da396ea" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "bytes", "http", @@ -2007,8 +2005,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b18abda5cca94178d08b622bca042e1cbb5eb7d4ebf3a2a81590a3bb3c57008" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2019,8 +2016,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49369332a5f299e832e19661f92d49e08c345c3c6c4ab16e09cb31c5ff6da878" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "ruma-api", "ruma-common", @@ -2034,8 +2030,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9568a222c12cf6220e751484ab78feec28071f85965113a5bb802936a2920ff0" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "assign", "bytes", @@ -2055,8 +2050,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d5b7605f58dc0d9cf1848cc7f1af2bae4e4bcd1d2b7a87bbb9864c8a785b91" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "indexmap", "js_int", @@ -2071,8 +2065,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.24.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87801e1207cfebdee02e7997ebf181a1c9837260b78c1b8ce96b896a2bcb3763" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "indoc", "js_int", @@ -2088,8 +2081,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.24.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da4498845347de88adf1b7da4578e2ca7355ad4ce47b0976f6594bacf958660" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2100,8 +2092,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa3d1db1a064ab26484df6ef5d96c384fc053022004f34d96c3b4939e13dc204" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "js_int", "ruma-api", @@ -2116,8 +2107,7 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb417d091e8dd5a633e4e5998231a156049d7fcc221045cfdc0642eb72067732" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "paste", "rand 0.8.4", @@ -2131,8 +2121,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c708edad7f605638f26c951cbad7501fbf28ab01009e5ca65ea5a2db74a882b1" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "quote", "ruma-identifiers-validation", @@ -2142,14 +2131,12 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42285e7fb5d5f2d5268e45bb683e36d5c6fd9fc1e11a4559ba3c3521f3bbb2cb" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" [[package]] name = "ruma-identity-service-api" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e76e66e24f2d5a31511fbf6c79e79f67a7a6a98ebf48d72381b7d5bb6c09f035" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "js_int", "ruma-api", @@ -2162,8 +2149,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef5b29da7065efc5b1e1a8f61add7543c9ab4ecce5ee0dd1c1c5ecec83fbeec" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "js_int", "ruma-api", @@ -2178,8 +2164,7 @@ dependencies = [ [[package]] name = "ruma-serde" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2b22aae842e7ecda695e42b7b39d4558959d9d9a27acc2a16acf4f4f7f00c3" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "bytes", "form_urlencoded", @@ -2193,8 +2178,7 @@ dependencies = [ [[package]] name = "ruma-serde-macros" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243e9bef188b08f94c79bc2f8fd1eb307a9e636b2b8e4571acf8c7be16381d28" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2205,8 +2189,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a4f64027165b59500162d10d435b1253898bf3ad4f5002cb0d56913fe7f76d7" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "base64 0.13.0", "ed25519-dalek", @@ -2223,8 +2206,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518c1afbddfcc5ffac8818a5cf0902709e6eca11aca8f24f6479df6f0601f1ba" +source = "git+https://github.com/ruma/ruma?rev=a6a1224652912a957b09f136ec5da2686be6e0e2#a6a1224652912a957b09f136ec5da2686be6e0e2" dependencies = [ "itertools 0.10.1", "js_int", diff --git a/Cargo.toml b/Cargo.toml index 04887d0..593a1fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,8 @@ edition = "2018" rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests # Used for matrix spec type definitions and helpers -ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } -#ruma = { git = "https://github.com/ruma/ruma", rev = "f5ab038e22421ed338396ece977b6b2844772ced", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } +#ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } +ruma = { git = "https://github.com/ruma/ruma", rev = "a6a1224652912a957b09f136ec5da2686be6e0e2", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index 52e074c..01c19c2 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -976,10 +976,10 @@ pub(crate) async fn invite_helper<'a>( let auth_check = state_res::auth_check( &room_version, - &Arc::new(pdu.clone()), + &pdu, create_prev_event, - None, // TODO: third_party_invite - |k, s| auth_events.get(&(k.clone(), s.to_owned())).map(Arc::clone), + None::, // TODO: third_party_invite + |k, s| auth_events.get(&(k.clone(), s.to_owned())), ) .map_err(|e| { error!("{:?}", e); diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 4245483..51023ba 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -252,12 +252,7 @@ impl Rooms { return Ok(HashMap::new()); }; - let auth_events = state_res::auth_types_for_event( - kind, - sender, - state_key.map(|s| s.to_string()), - content.clone(), - ); + let auth_events = state_res::auth_types_for_event(kind, sender, state_key, &content); let mut sauthevents = auth_events .into_iter() @@ -2046,10 +2041,10 @@ impl Rooms { let auth_check = state_res::auth_check( &room_version, - &Arc::new(pdu.clone()), + &pdu, create_prev_event, - None, // TODO: third_party_invite - |k, s| auth_events.get(&(k.clone(), s.to_owned())).map(Arc::clone), + None::, // TODO: third_party_invite + |k, s| auth_events.get(&(k.clone(), s.to_owned())), ) .map_err(|e| { error!("{:?}", e); diff --git a/src/pdu.rs b/src/pdu.rs index 1016fe6..8623b1a 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -260,37 +260,47 @@ impl state_res::Event for PduEvent { fn sender(&self) -> &UserId { &self.sender } - fn kind(&self) -> EventType { - self.kind.clone() + + fn event_type(&self) -> &EventType { + &self.kind } - fn content(&self) -> serde_json::Value { - self.content.clone() + fn content(&self) -> &serde_json::Value { + &self.content } + fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { MilliSecondsSinceUnixEpoch(self.origin_server_ts) } - fn state_key(&self) -> Option { - self.state_key.clone() + + fn state_key(&self) -> Option<&str> { + self.state_key.as_deref() } - fn prev_events(&self) -> Vec { - self.prev_events.to_vec() + + fn prev_events(&self) -> Box + '_> { + Box::new(self.prev_events.iter()) } + fn depth(&self) -> &UInt { &self.depth } - fn auth_events(&self) -> Vec { - self.auth_events.to_vec() + + fn auth_events(&self) -> Box + '_> { + Box::new(self.auth_events.iter()) } + fn redacts(&self) -> Option<&EventId> { self.redacts.as_ref() } + fn hashes(&self) -> &EventHash { &self.hashes } + fn signatures(&self) -> BTreeMap, BTreeMap> { self.signatures.clone() } + fn unsigned(&self) -> &BTreeMap { &self.unsigned } diff --git a/src/server_server.rs b/src/server_server.rs index c27ea22..89b9c5c 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1065,23 +1065,22 @@ pub(crate) async fn handle_incoming_pdu<'a>( } } - let sorted = - state_res::StateResolution::lexicographical_topological_sort(dbg!(&graph), |event_id| { - // This return value is the key used for sorting events, - // events are then sorted by power level, time, - // and lexically by event_id. - println!("{}", event_id); - Ok(( - 0, - MilliSecondsSinceUnixEpoch( - eventid_info - .get(event_id) - .map_or_else(|| uint!(0), |info| info.0.origin_server_ts), - ), - ruma::event_id!("$notimportant"), - )) - }) - .map_err(|_| "Error sorting prev events".to_owned())?; + let sorted = state_res::lexicographical_topological_sort(dbg!(&graph), |event_id| { + // This return value is the key used for sorting events, + // events are then sorted by power level, time, + // and lexically by event_id. + println!("{}", event_id); + Ok(( + 0, + MilliSecondsSinceUnixEpoch( + eventid_info + .get(event_id) + .map_or_else(|| uint!(0), |info| info.0.origin_server_ts), + ), + ruma::event_id!("$notimportant"), + )) + }) + .map_err(|_| "Error sorting prev events".to_owned())?; let mut errors = 0; for prev_id in dbg!(sorted) { @@ -1280,8 +1279,8 @@ fn handle_outlier_pdu<'a>( &room_version, &incoming_pdu, previous_create, - None, // TODO: third party invite - |k, s| auth_events.get(&(k.clone(), s.to_owned())).map(Arc::clone), + None::, // TODO: third party invite + |k, s| auth_events.get(&(k.clone(), s.to_owned())), ) .map_err(|_e| "Auth check failed".to_string())? { @@ -1437,8 +1436,7 @@ async fn upgrade_outlier_to_timeline_pdu( fork_states.push(state); } - state_at_incoming_event = match state_res::StateResolution::resolve( - &room_id, + state_at_incoming_event = match state_res::resolve( room_version_id, &fork_states, auth_chain_sets, @@ -1566,8 +1564,8 @@ async fn upgrade_outlier_to_timeline_pdu( let check_result = state_res::event_auth::auth_check( &room_version, &incoming_pdu, - previous_create.clone(), - None, // TODO: third party invite + previous_create.as_deref(), + None::, // TODO: third party invite |k, s| { db.rooms .get_shortstatekey(&k, &s) @@ -1650,9 +1648,9 @@ async fn upgrade_outlier_to_timeline_pdu( let soft_fail = !state_res::event_auth::auth_check( &room_version, &incoming_pdu, - previous_create, - None, - |k, s| auth_events.get(&(k.clone(), s.to_owned())).map(Arc::clone), + previous_create.as_deref(), + None::, + |k, s| auth_events.get(&(k.clone(), s.to_owned())), ) .map_err(|_e| "Auth check failed.".to_owned())?; @@ -1795,8 +1793,7 @@ async fn upgrade_outlier_to_timeline_pdu( .collect::>>() .map_err(|_| "Failed to get_statekey_from_short.".to_owned())?; - let state = match state_res::StateResolution::resolve( - &room_id, + let state = match state_res::resolve( room_version_id, fork_states, auth_chain_sets, @@ -2773,10 +2770,10 @@ pub fn create_join_event_template_route( let auth_check = state_res::auth_check( &room_version, - &Arc::new(pdu.clone()), - create_prev_event, - None, // TODO: third_party_invite - |k, s| auth_events.get(&(k.clone(), s.to_owned())).map(Arc::clone), + &pdu, + create_prev_event.as_deref(), + None::, // TODO: third_party_invite + |k, s| auth_events.get(&(k.clone(), s.to_owned())), ) .map_err(|e| { error!("{:?}", e);