|
|
@ -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"))?
|
|
|
|