chore: get rid of warnings

next
Timo Kösters 2021-03-24 11:52:10 +01:00
parent e50f2864de
commit 16eed1d8c2
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
9 changed files with 82 additions and 96 deletions

View File

@ -267,12 +267,10 @@ pub async fn get_backup_key_session_route(
let key_data = db let key_data = db
.key_backups .key_backups
.get_session(&sender_user, &body.version, &body.room_id, &body.session_id)? .get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?
.ok_or_else(|| { .ok_or(Error::BadRequest(
Error::BadRequest(
ErrorKind::NotFound, ErrorKind::NotFound,
"Backup key not found for this user's session.", "Backup key not found for this user's session.",
) ))?;
})?;
Ok(get_backup_key_session::Response { key_data }.into()) Ok(get_backup_key_session::Response { key_data }.into())
} }

View File

@ -3,7 +3,10 @@ use crate::{ConduitResult, Database, Error, Ruma};
use ruma::{ use ruma::{
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
r0::config::{get_room_account_data, get_global_account_data, set_room_account_data, set_global_account_data}, r0::config::{
get_global_account_data, get_room_account_data, set_global_account_data,
set_room_account_data,
},
}, },
events::{custom::CustomEventContent, BasicEvent}, events::{custom::CustomEventContent, BasicEvent},
serde::Raw, serde::Raw,
@ -45,7 +48,10 @@ pub async fn set_global_account_data_route(
#[cfg_attr( #[cfg_attr(
feature = "conduit_bin", feature = "conduit_bin",
put("/_matrix/client/r0/user/<_>/rooms/<_>/account_data/<_>", data = "<body>") put(
"/_matrix/client/r0/user/<_>/rooms/<_>/account_data/<_>",
data = "<body>"
)
)] )]
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, body))]
pub async fn set_room_account_data_route( pub async fn set_room_account_data_route(
@ -97,7 +103,10 @@ pub async fn get_global_account_data_route(
#[cfg_attr( #[cfg_attr(
feature = "conduit_bin", feature = "conduit_bin",
get("/_matrix/client/r0/user/<_>/rooms/<_>/account_data/<_>", data = "<body>") get(
"/_matrix/client/r0/user/<_>/rooms/<_>/account_data/<_>",
data = "<body>"
)
)] )]
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, body))]
pub async fn get_room_account_data_route( pub async fn get_room_account_data_route(
@ -108,7 +117,11 @@ pub async fn get_room_account_data_route(
let data = db let data = db
.account_data .account_data
.get::<Raw<ruma::events::AnyBasicEvent>>(Some(&body.room_id), sender_user, body.event_type.clone().into())? .get::<Raw<ruma::events::AnyBasicEvent>>(
Some(&body.room_id),
sender_user,
body.event_type.clone().into(),
)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
db.flush().await?; db.flush().await?;

View File

@ -136,9 +136,7 @@ pub async fn sync_events_route(
.map(|since_shortstatehash| { .map(|since_shortstatehash| {
Ok::<_, Error>( Ok::<_, Error>(
since_shortstatehash since_shortstatehash
.map(|since_shortstatehash| { .map(|since_shortstatehash| db.rooms.state_full(since_shortstatehash))
db.rooms.state_full(&room_id, since_shortstatehash)
})
.transpose()?, .transpose()?,
) )
}) })
@ -512,12 +510,7 @@ pub async fn sync_events_route(
}) })
.and_then(|shortstatehash| { .and_then(|shortstatehash| {
db.rooms db.rooms
.state_get( .state_get(shortstatehash, &EventType::RoomMember, sender_user.as_str())
&room_id,
shortstatehash,
&EventType::RoomMember,
sender_user.as_str(),
)
.ok()? .ok()?
.ok_or_else(|| Error::bad_database("State hash in db doesn't have a state.")) .ok_or_else(|| Error::bad_database("State hash in db doesn't have a state."))
.ok() .ok()

View File

@ -1,7 +1,6 @@
use crate::ConduitResult; use crate::ConduitResult;
use ruma::api::client::r0::thirdparty::get_protocols; use ruma::api::client::r0::thirdparty::get_protocols;
use log::warn;
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
use rocket::get; use rocket::get;
use std::collections::BTreeMap; use std::collections::BTreeMap;

View File

@ -55,9 +55,7 @@ impl Appservice {
}) })
} }
pub fn iter_all<'a>( pub fn iter_all(&self) -> impl Iterator<Item = Result<(String, serde_yaml::Value)>> + '_ {
&'a self,
) -> impl Iterator<Item = Result<(String, serde_yaml::Value)>> + 'a {
self.iter_ids().filter_map(|id| id.ok()).map(move |id| { self.iter_ids().filter_map(|id| id.ok()).map(move |id| {
Ok(( Ok((
id.clone(), id.clone(),

View File

@ -262,7 +262,7 @@ impl Media {
} }
}; };
image.thumbnail_exact(dbg!(exact_width), dbg!(exact_height)) image.thumbnail_exact(exact_width, exact_height)
}; };
let mut thumbnail_bytes = Vec::new(); let mut thumbnail_bytes = Vec::new();

View File

@ -108,7 +108,6 @@ impl Rooms {
pub fn state_full( pub fn state_full(
&self, &self,
room_id: &RoomId,
shortstatehash: u64, shortstatehash: u64,
) -> Result<BTreeMap<(EventType, String), PduEvent>> { ) -> Result<BTreeMap<(EventType, String), PduEvent>> {
Ok(self Ok(self
@ -151,7 +150,6 @@ impl Rooms {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn state_get( pub fn state_get(
&self, &self,
room_id: &RoomId,
shortstatehash: u64, shortstatehash: u64,
event_type: &EventType, event_type: &EventType,
state_key: &str, state_key: &str,
@ -257,11 +255,11 @@ impl Rooms {
/// Generate a new StateHash. /// Generate a new StateHash.
/// ///
/// A unique hash made from hashing all PDU ids of the state joined with 0xff. /// A unique hash made from hashing all PDU ids of the state joined with 0xff.
fn calculate_hash(&self, bytes_list: &[&[u8]]) -> Result<StateHashId> { fn calculate_hash(&self, bytes_list: &[&[u8]]) -> StateHashId {
// We only hash the pdu's event ids, not the whole pdu // We only hash the pdu's event ids, not the whole pdu
let bytes = bytes_list.join(&0xff); let bytes = bytes_list.join(&0xff);
let hash = digest::digest(&digest::SHA256, &bytes); let hash = digest::digest(&digest::SHA256, &bytes);
Ok(hash.as_ref().into()) hash.as_ref().into()
} }
/// Checks if a room exists. /// Checks if a room exists.
@ -291,7 +289,7 @@ impl Rooms {
.values() .values()
.map(|event_id| event_id.as_bytes()) .map(|event_id| event_id.as_bytes())
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
)?; );
let shortstatehash = match self.statehash_shortstatehash.get(&state_hash)? { let shortstatehash = match self.statehash_shortstatehash.get(&state_hash)? {
Some(shortstatehash) => { Some(shortstatehash) => {
@ -353,7 +351,7 @@ impl Rooms {
room_id: &RoomId, room_id: &RoomId,
) -> Result<BTreeMap<(EventType, String), PduEvent>> { ) -> Result<BTreeMap<(EventType, String), PduEvent>> {
if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? { if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? {
self.state_full(&room_id, current_shortstatehash) self.state_full(current_shortstatehash)
} else { } else {
Ok(BTreeMap::new()) Ok(BTreeMap::new())
} }
@ -368,7 +366,7 @@ impl Rooms {
state_key: &str, state_key: &str,
) -> Result<Option<PduEvent>> { ) -> Result<Option<PduEvent>> {
if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? { if let Some(current_shortstatehash) = self.current_shortstatehash(room_id)? {
self.state_get(&room_id, current_shortstatehash, event_type, state_key) self.state_get(current_shortstatehash, event_type, state_key)
} else { } else {
Ok(None) Ok(None)
} }
@ -582,7 +580,7 @@ impl Rooms {
{ {
if let Some(shortstatehash) = self.pdu_shortstatehash(&pdu.event_id).unwrap() { if let Some(shortstatehash) = self.pdu_shortstatehash(&pdu.event_id).unwrap() {
if let Some(prev_state) = self if let Some(prev_state) = self
.state_get(&pdu.room_id, shortstatehash, &pdu.kind, &state_key) .state_get(shortstatehash, &pdu.kind, &state_key)
.unwrap() .unwrap()
{ {
unsigned.insert( unsigned.insert(
@ -849,7 +847,7 @@ impl Rooms {
.values() .values()
.map(|event_id| &**event_id) .map(|event_id| &**event_id)
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
)?; );
let shortstatehash = match self.statehash_shortstatehash.get(&new_state_hash)? { let shortstatehash = match self.statehash_shortstatehash.get(&new_state_hash)? {
Some(shortstatehash) => { Some(shortstatehash) => {

View File

@ -1,6 +1,6 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
convert::{TryFrom, TryInto}, convert::TryFrom,
fmt::Debug, fmt::Debug,
sync::Arc, sync::Arc,
time::{Duration, Instant, SystemTime}, time::{Duration, Instant, SystemTime},
@ -10,11 +10,11 @@ use crate::{
appservice_server, database::pusher, server_server, utils, Database, Error, PduEvent, Result, appservice_server, database::pusher, server_server, utils, Database, Error, PduEvent, Result,
}; };
use federation::transactions::send_transaction_message; use federation::transactions::send_transaction_message;
use log::{error, info, warn}; use log::{info, warn};
use ring::digest; use ring::digest;
use rocket::futures::stream::{FuturesUnordered, StreamExt}; use rocket::futures::stream::{FuturesUnordered, StreamExt};
use ruma::{ use ruma::{
api::{appservice, client::r0::push::Pusher, federation, OutgoingRequest}, api::{appservice, federation, OutgoingRequest},
events::{push_rules, EventType}, events::{push_rules, EventType},
uint, ServerName, UInt, UserId, uint, ServerName, UInt, UserId,
}; };
@ -264,7 +264,7 @@ impl Sending {
futures.push( futures.push(
Self::handle_event( Self::handle_event(
outgoing_kind, outgoing_kind,
vec![pdu_id.into()], vec![pdu_id],
&db, &db,
) )
); );
@ -395,13 +395,14 @@ impl Sending {
continue; continue;
} }
let userid = UserId::try_from(utils::string_from_bytes(user).map_err(|e| { let userid =
UserId::try_from(utils::string_from_bytes(user).map_err(|_| {
( (
OutgoingKind::Push(user.clone(), pushkey.clone()), OutgoingKind::Push(user.clone(), pushkey.clone()),
Error::bad_database("Invalid push user string in db."), Error::bad_database("Invalid push user string in db."),
) )
})?) })?)
.map_err(|e| { .map_err(|_| {
( (
OutgoingKind::Push(user.clone(), pushkey.clone()), OutgoingKind::Push(user.clone(), pushkey.clone()),
Error::bad_database("Invalid push user id in db."), Error::bad_database("Invalid push user id in db."),

View File

@ -21,10 +21,9 @@ use ruma::{
}, },
directory::{IncomingFilter, IncomingRoomNetwork}, directory::{IncomingFilter, IncomingRoomNetwork},
events::EventType, events::EventType,
identifiers::{KeyId, KeyName},
serde::to_canonical_value, serde::to_canonical_value,
signatures::{CanonicalJsonObject, CanonicalJsonValue, PublicKeyMap}, signatures::{CanonicalJsonObject, CanonicalJsonValue, PublicKeyMap},
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, SigningKeyAlgorithm, UserId, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
}; };
use state_res::{Event, EventMap, StateMap}; use state_res::{Event, EventMap, StateMap};
use std::{ use std::{
@ -788,20 +787,14 @@ pub async fn send_transaction_message_route<'a>(
// This will create the state after any state snapshot it builds // This will create the state after any state snapshot it builds
// So current_state will have the incoming event inserted to it // So current_state will have the incoming event inserted to it
let mut fork_states = match build_forward_extremity_snapshots( let mut fork_states =
&db, match build_forward_extremity_snapshots(&db, pdu.clone(), current_state, &extremities)
pdu.clone(),
server_name,
current_state,
&extremities,
&pub_key_map,
&mut auth_cache,
)
.await .await
{ {
Ok(states) => states, Ok(states) => states,
Err(_) => { Err(_) => {
resolved_map.insert(event_id, Err("Failed to gather forward extremities".into())); resolved_map
.insert(event_id, Err("Failed to gather forward extremities".into()));
continue; continue;
} }
}; };
@ -1320,11 +1313,8 @@ pub(crate) async fn calculate_forward_extremities(
pub(crate) async fn build_forward_extremity_snapshots( pub(crate) async fn build_forward_extremity_snapshots(
db: &Database, db: &Database,
pdu: Arc<PduEvent>, pdu: Arc<PduEvent>,
origin: &ServerName,
mut current_state: StateMap<Arc<PduEvent>>, mut current_state: StateMap<Arc<PduEvent>>,
current_leaves: &[EventId], current_leaves: &[EventId],
pub_key_map: &PublicKeyMap,
auth_cache: &mut EventMap<Arc<PduEvent>>,
) -> Result<BTreeSet<StateMap<Arc<PduEvent>>>> { ) -> Result<BTreeSet<StateMap<Arc<PduEvent>>>> {
let current_shortstatehash = db.rooms.current_shortstatehash(pdu.room_id())?; let current_shortstatehash = db.rooms.current_shortstatehash(pdu.room_id())?;
@ -1354,7 +1344,7 @@ pub(crate) async fn build_forward_extremity_snapshots(
let mut state_before = db let mut state_before = db
.rooms .rooms
.state_full(pdu.room_id(), pdu_shortstatehash)? .state_full(pdu_shortstatehash)?
.into_iter() .into_iter()
.map(|(k, v)| ((k.0, Some(k.1)), Arc::new(v))) .map(|(k, v)| ((k.0, Some(k.1)), Arc::new(v)))
.collect::<StateMap<_>>(); .collect::<StateMap<_>>();
@ -1396,9 +1386,9 @@ pub(crate) fn update_resolved_state(
new_state.insert( new_state.insert(
( (
ev_type, ev_type,
state_k.ok_or_else(|| { state_k.ok_or(Error::Conflict(
Error::Conflict("update_resolved_state: State contained non state event") "update_resolved_state: State contained non state event",
})?, ))?,
), ),
pdu.event_id.clone(), pdu.event_id.clone(),
); );
@ -1426,9 +1416,9 @@ pub(crate) fn append_incoming_pdu(
new_state.insert( new_state.insert(
( (
ev_type.clone(), ev_type.clone(),
state_k.clone().ok_or_else(|| { state_k.clone().ok_or(Error::Conflict(
Error::Conflict("append_incoming_pdu: State contained non state event") "append_incoming_pdu: State contained non state event",
})?, ))?,
), ),
state_pdu.event_id.clone(), state_pdu.event_id.clone(),
); );
@ -1600,8 +1590,7 @@ pub fn get_room_state_ids_route<'a>(
let mut todo = BTreeSet::new(); let mut todo = BTreeSet::new();
todo.insert(body.event_id.clone()); todo.insert(body.event_id.clone());
loop { while let Some(event_id) = todo.iter().next().cloned() {
if let Some(event_id) = todo.iter().next().cloned() {
if let Some(pdu) = db.rooms.get_pdu(&event_id)? { if let Some(pdu) = db.rooms.get_pdu(&event_id)? {
todo.extend( todo.extend(
pdu.auth_events pdu.auth_events
@ -1617,9 +1606,6 @@ pub fn get_room_state_ids_route<'a>(
} }
todo.remove(&event_id); todo.remove(&event_id);
} else {
break;
}
} }
Ok(get_room_state_ids::v1::Response { Ok(get_room_state_ids::v1::Response {