From 845477327528cdae41691af5ae6757a7f7f002e3 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 3 Dec 2023 20:20:25 -0500 Subject: [PATCH] log rejected sendjoin, remove unnecessary clone Signed-off-by: strawberry --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/api/client_server/membership.rs | 28 +++++++++++++++------------- src/api/server_server.rs | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea149755..c5d708df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,6 +414,7 @@ dependencies = [ "js_option", "jsonwebtoken", "lazy_static", + "loole", "lru-cache", "nix", "num_cpus", @@ -1421,6 +1422,12 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "loole" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a7039a651ba2fccd770a7534059b9744b3641390d696e2f91de6655457e9327" + [[package]] name = "lru-cache" version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index 83f2716b..4b6a6ac1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ hyperlocal = { git = "https://github.com/softprops/hyperlocal", rev = "2ee4d1496 ] } hyper = { version = "0.14", features = ["server", "http1", "http2"] } tokio = { version = "1.34.0", features = ["fs", "macros", "signal", "sync"] } +loole = "0.1" # Used for storing data permanently #sled = { version = "0.34.7", features = ["compression", "no_metrics"], optional = true } #sled = { git = "https://github.com/spacejam/sled.git", rev = "e4640e0773595229f398438886f19bca6f7326a2", features = ["compression"] } diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 82ed9a2f..f1513ca8 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -631,7 +631,7 @@ async fn join_room_by_id_helper( )); } - if let Ok(signature) = signed_value["signatures"] + match signed_value["signatures"] .as_object() .ok_or(Error::BadRequest( ErrorKind::InvalidParam, @@ -642,18 +642,20 @@ async fn join_room_by_id_helper( ErrorKind::InvalidParam, "Server did not send its signature", )) - }) - { - join_event - .get_mut("signatures") - .expect("we created a valid pdu") - .as_object_mut() - .expect("we created a valid pdu") - .insert(remote_server.to_string(), signature.clone()); - } else { - warn!( - "Server {remote_server} sent invalid signature in sendjoin signatures for event {signed_value:?}", - ); + }) { + Ok(signature) => { + join_event + .get_mut("signatures") + .expect("we created a valid pdu") + .as_object_mut() + .expect("we created a valid pdu") + .insert(remote_server.to_string(), signature.clone()); + } + Err(e) => { + warn!( + "Server {remote_server} sent invalid signature in sendjoin signatures for event {signed_value:?}: {e:?}", + ); + } } } diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 9df1beef..017179b2 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -1921,7 +1921,7 @@ pub async fn get_devices_route( let device_id_string = metadata.device_id.as_str().to_owned(); let device_display_name = match services().globals.allow_device_name_federation() { true => metadata.display_name, - false => Some(device_id_string.to_string()), + false => Some(device_id_string), }; Some(UserDevice { keys: services()