diff --git a/src/client_server/account.rs b/src/client_server/account.rs index f48543e2bad296b8f409d90d3c7a128f312523ba..ab90de5b88e92117fef3e3889d9299b8057dd046 100644 --- a/src/client_server/account.rs +++ b/src/client_server/account.rs @@ -15,13 +15,10 @@ }, }, events::{ - room::canonical_alias, - room::guest_access, - room::history_visibility, - room::join_rules, - room::member, - room::name, - room::{message, topic}, + room::{ + canonical_alias, guest_access, history_visibility, join_rules, member, message, name, + topic, + }, EventType, }, RoomAliasId, RoomId, RoomVersionId, UserId, diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs index 048b4100f5dff3a7fa7e8d0cac47800339baa255..d8af2e3f906c2fa0e573061bfc24251436ef1da5 100644 --- a/src/client_server/directory.rs +++ b/src/client_server/directory.rs @@ -15,9 +15,7 @@ }, federation, }, - directory::Filter, - directory::RoomNetwork, - directory::{IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk}, + directory::{Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, events::{ room::{avatar, canonical_alias, guest_access, history_visibility, name, topic}, EventType, diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index 50a8cca041968f043360acd111d8338bb321a0d3..0e6235f48b3d021470a2fc230ba99ae87f9e9c20 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -17,15 +17,12 @@ }, federation, }, - events::pdu::Pdu, - events::{room::member, EventType}, + events::{pdu::Pdu, room::member, EventType}, EventId, Raw, RoomId, RoomVersionId, ServerName, UserId, }; use state_res::StateEvent; use std::{ - collections::BTreeMap, - collections::HashMap, - collections::HashSet, + collections::{BTreeMap, HashMap, HashSet}, convert::{TryFrom, TryInto}, iter, sync::Arc, diff --git a/src/client_server/state.rs b/src/client_server/state.rs index 3777862347dca1b5a2ba31f92e28fd05810e62e3..010b20d3291a9ac4243cae1a845c31d233121d3a 100644 --- a/src/client_server/state.rs +++ b/src/client_server/state.rs @@ -9,9 +9,8 @@ }, }, events::{ - room::history_visibility::HistoryVisibility, - room::history_visibility::HistoryVisibilityEventContent, AnyStateEventContent, - EventContent, EventType, + room::history_visibility::{HistoryVisibility, HistoryVisibilityEventContent}, + AnyStateEventContent, EventContent, EventType, }, EventId, RoomId, UserId, }; @@ -103,6 +102,7 @@ pub async fn get_state_events_route( ) -> ConduitResult<get_state_events::Response> { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + #[allow(clippy::blocks_in_if_conditions)] // Users not in the room should not be able to access the state unless history_visibility is // WorldReadable if !db.rooms.is_joined(sender_user, &body.room_id)? @@ -148,6 +148,7 @@ pub async fn get_state_events_for_key_route( ) -> ConduitResult<get_state_events_for_key::Response> { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + #[allow(clippy::blocks_in_if_conditions)] // Users not in the room should not be able to access the state unless history_visibility is // WorldReadable if !db.rooms.is_joined(sender_user, &body.room_id)? @@ -198,6 +199,7 @@ pub async fn get_state_events_for_empty_key_route( ) -> ConduitResult<get_state_events_for_empty_key::Response> { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + #[allow(clippy::blocks_in_if_conditions)] // Users not in the room should not be able to access the state unless history_visibility is // WorldReadable if !db.rooms.is_joined(sender_user, &body.room_id)? diff --git a/src/database/sending.rs b/src/database/sending.rs index e3fca4f0a0a2dfbb563ccb06c937b913a04e614c..c108e7eebb4a77260a6bd63d6abf1b6488552adb 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -116,6 +116,7 @@ pub fn start_handler(&self, globals: &super::globals::Globals, rooms: &super::ro } } Err((_server, _e)) => { + log::error!("server: {}\nerror: {}", _server, _e) // TODO: exponential backoff } }; @@ -131,7 +132,7 @@ pub fn start_handler(&self, globals: &super::globals::Globals, rooms: &super::ro .expect("splitn will always return 1 or more elements"), ) .map_err(|_| Error::bad_database("ServerName in servernamepduid bytes are invalid.")) - .and_then(|server_str|Box::<ServerName>::try_from(server_str) + .and_then(|server_str| Box::<ServerName>::try_from(server_str) .map_err(|_| Error::bad_database("ServerName in servernamepduid is invalid."))) .ok() .and_then(|server| parts @@ -162,7 +163,7 @@ pub fn start_handler(&self, globals: &super::globals::Globals, rooms: &super::ro }); } - pub fn send_pdu(&self, server: Box<ServerName>, pdu_id: &[u8]) -> Result<()> { + pub fn send_pdu(&self, server: &ServerName, pdu_id: &[u8]) -> Result<()> { let mut key = server.as_bytes().to_vec(); key.push(0xff); key.extend_from_slice(pdu_id); diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index 8dfd2080c9fd32daed52e1d27e35bd17b0928ed7..1c5529a3a461bb8b56734f836b36f56fca59a795 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -4,7 +4,10 @@ identifiers::{DeviceId, UserId}, Outgoing, }; -use std::{convert::TryFrom, convert::TryInto, ops::Deref}; +use std::{ + convert::{TryFrom, TryInto}, + ops::Deref, +}; #[cfg(feature = "conduit_bin")] use { diff --git a/src/utils.rs b/src/utils.rs index 452b7c5afea2bbf2f2c7ba3232039cd1f24969eb..e65ec864ce3148d6a48d8361e343e61e6cea79cd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -89,9 +89,23 @@ pub fn common_elements( } } } - false }) .all(|b| b) })) } + +#[test] +fn sled_tests() { + let db = sled::Config::new().temporary(true).open().unwrap(); + + db.insert(1_u64.to_be_bytes(), vec![10]).unwrap(); + db.insert(2_u64.to_be_bytes(), vec![20]).unwrap(); + db.insert(3_u64.to_be_bytes(), vec![30]).unwrap(); + + let mut key = 1_u64.to_be_bytes().to_vec(); + key.push(1); + db.insert(key, vec![40]).unwrap(); + + println!("{:?}", db.iter().collect::<Result<Vec<_>, _>>().unwrap()) +}