mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-17 10:48:18 -07:00
Enable more lints and apply their suggestions
This commit is contained in:
parent
09895a20c8
commit
1c4d9af586
@ -475,7 +475,7 @@ pub async fn upgrade_room_route(
|
|||||||
PduBuilder {
|
PduBuilder {
|
||||||
event_type: EventType::RoomTombstone,
|
event_type: EventType::RoomTombstone,
|
||||||
content: to_raw_value(&RoomTombstoneEventContent {
|
content: to_raw_value(&RoomTombstoneEventContent {
|
||||||
body: "This room has been replaced".to_string(),
|
body: "This room has been replaced".to_owned(),
|
||||||
replacement_room: replacement_room.clone(),
|
replacement_room: replacement_room.clone(),
|
||||||
})
|
})
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
|
@ -499,13 +499,13 @@ impl Database {
|
|||||||
if let Some(parent_stateinfo) = states_parents.last() {
|
if let Some(parent_stateinfo) = states_parents.last() {
|
||||||
let statediffnew = current_state
|
let statediffnew = current_state
|
||||||
.difference(&parent_stateinfo.1)
|
.difference(&parent_stateinfo.1)
|
||||||
.cloned()
|
.copied()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
let statediffremoved = parent_stateinfo
|
let statediffremoved = parent_stateinfo
|
||||||
.1
|
.1
|
||||||
.difference(¤t_state)
|
.difference(¤t_state)
|
||||||
.cloned()
|
.copied()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
(statediffnew, statediffremoved)
|
(statediffnew, statediffremoved)
|
||||||
|
@ -22,7 +22,7 @@ pub trait Tree: Send + Sync {
|
|||||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
||||||
|
|
||||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
|
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
|
||||||
fn insert_batch<'a>(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>;
|
fn insert_batch(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>;
|
||||||
|
|
||||||
fn remove(&self, key: &[u8]) -> Result<()>;
|
fn remove(&self, key: &[u8]) -> Result<()>;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ pub trait Tree: Send + Sync {
|
|||||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
||||||
|
|
||||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>;
|
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>;
|
||||||
fn increment_batch<'a>(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()>;
|
fn increment_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()>;
|
||||||
|
|
||||||
fn scan_prefix<'a>(
|
fn scan_prefix<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -81,7 +81,7 @@ impl KeyBackups {
|
|||||||
)?;
|
)?;
|
||||||
self.backupid_etag
|
self.backupid_etag
|
||||||
.insert(&key, &globals.next_count()?.to_be_bytes())?;
|
.insert(&key, &globals.next_count()?.to_be_bytes())?;
|
||||||
Ok(version.to_string())
|
Ok(version.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>> {
|
pub fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>> {
|
||||||
|
@ -136,7 +136,7 @@ impl std::str::FromStr for WildCardedDomain {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'de> serde::de::Deserialize<'de> for WildCardedDomain {
|
impl<'de> Deserialize<'de> for WildCardedDomain {
|
||||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: serde::de::Deserializer<'de>,
|
D: serde::de::Deserializer<'de>,
|
||||||
|
@ -50,7 +50,7 @@ pub type StateHashId = Vec<u8>;
|
|||||||
pub type CompressedStateEvent = [u8; 2 * size_of::<u64>()];
|
pub type CompressedStateEvent = [u8; 2 * size_of::<u64>()];
|
||||||
|
|
||||||
pub struct Rooms {
|
pub struct Rooms {
|
||||||
pub edus: edus::RoomEdus,
|
pub edus: RoomEdus,
|
||||||
pub(super) pduid_pdu: Arc<dyn Tree>, // PduId = ShortRoomId + Count
|
pub(super) pduid_pdu: Arc<dyn Tree>, // PduId = ShortRoomId + Count
|
||||||
pub(super) eventid_pduid: Arc<dyn Tree>,
|
pub(super) eventid_pduid: Arc<dyn Tree>,
|
||||||
pub(super) roomid_pduleaves: Arc<dyn Tree>,
|
pub(super) roomid_pduleaves: Arc<dyn Tree>,
|
||||||
@ -371,13 +371,13 @@ impl Rooms {
|
|||||||
{
|
{
|
||||||
let statediffnew = new_state_ids_compressed
|
let statediffnew = new_state_ids_compressed
|
||||||
.difference(&parent_stateinfo.1)
|
.difference(&parent_stateinfo.1)
|
||||||
.cloned()
|
.copied()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
let statediffremoved = parent_stateinfo
|
let statediffremoved = parent_stateinfo
|
||||||
.1
|
.1
|
||||||
.difference(&new_state_ids_compressed)
|
.difference(&new_state_ids_compressed)
|
||||||
.cloned()
|
.copied()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
(statediffnew, statediffremoved)
|
(statediffnew, statediffremoved)
|
||||||
@ -498,7 +498,7 @@ impl Rooms {
|
|||||||
if parent != 0_u64 {
|
if parent != 0_u64 {
|
||||||
let mut response = self.load_shortstatehash_info(parent)?;
|
let mut response = self.load_shortstatehash_info(parent)?;
|
||||||
let mut state = response.last().unwrap().1.clone();
|
let mut state = response.last().unwrap().1.clone();
|
||||||
state.extend(added.iter().cloned());
|
state.extend(added.iter().copied());
|
||||||
for r in &removed {
|
for r in &removed {
|
||||||
state.remove(r);
|
state.remove(r);
|
||||||
}
|
}
|
||||||
@ -1773,13 +1773,13 @@ impl Rooms {
|
|||||||
if let Some(parent_stateinfo) = states_parents.last() {
|
if let Some(parent_stateinfo) = states_parents.last() {
|
||||||
let statediffnew = state_ids_compressed
|
let statediffnew = state_ids_compressed
|
||||||
.difference(&parent_stateinfo.1)
|
.difference(&parent_stateinfo.1)
|
||||||
.cloned()
|
.copied()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
let statediffremoved = parent_stateinfo
|
let statediffremoved = parent_stateinfo
|
||||||
.1
|
.1
|
||||||
.difference(&state_ids_compressed)
|
.difference(&state_ids_compressed)
|
||||||
.cloned()
|
.copied()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
(statediffnew, statediffremoved)
|
(statediffnew, statediffremoved)
|
||||||
|
@ -331,7 +331,7 @@ impl RoomEdus {
|
|||||||
&self,
|
&self,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
presence: ruma::events::presence::PresenceEvent,
|
presence: PresenceEvent,
|
||||||
globals: &super::super::globals::Globals,
|
globals: &super::super::globals::Globals,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// TODO: Remove old entry? Or maybe just wipe completely from time to time?
|
// TODO: Remove old entry? Or maybe just wipe completely from time to time?
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
#![warn(
|
||||||
|
rust_2018_idioms,
|
||||||
|
unused_qualifications,
|
||||||
|
clippy::cloned_instead_of_copied,
|
||||||
|
clippy::str_to_string
|
||||||
|
)]
|
||||||
#![allow(clippy::suspicious_else_formatting)]
|
#![allow(clippy::suspicious_else_formatting)]
|
||||||
#![deny(clippy::dbg_macro)]
|
#![deny(clippy::dbg_macro)]
|
||||||
|
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
#![warn(rust_2018_idioms)]
|
#![warn(
|
||||||
|
rust_2018_idioms,
|
||||||
|
unused_qualifications,
|
||||||
|
clippy::cloned_instead_of_copied,
|
||||||
|
clippy::str_to_string
|
||||||
|
)]
|
||||||
#![allow(clippy::suspicious_else_formatting)]
|
#![allow(clippy::suspicious_else_formatting)]
|
||||||
#![deny(clippy::dbg_macro)]
|
#![deny(clippy::dbg_macro)]
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ impl PduEvent {
|
|||||||
mut json: CanonicalJsonObject,
|
mut json: CanonicalJsonObject,
|
||||||
) -> Result<Self, serde_json::Error> {
|
) -> Result<Self, serde_json::Error> {
|
||||||
json.insert(
|
json.insert(
|
||||||
"event_id".to_string(),
|
"event_id".to_owned(),
|
||||||
CanonicalJsonValue::String(event_id.as_str().to_owned()),
|
CanonicalJsonValue::String(event_id.as_str().to_owned()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ impl<T: Outgoing> Deref for Ruma<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This struct converts ruma responses into rocket http responses.
|
/// This struct converts ruma responses into rocket http responses.
|
||||||
pub type ConduitResult<T> = std::result::Result<RumaResponse<T>, Error>;
|
pub type ConduitResult<T> = Result<RumaResponse<T>, Error>;
|
||||||
|
|
||||||
pub fn response<T: OutgoingResponse>(response: RumaResponse<T>) -> response::Result<'static> {
|
pub fn response<T: OutgoingResponse>(response: RumaResponse<T>) -> response::Result<'static> {
|
||||||
let http_response = response
|
let http_response = response
|
||||||
|
@ -336,7 +336,7 @@ fn add_port_to_hostname(destination_str: &str) -> FedDest {
|
|||||||
None => (destination_str, ":8448"),
|
None => (destination_str, ":8448"),
|
||||||
Some(pos) => destination_str.split_at(pos),
|
Some(pos) => destination_str.split_at(pos),
|
||||||
};
|
};
|
||||||
FedDest::Named(host.to_string(), port.to_string())
|
FedDest::Named(host.to_owned(), port.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns: actual_destination, host header
|
/// Returns: actual_destination, host header
|
||||||
@ -358,7 +358,7 @@ async fn find_actual_destination(
|
|||||||
if let Some(pos) = destination_str.find(':') {
|
if let Some(pos) = destination_str.find(':') {
|
||||||
// 2: Hostname with included port
|
// 2: Hostname with included port
|
||||||
let (host, port) = destination_str.split_at(pos);
|
let (host, port) = destination_str.split_at(pos);
|
||||||
FedDest::Named(host.to_string(), port.to_string())
|
FedDest::Named(host.to_owned(), port.to_owned())
|
||||||
} else {
|
} else {
|
||||||
match request_well_known(globals, destination.as_str()).await {
|
match request_well_known(globals, destination.as_str()).await {
|
||||||
// 3: A .well-known file is available
|
// 3: A .well-known file is available
|
||||||
@ -370,7 +370,7 @@ async fn find_actual_destination(
|
|||||||
if let Some(pos) = delegated_hostname.find(':') {
|
if let Some(pos) = delegated_hostname.find(':') {
|
||||||
// 3.2: Hostname with port in .well-known file
|
// 3.2: Hostname with port in .well-known file
|
||||||
let (host, port) = delegated_hostname.split_at(pos);
|
let (host, port) = delegated_hostname.split_at(pos);
|
||||||
FedDest::Named(host.to_string(), port.to_string())
|
FedDest::Named(host.to_owned(), port.to_owned())
|
||||||
} else {
|
} else {
|
||||||
// Delegated hostname has no port in this branch
|
// Delegated hostname has no port in this branch
|
||||||
if let Some(hostname_override) =
|
if let Some(hostname_override) =
|
||||||
@ -454,12 +454,12 @@ async fn find_actual_destination(
|
|||||||
let hostname = if let Ok(addr) = hostname.parse::<SocketAddr>() {
|
let hostname = if let Ok(addr) = hostname.parse::<SocketAddr>() {
|
||||||
FedDest::Literal(addr)
|
FedDest::Literal(addr)
|
||||||
} else if let Ok(addr) = hostname.parse::<IpAddr>() {
|
} else if let Ok(addr) = hostname.parse::<IpAddr>() {
|
||||||
FedDest::Named(addr.to_string(), ":8448".to_string())
|
FedDest::Named(addr.to_string(), ":8448".to_owned())
|
||||||
} else if let Some(pos) = hostname.find(':') {
|
} else if let Some(pos) = hostname.find(':') {
|
||||||
let (host, port) = hostname.split_at(pos);
|
let (host, port) = hostname.split_at(pos);
|
||||||
FedDest::Named(host.to_string(), port.to_string())
|
FedDest::Named(host.to_owned(), port.to_owned())
|
||||||
} else {
|
} else {
|
||||||
FedDest::Named(hostname, ":8448".to_string())
|
FedDest::Named(hostname, ":8448".to_owned())
|
||||||
};
|
};
|
||||||
(actual_destination, hostname)
|
(actual_destination, hostname)
|
||||||
}
|
}
|
||||||
@ -476,11 +476,7 @@ async fn query_srv_record(
|
|||||||
.map(|srv| {
|
.map(|srv| {
|
||||||
srv.iter().next().map(|result| {
|
srv.iter().next().map(|result| {
|
||||||
FedDest::Named(
|
FedDest::Named(
|
||||||
result
|
result.target().to_string().trim_end_matches('.').to_owned(),
|
||||||
.target()
|
|
||||||
.to_string()
|
|
||||||
.trim_end_matches('.')
|
|
||||||
.to_string(),
|
|
||||||
format!(":{}", result.port()),
|
format!(":{}", result.port()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -745,7 +741,7 @@ pub async fn send_transaction_message_route(
|
|||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => {
|
None => {
|
||||||
// Event is invalid
|
// Event is invalid
|
||||||
resolved_map.insert(event_id, Err("Event needs a valid RoomId.".to_string()));
|
resolved_map.insert(event_id, Err("Event needs a valid RoomId.".to_owned()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -963,7 +959,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||||||
match db.rooms.exists(room_id) {
|
match db.rooms.exists(room_id) {
|
||||||
Ok(true) => {}
|
Ok(true) => {}
|
||||||
_ => {
|
_ => {
|
||||||
return Err("Room is unknown to this server.".to_string());
|
return Err("Room is unknown to this server.".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1173,14 +1169,14 @@ fn handle_outlier_pdu<'a>(
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Drop
|
// Drop
|
||||||
warn!("Dropping bad event {}: {}", event_id, e);
|
warn!("Dropping bad event {}: {}", event_id, e);
|
||||||
return Err("Signature verification failed".to_string());
|
return Err("Signature verification failed".to_owned());
|
||||||
}
|
}
|
||||||
Ok(ruma::signatures::Verified::Signatures) => {
|
Ok(ruma::signatures::Verified::Signatures) => {
|
||||||
// Redact
|
// Redact
|
||||||
warn!("Calculated hash does not match: {}", event_id);
|
warn!("Calculated hash does not match: {}", event_id);
|
||||||
match ruma::signatures::redact(&value, room_version_id) {
|
match ruma::signatures::redact(&value, room_version_id) {
|
||||||
Ok(obj) => obj,
|
Ok(obj) => obj,
|
||||||
Err(_) => return Err("Redaction failed".to_string()),
|
Err(_) => return Err("Redaction failed".to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ruma::signatures::Verified::All) => value,
|
Ok(ruma::signatures::Verified::All) => value,
|
||||||
@ -1195,7 +1191,7 @@ fn handle_outlier_pdu<'a>(
|
|||||||
let incoming_pdu = serde_json::from_value::<PduEvent>(
|
let incoming_pdu = serde_json::from_value::<PduEvent>(
|
||||||
serde_json::to_value(&val).expect("CanonicalJsonObj is a valid JsonValue"),
|
serde_json::to_value(&val).expect("CanonicalJsonObj is a valid JsonValue"),
|
||||||
)
|
)
|
||||||
.map_err(|_| "Event is not a valid PDU.".to_string())?;
|
.map_err(|_| "Event is not a valid PDU.".to_owned())?;
|
||||||
|
|
||||||
// 4. fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events
|
// 4. fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events
|
||||||
// 5. Reject "due to auth events" if can't get all the auth events or some of the auth events are also rejected "due to auth events"
|
// 5. Reject "due to auth events" if can't get all the auth events or some of the auth events are also rejected "due to auth events"
|
||||||
@ -1280,9 +1276,9 @@ fn handle_outlier_pdu<'a>(
|
|||||||
None::<PduEvent>, // TODO: third party invite
|
None::<PduEvent>, // TODO: third party invite
|
||||||
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
|
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
|
||||||
)
|
)
|
||||||
.map_err(|_e| "Auth check failed".to_string())?
|
.map_err(|_e| "Auth check failed".to_owned())?
|
||||||
{
|
{
|
||||||
return Err("Event has failed auth check with auth events.".to_string());
|
return Err("Event has failed auth check with auth events.".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Validation successful.");
|
debug!("Validation successful.");
|
||||||
@ -2256,7 +2252,7 @@ pub(crate) fn get_auth_chain<'a>(
|
|||||||
.collect::<Vec<u64>>();
|
.collect::<Vec<u64>>();
|
||||||
if let Some(cached) = db.rooms.get_auth_chain_from_cache(&chunk_key)? {
|
if let Some(cached) = db.rooms.get_auth_chain_from_cache(&chunk_key)? {
|
||||||
hits += 1;
|
hits += 1;
|
||||||
full_auth_chain.extend(cached.iter().cloned());
|
full_auth_chain.extend(cached.iter().copied());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
misses += 1;
|
misses += 1;
|
||||||
@ -2267,7 +2263,7 @@ pub(crate) fn get_auth_chain<'a>(
|
|||||||
for (sevent_id, event_id) in chunk {
|
for (sevent_id, event_id) in chunk {
|
||||||
if let Some(cached) = db.rooms.get_auth_chain_from_cache(&[sevent_id])? {
|
if let Some(cached) = db.rooms.get_auth_chain_from_cache(&[sevent_id])? {
|
||||||
hits2 += 1;
|
hits2 += 1;
|
||||||
chunk_cache.extend(cached.iter().cloned());
|
chunk_cache.extend(cached.iter().copied());
|
||||||
} else {
|
} else {
|
||||||
misses2 += 1;
|
misses2 += 1;
|
||||||
let auth_chain = Arc::new(get_auth_chain_inner(room_id, &event_id, db)?);
|
let auth_chain = Arc::new(get_auth_chain_inner(room_id, &event_id, db)?);
|
||||||
@ -3385,10 +3381,10 @@ pub(crate) async fn fetch_join_signing_keys(
|
|||||||
// Try to fetch keys, failure is okay
|
// Try to fetch keys, failure is okay
|
||||||
// Servers we couldn't find in the cache will be added to `servers`
|
// Servers we couldn't find in the cache will be added to `servers`
|
||||||
for pdu in &event.room_state.state {
|
for pdu in &event.room_state.state {
|
||||||
let _ = get_server_keys_from_cache(&pdu, &mut servers, room_version, &mut pkm, db);
|
let _ = get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm, db);
|
||||||
}
|
}
|
||||||
for pdu in &event.room_state.auth_chain {
|
for pdu in &event.room_state.auth_chain {
|
||||||
let _ = get_server_keys_from_cache(&pdu, &mut servers, room_version, &mut pkm, db);
|
let _ = get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(pkm);
|
drop(pkm);
|
||||||
|
@ -123,7 +123,7 @@ pub fn deserialize_from_str<
|
|||||||
E: std::fmt::Display,
|
E: std::fmt::Display,
|
||||||
>(
|
>(
|
||||||
deserializer: D,
|
deserializer: D,
|
||||||
) -> std::result::Result<T, D::Error> {
|
) -> Result<T, D::Error> {
|
||||||
struct Visitor<T: FromStr<Err = E>, E>(std::marker::PhantomData<T>);
|
struct Visitor<T: FromStr<Err = E>, E>(std::marker::PhantomData<T>);
|
||||||
impl<'de, T: FromStr<Err = Err>, Err: std::fmt::Display> serde::de::Visitor<'de>
|
impl<'de, T: FromStr<Err = Err>, Err: std::fmt::Display> serde::de::Visitor<'de>
|
||||||
for Visitor<T, Err>
|
for Visitor<T, Err>
|
||||||
|
Loading…
Reference in New Issue
Block a user