mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-27 21:13:47 +03:00
Fix clippy warnings remove unused imports
This commit is contained in:
parent
63af3d3da0
commit
cdeb1236a2
7 changed files with 39 additions and 34 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2127,7 +2127,7 @@ checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "state-res"
|
name = "state-res"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/ruma/state-res?branch=event-trait#bfadbdf57e26f26c2ea5b2ed50ce3e5f6fb914cd"
|
source = "git+https://github.com/ruma/state-res?branch=event-trait#e5d32e44adb66c5932a81d2c8a8d840abd17c870"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools",
|
"itertools",
|
||||||
"maplit",
|
"maplit",
|
||||||
|
|
|
@ -25,7 +25,7 @@ where
|
||||||
|
|
||||||
let mut parts = http_request.uri().clone().into_parts();
|
let mut parts = http_request.uri().clone().into_parts();
|
||||||
let old_path_and_query = parts.path_and_query.unwrap().as_str().to_owned();
|
let old_path_and_query = parts.path_and_query.unwrap().as_str().to_owned();
|
||||||
let symbol = if old_path_and_query.contains("?") {
|
let symbol = if old_path_and_query.contains('?') {
|
||||||
"&"
|
"&"
|
||||||
} else {
|
} else {
|
||||||
"?"
|
"?"
|
||||||
|
|
|
@ -675,7 +675,6 @@ async fn join_room_by_id_helper(
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|id| resolved_events.values().any(|rid| rid == *id))
|
.filter(|id| resolved_events.values().any(|rid| rid == *id))
|
||||||
{
|
{
|
||||||
// this is a `state_res::StateEvent` that holds a `ruma::Pdu`
|
|
||||||
let pdu = event_map
|
let pdu = event_map
|
||||||
.get(ev_id)
|
.get(ev_id)
|
||||||
.expect("Found event_id in sorted events that is not in resolved state");
|
.expect("Found event_id in sorted events that is not in resolved state");
|
||||||
|
|
|
@ -9,9 +9,11 @@ use trust_dns_resolver::TokioAsyncResolver;
|
||||||
|
|
||||||
pub const COUNTER: &str = "c";
|
pub const COUNTER: &str = "c";
|
||||||
|
|
||||||
|
pub type DestinationCache = Arc<RwLock<HashMap<Box<ServerName>, (String, Option<String>)>>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
pub actual_destination_cache: Arc<RwLock<HashMap<Box<ServerName>, (String, Option<String>)>>>, // actual_destination, host
|
pub actual_destination_cache: DestinationCache, // actual_destination, host
|
||||||
pub(super) globals: sled::Tree,
|
pub(super) globals: sled::Tree,
|
||||||
config: Config,
|
config: Config,
|
||||||
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl Sending {
|
||||||
match response {
|
match response {
|
||||||
Ok((server, is_appservice)) => {
|
Ok((server, is_appservice)) => {
|
||||||
let mut prefix = if is_appservice {
|
let mut prefix = if is_appservice {
|
||||||
"+".as_bytes().to_vec()
|
b"+".to_vec()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
@ -125,7 +125,7 @@ impl Sending {
|
||||||
Err((server, is_appservice, e)) => {
|
Err((server, is_appservice, e)) => {
|
||||||
info!("Couldn't send transaction to {}\n{}", server, e);
|
info!("Couldn't send transaction to {}\n{}", server, e);
|
||||||
let mut prefix = if is_appservice {
|
let mut prefix = if is_appservice {
|
||||||
"+".as_bytes().to_vec()
|
b"+".to_vec()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
@ -157,7 +157,7 @@ impl Sending {
|
||||||
.map_err(|_| Error::bad_database("ServerName in servernamepduid bytes are invalid."))
|
.map_err(|_| Error::bad_database("ServerName in servernamepduid bytes are invalid."))
|
||||||
.map(|server_str| {
|
.map(|server_str| {
|
||||||
// Appservices start with a plus
|
// Appservices start with a plus
|
||||||
if server_str.starts_with("+") {
|
if server_str.starts_with('+') {
|
||||||
(server_str[1..].to_owned(), true)
|
(server_str[1..].to_owned(), true)
|
||||||
} else {
|
} else {
|
||||||
(server_str, false)
|
(server_str, false)
|
||||||
|
@ -186,7 +186,7 @@ impl Sending {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut prefix = if *is_appservice {
|
let mut prefix = if *is_appservice {
|
||||||
"+".as_bytes().to_vec()
|
b"+".to_vec()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
@ -220,7 +220,7 @@ impl Sending {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_pdu_appservice(&self, appservice_id: &str, pdu_id: &[u8]) -> Result<()> {
|
pub fn send_pdu_appservice(&self, appservice_id: &str, pdu_id: &[u8]) -> Result<()> {
|
||||||
let mut key = "+".as_bytes().to_vec();
|
let mut key = b"+".to_vec();
|
||||||
key.extend_from_slice(appservice_id.as_bytes());
|
key.extend_from_slice(appservice_id.as_bytes());
|
||||||
key.push(0xff);
|
key.push(0xff);
|
||||||
key.extend_from_slice(pdu_id);
|
key.extend_from_slice(pdu_id);
|
||||||
|
@ -330,7 +330,7 @@ impl Sending {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Appservices start with a plus
|
// Appservices start with a plus
|
||||||
let (server, is_appservice) = if server.starts_with("+") {
|
let (server, is_appservice) = if server.starts_with('+') {
|
||||||
(&server[1..], true)
|
(&server[1..], true)
|
||||||
} else {
|
} else {
|
||||||
(&*server, false)
|
(&*server, false)
|
||||||
|
|
|
@ -9,12 +9,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::{
|
use std::{collections::BTreeMap, convert::TryFrom, time::UNIX_EPOCH};
|
||||||
collections::BTreeMap,
|
|
||||||
convert::{TryFrom, TryInto},
|
|
||||||
sync::Arc,
|
|
||||||
time::UNIX_EPOCH,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize, Debug)]
|
#[derive(Clone, Deserialize, Serialize, Debug)]
|
||||||
pub struct PduEvent {
|
pub struct PduEvent {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{client_server, pdu, utils, ConduitResult, Database, Error, PduEvent, Result, Ruma};
|
use crate::{client_server, utils, ConduitResult, Database, Error, PduEvent, Result, Ruma};
|
||||||
use get_profile_information::v1::ProfileField;
|
use get_profile_information::v1::ProfileField;
|
||||||
use http::header::{HeaderValue, AUTHORIZATION, HOST};
|
use http::header::{HeaderValue, AUTHORIZATION, HOST};
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
|
@ -11,14 +11,13 @@ use ruma::{
|
||||||
get_server_keys, get_server_version::v1 as get_server_version, ServerSigningKeys,
|
get_server_keys, get_server_version::v1 as get_server_version, ServerSigningKeys,
|
||||||
VerifyKey,
|
VerifyKey,
|
||||||
},
|
},
|
||||||
event::{get_event, get_missing_events, get_room_state, get_room_state_ids},
|
event::{get_event, get_missing_events, get_room_state_ids},
|
||||||
query::get_profile_information,
|
query::get_profile_information,
|
||||||
transactions::send_transaction_message,
|
transactions::send_transaction_message,
|
||||||
},
|
},
|
||||||
OutgoingRequest,
|
OutgoingRequest,
|
||||||
},
|
},
|
||||||
directory::{IncomingFilter, IncomingRoomNetwork},
|
directory::{IncomingFilter, IncomingRoomNetwork},
|
||||||
serde::Raw,
|
|
||||||
signatures::{CanonicalJsonObject, PublicKeyMap},
|
signatures::{CanonicalJsonObject, PublicKeyMap},
|
||||||
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
|
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
|
||||||
};
|
};
|
||||||
|
@ -220,7 +219,7 @@ fn add_port_to_hostname(destination_str: String) -> String {
|
||||||
/// Numbers in comments below refer to bullet points in linked section of specification
|
/// Numbers in comments below refer to bullet points in linked section of specification
|
||||||
async fn find_actual_destination(
|
async fn find_actual_destination(
|
||||||
globals: &crate::database::globals::Globals,
|
globals: &crate::database::globals::Globals,
|
||||||
destination: &Box<ServerName>,
|
destination: &ServerName,
|
||||||
) -> (String, Option<String>) {
|
) -> (String, Option<String>) {
|
||||||
let mut host = None;
|
let mut host = None;
|
||||||
|
|
||||||
|
@ -594,13 +593,14 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let server_name = body.body.origin.clone();
|
||||||
let event = Arc::new(pdu.clone());
|
let event = Arc::new(pdu.clone());
|
||||||
|
// Fetch any unknown events or retrieve them from the DB
|
||||||
let previous = pdu
|
let previous =
|
||||||
.prev_events
|
match fetch_events(&db, server_name.clone(), &pub_key_map, &pdu.prev_events).await? {
|
||||||
.first()
|
mut evs if evs.len() == 1 => Some(Arc::new(evs.remove(0))),
|
||||||
.map(|id| db.rooms.get_pdu(id).expect("todo").map(Arc::new))
|
_ => None,
|
||||||
.flatten();
|
};
|
||||||
|
|
||||||
// 4. Passes authorization rules based on the event's auth events, otherwise it is rejected.
|
// 4. Passes authorization rules based on the event's auth events, otherwise it is rejected.
|
||||||
// TODO: To me this sounds more like the auth_events should be get the pdu.auth_events not
|
// TODO: To me this sounds more like the auth_events should be get the pdu.auth_events not
|
||||||
|
@ -616,14 +616,14 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
|
|
||||||
let mut event_map: state_res::EventMap<Arc<PduEvent>> = auth_events
|
let mut event_map: state_res::EventMap<Arc<PduEvent>> = auth_events
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, v)| (v.event_id().clone(), Arc::new(v.clone())))
|
.map(|(_k, v)| (v.event_id().clone(), Arc::new(v.clone())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !state_res::event_auth::auth_check(
|
if !state_res::event_auth::auth_check(
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::Version6,
|
||||||
&event,
|
&event,
|
||||||
previous.clone(),
|
previous.clone(),
|
||||||
auth_events
|
&auth_events
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, Arc::new(v)))
|
.map(|(k, v)| (k, Arc::new(v)))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -638,7 +638,6 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let server_name = body.body.origin.clone();
|
|
||||||
let (state_at_event, incoming_auth_events): (StateMap<Arc<PduEvent>>, _) = match db
|
let (state_at_event, incoming_auth_events): (StateMap<Arc<PduEvent>>, _) = match db
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(
|
||||||
|
@ -652,8 +651,18 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
let state = fetch_events(&db, server_name.clone(), &pub_key_map, &res.pdu_ids)
|
let state =
|
||||||
.await?
|
fetch_events(&db, server_name.clone(), &pub_key_map, &res.pdu_ids).await?;
|
||||||
|
// Sanity check: there are no conflicting events in the state we received
|
||||||
|
let mut seen = BTreeSet::new();
|
||||||
|
for ev in &state {
|
||||||
|
// If the key is already present
|
||||||
|
if !seen.insert((&ev.kind, &ev.state_key)) {
|
||||||
|
todo!("Server sent us an invalid state")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = state
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|pdu| ((pdu.kind.clone(), pdu.state_key.clone()), Arc::new(pdu)))
|
.map(|pdu| ((pdu.kind.clone(), pdu.state_key.clone()), Arc::new(pdu)))
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -677,8 +686,8 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::Version6,
|
||||||
&event,
|
&event,
|
||||||
previous.clone(),
|
previous.clone(),
|
||||||
state_at_event.clone(), // TODO: could this be &state avoid .clone
|
&state_at_event,
|
||||||
None, // TODO: third party invite
|
None, // TODO: third party invite
|
||||||
)
|
)
|
||||||
.map_err(|_e| Error::Conflict("Auth check failed"))?
|
.map_err(|_e| Error::Conflict("Auth check failed"))?
|
||||||
{
|
{
|
||||||
|
@ -760,7 +769,7 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::Version6,
|
||||||
&event,
|
&event,
|
||||||
previous,
|
previous,
|
||||||
state_at_forks,
|
&state_at_forks,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.map_err(|_e| Error::Conflict("Auth check failed"))?
|
.map_err(|_e| Error::Conflict("Auth check failed"))?
|
||||||
|
|
Loading…
Reference in a new issue