Database Refactor

combine service/users data w/ mod unit

split sliding sync related out of service/users

instrument database entry points

remove increment crap from database interface

de-wrap all database get() calls

de-wrap all database insert() calls

de-wrap all database remove() calls

refactor database interface for async streaming

add query key serializer for database

implement Debug for result handle

add query deserializer for database

add deserialization trait for option handle

start a stream utils suite

de-wrap/asyncify/type-query count_one_time_keys()

de-wrap/asyncify users count

add admin query users command suite

de-wrap/asyncify users exists

de-wrap/partially asyncify user filter related

asyncify/de-wrap users device/keys related

asyncify/de-wrap user auth/misc related

asyncify/de-wrap users blurhash

asyncify/de-wrap account_data get; merge Data into Service

partial asyncify/de-wrap uiaa; merge Data into Service

partially asyncify/de-wrap transaction_ids get; merge Data into Service

partially asyncify/de-wrap key_backups; merge Data into Service

asyncify/de-wrap pusher service getters; merge Data into Service

asyncify/de-wrap rooms alias getters/some iterators

asyncify/de-wrap rooms directory getters/iterator

partially asyncify/de-wrap rooms lazy-loading

partially asyncify/de-wrap rooms metadata

asyncify/dewrap rooms outlier

asyncify/dewrap rooms pdu_metadata

dewrap/partially asyncify rooms read receipt

de-wrap rooms search service

de-wrap/partially asyncify rooms user service

partial de-wrap rooms state_compressor

de-wrap rooms state_cache

de-wrap room state et al

de-wrap rooms timeline service

additional users device/keys related

de-wrap/asyncify sender

asyncify services

refactor database to TryFuture/TryStream

refactor services for TryFuture/TryStream

asyncify api handlers

additional asyncification for admin module

abstract stream related; support reverse streams

additional stream conversions

asyncify state-res related

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-08-08 17:18:30 +00:00 committed by strawberry
parent 6001014078
commit 946ca364e0
203 changed files with 12202 additions and 10709 deletions

View file

@ -1,9 +1,13 @@
use std::cmp;
use axum::extract::State;
use conduit::{Error, Result};
use ruma::{
api::{client::error::ErrorKind, federation::backfill::get_backfill},
uint, user_id, MilliSecondsSinceUnixEpoch,
use conduit::{
is_equal_to,
utils::{IterStream, ReadyExt},
Err, PduCount, Result,
};
use futures::{FutureExt, StreamExt};
use ruma::{api::federation::backfill::get_backfill, uint, user_id, MilliSecondsSinceUnixEpoch};
use crate::Ruma;
@ -19,27 +23,35 @@ pub(crate) async fn get_backfill_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if !services
.rooms
.state_accessor
.is_world_readable(&body.room_id)?
&& !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)?
.is_world_readable(&body.room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)
.await
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room."));
return Err!(Request(Forbidden("Server is not in room.")));
}
let until = body
.v
.iter()
.map(|event_id| services.rooms.timeline.get_pdu_count(event_id))
.filter_map(|r| r.ok().flatten())
.max()
.ok_or_else(|| Error::BadRequest(ErrorKind::InvalidParam, "Event not found."))?;
.stream()
.filter_map(|event_id| {
services
.rooms
.timeline
.get_pdu_count(event_id)
.map(Result::ok)
})
.ready_fold(PduCount::Backfilled(0), cmp::max)
.await;
let limit = body
.limit
@ -47,31 +59,37 @@ pub(crate) async fn get_backfill_route(
.try_into()
.expect("UInt could not be converted to usize");
let all_events = services
let pdus = services
.rooms
.timeline
.pdus_until(user_id!("@doesntmatter:conduit.rs"), &body.room_id, until)?
.take(limit);
.pdus_until(user_id!("@doesntmatter:conduit.rs"), &body.room_id, until)
.await?
.take(limit)
.filter_map(|(_, pdu)| async move {
if !services
.rooms
.state_accessor
.server_can_see_event(origin, &pdu.room_id, &pdu.event_id)
.await
.is_ok_and(is_equal_to!(true))
{
return None;
}
let events = all_events
.filter_map(Result::ok)
.filter(|(_, e)| {
matches!(
services
.rooms
.state_accessor
.server_can_see_event(origin, &e.room_id, &e.event_id,),
Ok(true),
)
services
.rooms
.timeline
.get_pdu_json(&pdu.event_id)
.await
.ok()
})
.map(|(_, pdu)| services.rooms.timeline.get_pdu_json(&pdu.event_id))
.filter_map(|r| r.ok().flatten())
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect();
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect()
.await;
Ok(get_backfill::v1::Response {
origin: services.globals.server_name().to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
pdus: events,
pdus,
})
}

View file

@ -1,9 +1,6 @@
use axum::extract::State;
use conduit::{Error, Result};
use ruma::{
api::{client::error::ErrorKind, federation::event::get_event},
MilliSecondsSinceUnixEpoch, RoomId,
};
use conduit::{err, Err, Result};
use ruma::{api::federation::event::get_event, MilliSecondsSinceUnixEpoch, RoomId};
use crate::Ruma;
@ -21,34 +18,46 @@ pub(crate) async fn get_event_route(
let event = services
.rooms
.timeline
.get_pdu_json(&body.event_id)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Event not found."))?;
.get_pdu_json(&body.event_id)
.await
.map_err(|_| err!(Request(NotFound("Event not found."))))?;
let room_id_str = event
.get("room_id")
.and_then(|val| val.as_str())
.ok_or_else(|| Error::bad_database("Invalid event in database."))?;
.ok_or_else(|| err!(Database("Invalid event in database.")))?;
let room_id =
<&RoomId>::try_from(room_id_str).map_err(|_| Error::bad_database("Invalid room_id in event in database."))?;
<&RoomId>::try_from(room_id_str).map_err(|_| err!(Database("Invalid room_id in event in database.")))?;
if !services.rooms.state_accessor.is_world_readable(room_id)?
&& !services.rooms.state_cache.server_in_room(origin, room_id)?
if !services
.rooms
.state_accessor
.is_world_readable(room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, room_id)
.await
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room."));
return Err!(Request(Forbidden("Server is not in room.")));
}
if !services
.rooms
.state_accessor
.server_can_see_event(origin, room_id, &body.event_id)?
.server_can_see_event(origin, room_id, &body.event_id)
.await?
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not allowed to see event."));
return Err!(Request(Forbidden("Server is not allowed to see event.")));
}
Ok(get_event::v1::Response {
origin: services.globals.server_name().to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
pdu: services.sending.convert_to_outgoing_federation_event(event),
pdu: services
.sending
.convert_to_outgoing_federation_event(event)
.await,
})
}

View file

@ -2,6 +2,7 @@ use std::sync::Arc;
use axum::extract::State;
use conduit::{Error, Result};
use futures::StreamExt;
use ruma::{
api::{client::error::ErrorKind, federation::authorization::get_event_authorization},
RoomId,
@ -22,16 +23,18 @@ pub(crate) async fn get_event_authorization_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if !services
.rooms
.state_accessor
.is_world_readable(&body.room_id)?
&& !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)?
.is_world_readable(&body.room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)
.await
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room."));
}
@ -39,8 +42,9 @@ pub(crate) async fn get_event_authorization_route(
let event = services
.rooms
.timeline
.get_pdu_json(&body.event_id)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Event not found."))?;
.get_pdu_json(&body.event_id)
.await
.map_err(|_| Error::BadRequest(ErrorKind::NotFound, "Event not found."))?;
let room_id_str = event
.get("room_id")
@ -50,16 +54,17 @@ pub(crate) async fn get_event_authorization_route(
let room_id =
<&RoomId>::try_from(room_id_str).map_err(|_| Error::bad_database("Invalid room_id in event in database."))?;
let auth_chain_ids = services
let auth_chain = services
.rooms
.auth_chain
.event_ids_iter(room_id, vec![Arc::from(&*body.event_id)])
.await?;
.await?
.filter_map(|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() })
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect()
.await;
Ok(get_event_authorization::v1::Response {
auth_chain: auth_chain_ids
.filter_map(|id| services.rooms.timeline.get_pdu_json(&id).ok()?)
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect(),
auth_chain,
})
}

View file

@ -18,16 +18,18 @@ pub(crate) async fn get_missing_events_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if !services
.rooms
.state_accessor
.is_world_readable(&body.room_id)?
&& !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)?
.is_world_readable(&body.room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)
.await
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room"));
}
@ -43,7 +45,12 @@ pub(crate) async fn get_missing_events_route(
let mut i: usize = 0;
while i < queued_events.len() && events.len() < limit {
if let Some(pdu) = services.rooms.timeline.get_pdu_json(&queued_events[i])? {
if let Ok(pdu) = services
.rooms
.timeline
.get_pdu_json(&queued_events[i])
.await
{
let room_id_str = pdu
.get("room_id")
.and_then(|val| val.as_str())
@ -64,7 +71,8 @@ pub(crate) async fn get_missing_events_route(
if !services
.rooms
.state_accessor
.server_can_see_event(origin, &body.room_id, &queued_events[i])?
.server_can_see_event(origin, &body.room_id, &queued_events[i])
.await?
{
i = i.saturating_add(1);
continue;
@ -81,7 +89,12 @@ pub(crate) async fn get_missing_events_route(
)
.map_err(|_| Error::bad_database("Invalid prev_events in event in database."))?,
);
events.push(services.sending.convert_to_outgoing_federation_event(pdu));
events.push(
services
.sending
.convert_to_outgoing_federation_event(pdu)
.await,
);
}
i = i.saturating_add(1);
}

View file

@ -12,7 +12,7 @@ pub(crate) async fn get_hierarchy_route(
) -> Result<get_hierarchy::v1::Response> {
let origin = body.origin.as_ref().expect("server is authenticated");
if services.rooms.metadata.exists(&body.room_id)? {
if services.rooms.metadata.exists(&body.room_id).await {
services
.rooms
.spaces

View file

@ -24,7 +24,8 @@ pub(crate) async fn create_invite_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if !services
.globals
@ -98,7 +99,8 @@ pub(crate) async fn create_invite_route(
services
.rooms
.event_handler
.acl_check(invited_user.server_name(), &body.room_id)?;
.acl_check(invited_user.server_name(), &body.room_id)
.await?;
ruma::signatures::hash_and_sign_event(
services.globals.server_name().as_str(),
@ -128,14 +130,14 @@ pub(crate) async fn create_invite_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "sender is not a user ID."))?;
if services.rooms.metadata.is_banned(&body.room_id)? && !services.users.is_admin(&invited_user)? {
if services.rooms.metadata.is_banned(&body.room_id).await && !services.users.is_admin(&invited_user).await {
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"This room is banned on this homeserver.",
));
}
if services.globals.block_non_admin_invites() && !services.users.is_admin(&invited_user)? {
if services.globals.block_non_admin_invites() && !services.users.is_admin(&invited_user).await {
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"This server does not allow room invites.",
@ -159,22 +161,28 @@ pub(crate) async fn create_invite_route(
if !services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), &body.room_id)?
.server_in_room(services.globals.server_name(), &body.room_id)
.await
{
services.rooms.state_cache.update_membership(
&body.room_id,
&invited_user,
RoomMemberEventContent::new(MembershipState::Invite),
&sender,
Some(invite_state),
body.via.clone(),
true,
)?;
services
.rooms
.state_cache
.update_membership(
&body.room_id,
&invited_user,
RoomMemberEventContent::new(MembershipState::Invite),
&sender,
Some(invite_state),
body.via.clone(),
true,
)
.await?;
}
Ok(create_invite::v2::Response {
event: services
.sending
.convert_to_outgoing_federation_event(signed_event),
.convert_to_outgoing_federation_event(signed_event)
.await,
})
}

View file

@ -1,4 +1,6 @@
use axum::extract::State;
use conduit::utils::{IterStream, ReadyExt};
use futures::StreamExt;
use ruma::{
api::{client::error::ErrorKind, federation::membership::prepare_join_event},
events::{
@ -24,7 +26,7 @@ use crate::{
pub(crate) async fn create_join_event_template_route(
State(services): State<crate::State>, body: Ruma<prepare_join_event::v1::Request>,
) -> Result<prepare_join_event::v1::Response> {
if !services.rooms.metadata.exists(&body.room_id)? {
if !services.rooms.metadata.exists(&body.room_id).await {
return Err(Error::BadRequest(ErrorKind::NotFound, "Room is unknown to this server."));
}
@ -40,7 +42,8 @@ pub(crate) async fn create_join_event_template_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if services
.globals
@ -73,7 +76,7 @@ pub(crate) async fn create_join_event_template_route(
}
}
let room_version_id = services.rooms.state.get_room_version(&body.room_id)?;
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
@ -81,22 +84,24 @@ pub(crate) async fn create_join_event_template_route(
.rooms
.state_cache
.is_left(&body.user_id, &body.room_id)
.unwrap_or(true))
&& user_can_perform_restricted_join(&services, &body.user_id, &body.room_id, &room_version_id)?
.await)
&& user_can_perform_restricted_join(&services, &body.user_id, &body.room_id, &room_version_id).await?
{
let auth_user = services
.rooms
.state_cache
.room_members(&body.room_id)
.filter_map(Result::ok)
.filter(|user| user.server_name() == services.globals.server_name())
.find(|user| {
.ready_filter(|user| user.server_name() == services.globals.server_name())
.filter(|user| {
services
.rooms
.state_accessor
.user_can_invite(&body.room_id, user, &body.user_id, &state_lock)
.unwrap_or(false)
});
})
.boxed()
.next()
.await
.map(ToOwned::to_owned);
if auth_user.is_some() {
auth_user
@ -110,7 +115,7 @@ pub(crate) async fn create_join_event_template_route(
None
};
let room_version_id = services.rooms.state.get_room_version(&body.room_id)?;
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
if !body.ver.contains(&room_version_id) {
return Err(Error::BadRequest(
ErrorKind::IncompatibleRoomVersion {
@ -132,19 +137,23 @@ pub(crate) async fn create_join_event_template_route(
})
.expect("member event is valid value");
let (_pdu, mut pdu_json) = services.rooms.timeline.create_hash_and_sign_event(
PduBuilder {
event_type: TimelineEventType::RoomMember,
content,
unsigned: None,
state_key: Some(body.user_id.to_string()),
redacts: None,
timestamp: None,
},
&body.user_id,
&body.room_id,
&state_lock,
)?;
let (_pdu, mut pdu_json) = services
.rooms
.timeline
.create_hash_and_sign_event(
PduBuilder {
event_type: TimelineEventType::RoomMember,
content,
unsigned: None,
state_key: Some(body.user_id.to_string()),
redacts: None,
timestamp: None,
},
&body.user_id,
&body.room_id,
&state_lock,
)
.await?;
drop(state_lock);
@ -161,7 +170,7 @@ pub(crate) async fn create_join_event_template_route(
/// This doesn't check the current user's membership. This should be done
/// externally, either by using the state cache or attempting to authorize the
/// event.
pub(crate) fn user_can_perform_restricted_join(
pub(crate) async fn user_can_perform_restricted_join(
services: &Services, user_id: &UserId, room_id: &RoomId, room_version_id: &RoomVersionId,
) -> Result<bool> {
use RoomVersionId::*;
@ -169,18 +178,15 @@ pub(crate) fn user_can_perform_restricted_join(
let join_rules_event = services
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomJoinRules, "")?;
.room_state_get(room_id, &StateEventType::RoomJoinRules, "")
.await;
let Some(join_rules_event_content) = join_rules_event
.as_ref()
.map(|join_rules_event| {
serde_json::from_str::<RoomJoinRulesEventContent>(join_rules_event.content.get()).map_err(|e| {
warn!("Invalid join rules event in database: {e}");
Error::bad_database("Invalid join rules event in database")
})
let Ok(Ok(join_rules_event_content)) = join_rules_event.as_ref().map(|join_rules_event| {
serde_json::from_str::<RoomJoinRulesEventContent>(join_rules_event.content.get()).map_err(|e| {
warn!("Invalid join rules event in database: {e}");
Error::bad_database("Invalid join rules event in database")
})
.transpose()?
else {
}) else {
return Ok(false);
};
@ -201,13 +207,10 @@ pub(crate) fn user_can_perform_restricted_join(
None
}
})
.any(|m| {
services
.rooms
.state_cache
.is_joined(user_id, &m.room_id)
.unwrap_or(false)
}) {
.stream()
.any(|m| services.rooms.state_cache.is_joined(user_id, &m.room_id))
.await
{
Ok(true)
} else {
Err(Error::BadRequest(

View file

@ -18,7 +18,7 @@ use crate::{service::pdu::PduBuilder, Ruma};
pub(crate) async fn create_leave_event_template_route(
State(services): State<crate::State>, body: Ruma<prepare_leave_event::v1::Request>,
) -> Result<prepare_leave_event::v1::Response> {
if !services.rooms.metadata.exists(&body.room_id)? {
if !services.rooms.metadata.exists(&body.room_id).await {
return Err(Error::BadRequest(ErrorKind::NotFound, "Room is unknown to this server."));
}
@ -34,9 +34,10 @@ pub(crate) async fn create_leave_event_template_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
let room_version_id = services.rooms.state.get_room_version(&body.room_id)?;
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
let content = to_raw_value(&RoomMemberEventContent {
avatar_url: None,
@ -50,19 +51,23 @@ pub(crate) async fn create_leave_event_template_route(
})
.expect("member event is valid value");
let (_pdu, mut pdu_json) = services.rooms.timeline.create_hash_and_sign_event(
PduBuilder {
event_type: TimelineEventType::RoomMember,
content,
unsigned: None,
state_key: Some(body.user_id.to_string()),
redacts: None,
timestamp: None,
},
&body.user_id,
&body.room_id,
&state_lock,
)?;
let (_pdu, mut pdu_json) = services
.rooms
.timeline
.create_hash_and_sign_event(
PduBuilder {
event_type: TimelineEventType::RoomMember,
content,
unsigned: None,
state_key: Some(body.user_id.to_string()),
redacts: None,
timestamp: None,
},
&body.user_id,
&body.room_id,
&state_lock,
)
.await?;
drop(state_lock);

View file

@ -10,6 +10,9 @@ pub(crate) async fn get_openid_userinfo_route(
State(services): State<crate::State>, body: Ruma<get_openid_userinfo::v1::Request>,
) -> Result<get_openid_userinfo::v1::Response> {
Ok(get_openid_userinfo::v1::Response::new(
services.users.find_from_openid_token(&body.access_token)?,
services
.users
.find_from_openid_token(&body.access_token)
.await?,
))
}

View file

@ -1,7 +1,8 @@
use std::collections::BTreeMap;
use axum::extract::State;
use conduit::{Error, Result};
use conduit::{err, Error, Result};
use futures::StreamExt;
use get_profile_information::v1::ProfileField;
use rand::seq::SliceRandom;
use ruma::{
@ -23,15 +24,17 @@ pub(crate) async fn get_room_information_route(
let room_id = services
.rooms
.alias
.resolve_local_alias(&body.room_alias)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Room alias not found."))?;
.resolve_local_alias(&body.room_alias)
.await
.map_err(|_| err!(Request(NotFound("Room alias not found."))))?;
let mut servers: Vec<OwnedServerName> = services
.rooms
.state_cache
.room_servers(&room_id)
.filter_map(Result::ok)
.collect();
.map(ToOwned::to_owned)
.collect()
.await;
servers.sort_unstable();
servers.dedup();
@ -82,30 +85,31 @@ pub(crate) async fn get_profile_information_route(
match &body.field {
Some(ProfileField::DisplayName) => {
displayname = services.users.displayname(&body.user_id)?;
displayname = services.users.displayname(&body.user_id).await.ok();
},
Some(ProfileField::AvatarUrl) => {
avatar_url = services.users.avatar_url(&body.user_id)?;
blurhash = services.users.blurhash(&body.user_id)?;
avatar_url = services.users.avatar_url(&body.user_id).await.ok();
blurhash = services.users.blurhash(&body.user_id).await.ok();
},
Some(custom_field) => {
if let Some(value) = services
if let Ok(value) = services
.users
.profile_key(&body.user_id, custom_field.as_str())?
.profile_key(&body.user_id, custom_field.as_str())
.await
{
custom_profile_fields.insert(custom_field.to_string(), value);
}
},
None => {
displayname = services.users.displayname(&body.user_id)?;
avatar_url = services.users.avatar_url(&body.user_id)?;
blurhash = services.users.blurhash(&body.user_id)?;
tz = services.users.timezone(&body.user_id)?;
displayname = services.users.displayname(&body.user_id).await.ok();
avatar_url = services.users.avatar_url(&body.user_id).await.ok();
blurhash = services.users.blurhash(&body.user_id).await.ok();
tz = services.users.timezone(&body.user_id).await.ok();
custom_profile_fields = services
.users
.all_profile_keys(&body.user_id)
.filter_map(Result::ok)
.collect();
.collect()
.await;
},
}

View file

@ -2,7 +2,8 @@ use std::{collections::BTreeMap, net::IpAddr, time::Instant};
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use conduit::{debug, debug_warn, err, trace, warn, Err};
use conduit::{debug, debug_warn, err, result::LogErr, trace, utils::ReadyExt, warn, Err, Error, Result};
use futures::StreamExt;
use ruma::{
api::{
client::error::ErrorKind,
@ -23,10 +24,13 @@ use tokio::sync::RwLock;
use crate::{
services::Services,
utils::{self},
Error, Result, Ruma,
Ruma,
};
type ResolvedMap = BTreeMap<OwnedEventId, Result<(), Error>>;
const PDU_LIMIT: usize = 50;
const EDU_LIMIT: usize = 100;
type ResolvedMap = BTreeMap<OwnedEventId, Result<()>>;
/// # `PUT /_matrix/federation/v1/send/{txnId}`
///
@ -44,12 +48,16 @@ pub(crate) async fn send_transaction_message_route(
)));
}
if body.pdus.len() > 50_usize {
return Err!(Request(Forbidden("Not allowed to send more than 50 PDUs in one transaction")));
if body.pdus.len() > PDU_LIMIT {
return Err!(Request(Forbidden(
"Not allowed to send more than {PDU_LIMIT} PDUs in one transaction"
)));
}
if body.edus.len() > 100_usize {
return Err!(Request(Forbidden("Not allowed to send more than 100 EDUs in one transaction")));
if body.edus.len() > EDU_LIMIT {
return Err!(Request(Forbidden(
"Not allowed to send more than {EDU_LIMIT} EDUs in one transaction"
)));
}
let txn_start_time = Instant::now();
@ -62,8 +70,8 @@ pub(crate) async fn send_transaction_message_route(
"Starting txn",
);
let resolved_map = handle_pdus(&services, &client, &body, origin, &txn_start_time).await?;
handle_edus(&services, &client, &body, origin).await?;
let resolved_map = handle_pdus(&services, &client, &body, origin, &txn_start_time).await;
handle_edus(&services, &client, &body, origin).await;
debug!(
pdus = ?body.pdus.len(),
@ -85,10 +93,10 @@ pub(crate) async fn send_transaction_message_route(
async fn handle_pdus(
services: &Services, _client: &IpAddr, body: &Ruma<send_transaction_message::v1::Request>, origin: &ServerName,
txn_start_time: &Instant,
) -> Result<ResolvedMap> {
) -> ResolvedMap {
let mut parsed_pdus = Vec::with_capacity(body.pdus.len());
for pdu in &body.pdus {
parsed_pdus.push(match services.rooms.event_handler.parse_incoming_pdu(pdu) {
parsed_pdus.push(match services.rooms.event_handler.parse_incoming_pdu(pdu).await {
Ok(t) => t,
Err(e) => {
debug_warn!("Could not parse PDU: {e}");
@ -151,38 +159,34 @@ async fn handle_pdus(
}
}
Ok(resolved_map)
resolved_map
}
async fn handle_edus(
services: &Services, client: &IpAddr, body: &Ruma<send_transaction_message::v1::Request>, origin: &ServerName,
) -> Result<()> {
) {
for edu in body
.edus
.iter()
.filter_map(|edu| serde_json::from_str::<Edu>(edu.json().get()).ok())
{
match edu {
Edu::Presence(presence) => handle_edu_presence(services, client, origin, presence).await?,
Edu::Receipt(receipt) => handle_edu_receipt(services, client, origin, receipt).await?,
Edu::Typing(typing) => handle_edu_typing(services, client, origin, typing).await?,
Edu::DeviceListUpdate(content) => handle_edu_device_list_update(services, client, origin, content).await?,
Edu::DirectToDevice(content) => handle_edu_direct_to_device(services, client, origin, content).await?,
Edu::SigningKeyUpdate(content) => handle_edu_signing_key_update(services, client, origin, content).await?,
Edu::Presence(presence) => handle_edu_presence(services, client, origin, presence).await,
Edu::Receipt(receipt) => handle_edu_receipt(services, client, origin, receipt).await,
Edu::Typing(typing) => handle_edu_typing(services, client, origin, typing).await,
Edu::DeviceListUpdate(content) => handle_edu_device_list_update(services, client, origin, content).await,
Edu::DirectToDevice(content) => handle_edu_direct_to_device(services, client, origin, content).await,
Edu::SigningKeyUpdate(content) => handle_edu_signing_key_update(services, client, origin, content).await,
Edu::_Custom(ref _custom) => {
debug_warn!(?body.edus, "received custom/unknown EDU");
},
}
}
Ok(())
}
async fn handle_edu_presence(
services: &Services, _client: &IpAddr, origin: &ServerName, presence: PresenceContent,
) -> Result<()> {
async fn handle_edu_presence(services: &Services, _client: &IpAddr, origin: &ServerName, presence: PresenceContent) {
if !services.globals.allow_incoming_presence() {
return Ok(());
return;
}
for update in presence.push {
@ -194,23 +198,24 @@ async fn handle_edu_presence(
continue;
}
services.presence.set_presence(
&update.user_id,
&update.presence,
Some(update.currently_active),
Some(update.last_active_ago),
update.status_msg.clone(),
)?;
services
.presence
.set_presence(
&update.user_id,
&update.presence,
Some(update.currently_active),
Some(update.last_active_ago),
update.status_msg.clone(),
)
.await
.log_err()
.ok();
}
Ok(())
}
async fn handle_edu_receipt(
services: &Services, _client: &IpAddr, origin: &ServerName, receipt: ReceiptContent,
) -> Result<()> {
async fn handle_edu_receipt(services: &Services, _client: &IpAddr, origin: &ServerName, receipt: ReceiptContent) {
if !services.globals.allow_incoming_read_receipts() {
return Ok(());
return;
}
for (room_id, room_updates) in receipt.receipts {
@ -218,6 +223,7 @@ async fn handle_edu_receipt(
.rooms
.event_handler
.acl_check(origin, &room_id)
.await
.is_err()
{
debug_warn!(
@ -240,8 +246,8 @@ async fn handle_edu_receipt(
.rooms
.state_cache
.room_members(&room_id)
.filter_map(Result::ok)
.any(|member| member.server_name() == user_id.server_name())
.ready_any(|member| member.server_name() == user_id.server_name())
.await
{
for event_id in &user_updates.event_ids {
let user_receipts = BTreeMap::from([(user_id.clone(), user_updates.data.clone())]);
@ -255,7 +261,8 @@ async fn handle_edu_receipt(
services
.rooms
.read_receipt
.readreceipt_update(&user_id, &room_id, &event)?;
.readreceipt_update(&user_id, &room_id, &event)
.await;
}
} else {
debug_warn!(
@ -266,15 +273,11 @@ async fn handle_edu_receipt(
}
}
}
Ok(())
}
async fn handle_edu_typing(
services: &Services, _client: &IpAddr, origin: &ServerName, typing: TypingContent,
) -> Result<()> {
async fn handle_edu_typing(services: &Services, _client: &IpAddr, origin: &ServerName, typing: TypingContent) {
if !services.globals.config.allow_incoming_typing {
return Ok(());
return;
}
if typing.user_id.server_name() != origin {
@ -282,26 +285,28 @@ async fn handle_edu_typing(
%typing.user_id, %origin,
"received typing EDU for user not belonging to origin"
);
return Ok(());
return;
}
if services
.rooms
.event_handler
.acl_check(typing.user_id.server_name(), &typing.room_id)
.await
.is_err()
{
debug_warn!(
%typing.user_id, %typing.room_id, %origin,
"received typing EDU for ACL'd user's server"
);
return Ok(());
return;
}
if services
.rooms
.state_cache
.is_joined(&typing.user_id, &typing.room_id)?
.is_joined(&typing.user_id, &typing.room_id)
.await
{
if typing.typing {
let timeout = utils::millis_since_unix_epoch().saturating_add(
@ -315,28 +320,29 @@ async fn handle_edu_typing(
.rooms
.typing
.typing_add(&typing.user_id, &typing.room_id, timeout)
.await?;
.await
.log_err()
.ok();
} else {
services
.rooms
.typing
.typing_remove(&typing.user_id, &typing.room_id)
.await?;
.await
.log_err()
.ok();
}
} else {
debug_warn!(
%typing.user_id, %typing.room_id, %origin,
"received typing EDU for user not in room"
);
return Ok(());
}
Ok(())
}
async fn handle_edu_device_list_update(
services: &Services, _client: &IpAddr, origin: &ServerName, content: DeviceListUpdateContent,
) -> Result<()> {
) {
let DeviceListUpdateContent {
user_id,
..
@ -347,17 +353,15 @@ async fn handle_edu_device_list_update(
%user_id, %origin,
"received device list update EDU for user not belonging to origin"
);
return Ok(());
return;
}
services.users.mark_device_key_update(&user_id)?;
Ok(())
services.users.mark_device_key_update(&user_id).await;
}
async fn handle_edu_direct_to_device(
services: &Services, _client: &IpAddr, origin: &ServerName, content: DirectDeviceContent,
) -> Result<()> {
) {
let DirectDeviceContent {
sender,
ev_type,
@ -370,45 +374,52 @@ async fn handle_edu_direct_to_device(
%sender, %origin,
"received direct to device EDU for user not belonging to origin"
);
return Ok(());
return;
}
// Check if this is a new transaction id
if services
.transaction_ids
.existing_txnid(&sender, None, &message_id)?
.is_some()
.existing_txnid(&sender, None, &message_id)
.await
.is_ok()
{
return Ok(());
return;
}
for (target_user_id, map) in &messages {
for (target_device_id_maybe, event) in map {
let Ok(event) = event
.deserialize_as()
.map_err(|e| err!(Request(InvalidParam(error!("To-Device event is invalid: {e}")))))
else {
continue;
};
let ev_type = ev_type.to_string();
match target_device_id_maybe {
DeviceIdOrAllDevices::DeviceId(target_device_id) => {
services.users.add_to_device_event(
&sender,
target_user_id,
target_device_id,
&ev_type.to_string(),
event
.deserialize_as()
.map_err(|e| err!(Request(InvalidParam(error!("To-Device event is invalid: {e}")))))?,
)?;
services
.users
.add_to_device_event(&sender, target_user_id, target_device_id, &ev_type, event)
.await;
},
DeviceIdOrAllDevices::AllDevices => {
for target_device_id in services.users.all_device_ids(target_user_id) {
services.users.add_to_device_event(
&sender,
target_user_id,
&target_device_id?,
&ev_type.to_string(),
event
.deserialize_as()
.map_err(|e| err!(Request(InvalidParam("Event is invalid: {e}"))))?,
)?;
}
let (sender, ev_type, event) = (&sender, &ev_type, &event);
services
.users
.all_device_ids(target_user_id)
.for_each(|target_device_id| {
services.users.add_to_device_event(
sender,
target_user_id,
target_device_id,
ev_type,
event.clone(),
)
})
.await;
},
}
}
@ -417,14 +428,12 @@ async fn handle_edu_direct_to_device(
// Save transaction id with empty data
services
.transaction_ids
.add_txnid(&sender, None, &message_id, &[])?;
Ok(())
.add_txnid(&sender, None, &message_id, &[]);
}
async fn handle_edu_signing_key_update(
services: &Services, _client: &IpAddr, origin: &ServerName, content: SigningKeyUpdateContent,
) -> Result<()> {
) {
let SigningKeyUpdateContent {
user_id,
master_key,
@ -436,14 +445,15 @@ async fn handle_edu_signing_key_update(
%user_id, %origin,
"received signing key update EDU from server that does not belong to user's server"
);
return Ok(());
return;
}
if let Some(master_key) = master_key {
services
.users
.add_cross_signing_keys(&user_id, &master_key, &self_signing_key, &None, true)?;
.add_cross_signing_keys(&user_id, &master_key, &self_signing_key, &None, true)
.await
.log_err()
.ok();
}
Ok(())
}

View file

@ -3,7 +3,8 @@
use std::collections::BTreeMap;
use axum::extract::State;
use conduit::{pdu::gen_event_id_canonical_json, warn, Error, Result};
use conduit::{err, pdu::gen_event_id_canonical_json, utils::IterStream, warn, Error, Result};
use futures::{FutureExt, StreamExt, TryStreamExt};
use ruma::{
api::{client::error::ErrorKind, federation::membership::create_join_event},
events::{
@ -22,27 +23,32 @@ use crate::Ruma;
async fn create_join_event(
services: &Services, origin: &ServerName, room_id: &RoomId, pdu: &RawJsonValue,
) -> Result<create_join_event::v1::RoomState> {
if !services.rooms.metadata.exists(room_id)? {
if !services.rooms.metadata.exists(room_id).await {
return Err(Error::BadRequest(ErrorKind::NotFound, "Room is unknown to this server."));
}
// ACL check origin server
services.rooms.event_handler.acl_check(origin, room_id)?;
services
.rooms
.event_handler
.acl_check(origin, room_id)
.await?;
// We need to return the state prior to joining, let's keep a reference to that
// here
let shortstatehash = services
.rooms
.state
.get_room_shortstatehash(room_id)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Event state not found."))?;
.get_room_shortstatehash(room_id)
.await
.map_err(|_| err!(Request(NotFound("Event state not found."))))?;
let pub_key_map = RwLock::new(BTreeMap::new());
// let mut auth_cache = EventMap::new();
// We do not add the event_id field to the pdu here because of signature and
// hashes checks
let room_version_id = services.rooms.state.get_room_version(room_id)?;
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
let Ok((event_id, mut value)) = gen_event_id_canonical_json(pdu, &room_version_id) else {
// Event could not be converted to canonical json
@ -97,7 +103,8 @@ async fn create_join_event(
services
.rooms
.event_handler
.acl_check(sender.server_name(), room_id)?;
.acl_check(sender.server_name(), room_id)
.await?;
// check if origin server is trying to send for another server
if sender.server_name() != origin {
@ -126,7 +133,9 @@ async fn create_join_event(
if content
.join_authorized_via_users_server
.is_some_and(|user| services.globals.user_is_local(&user))
&& super::user_can_perform_restricted_join(services, &sender, room_id, &room_version_id).unwrap_or_default()
&& super::user_can_perform_restricted_join(services, &sender, room_id, &room_version_id)
.await
.unwrap_or_default()
{
ruma::signatures::hash_and_sign_event(
services.globals.server_name().as_str(),
@ -158,12 +167,14 @@ async fn create_join_event(
.mutex_federation
.lock(room_id)
.await;
let pdu_id: Vec<u8> = services
.rooms
.event_handler
.handle_incoming_pdu(&origin, room_id, &event_id, value.clone(), true, &pub_key_map)
.await?
.ok_or_else(|| Error::BadRequest(ErrorKind::InvalidParam, "Could not accept as timeline event."))?;
drop(mutex_lock);
let state_ids = services
@ -171,29 +182,43 @@ async fn create_join_event(
.state_accessor
.state_full_ids(shortstatehash)
.await?;
let auth_chain_ids = services
let state = state_ids
.iter()
.try_stream()
.and_then(|(_, event_id)| services.rooms.timeline.get_pdu_json(event_id))
.and_then(|pdu| {
services
.sending
.convert_to_outgoing_federation_event(pdu)
.map(Ok)
})
.try_collect()
.await?;
let auth_chain = services
.rooms
.auth_chain
.event_ids_iter(room_id, state_ids.values().cloned().collect())
.await?
.map(Ok)
.and_then(|event_id| async move { services.rooms.timeline.get_pdu_json(&event_id).await })
.and_then(|pdu| {
services
.sending
.convert_to_outgoing_federation_event(pdu)
.map(Ok)
})
.try_collect()
.await?;
services.sending.send_pdu_room(room_id, &pdu_id)?;
services.sending.send_pdu_room(room_id, &pdu_id).await?;
Ok(create_join_event::v1::RoomState {
auth_chain: auth_chain_ids
.filter_map(|id| services.rooms.timeline.get_pdu_json(&id).ok().flatten())
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect(),
state: state_ids
.iter()
.filter_map(|(_, id)| services.rooms.timeline.get_pdu_json(id).ok().flatten())
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect(),
auth_chain,
state,
// Event field is required if the room version supports restricted join rules.
event: Some(
to_raw_value(&CanonicalJsonValue::Object(value))
.expect("To raw json should not fail since only change was adding signature"),
),
event: to_raw_value(&CanonicalJsonValue::Object(value)).ok(),
})
}

View file

@ -3,7 +3,7 @@
use std::collections::BTreeMap;
use axum::extract::State;
use conduit::{Error, Result};
use conduit::{utils::ReadyExt, Error, Result};
use ruma::{
api::{client::error::ErrorKind, federation::membership::create_leave_event},
events::{
@ -49,18 +49,22 @@ pub(crate) async fn create_leave_event_v2_route(
async fn create_leave_event(
services: &Services, origin: &ServerName, room_id: &RoomId, pdu: &RawJsonValue,
) -> Result<()> {
if !services.rooms.metadata.exists(room_id)? {
if !services.rooms.metadata.exists(room_id).await {
return Err(Error::BadRequest(ErrorKind::NotFound, "Room is unknown to this server."));
}
// ACL check origin
services.rooms.event_handler.acl_check(origin, room_id)?;
services
.rooms
.event_handler
.acl_check(origin, room_id)
.await?;
let pub_key_map = RwLock::new(BTreeMap::new());
// We do not add the event_id field to the pdu here because of signature and
// hashes checks
let room_version_id = services.rooms.state.get_room_version(room_id)?;
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
let Ok((event_id, value)) = gen_event_id_canonical_json(pdu, &room_version_id) else {
// Event could not be converted to canonical json
return Err(Error::BadRequest(
@ -114,7 +118,8 @@ async fn create_leave_event(
services
.rooms
.event_handler
.acl_check(sender.server_name(), room_id)?;
.acl_check(sender.server_name(), room_id)
.await?;
if sender.server_name() != origin {
return Err(Error::BadRequest(
@ -173,10 +178,9 @@ async fn create_leave_event(
.rooms
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| !services.globals.server_is_ours(server));
.ready_filter(|server| !services.globals.server_is_ours(server));
services.sending.send_pdu_servers(servers, &pdu_id)?;
services.sending.send_pdu_servers(servers, &pdu_id).await?;
Ok(())
}

View file

@ -1,8 +1,9 @@
use std::sync::Arc;
use axum::extract::State;
use conduit::{Error, Result};
use ruma::api::{client::error::ErrorKind, federation::event::get_room_state};
use conduit::{err, result::LogErr, utils::IterStream, Err, Result};
use futures::{FutureExt, StreamExt, TryStreamExt};
use ruma::api::federation::event::get_room_state;
use crate::Ruma;
@ -17,56 +18,66 @@ pub(crate) async fn get_room_state_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if !services
.rooms
.state_accessor
.is_world_readable(&body.room_id)?
&& !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)?
.is_world_readable(&body.room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)
.await
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room."));
return Err!(Request(Forbidden("Server is not in room.")));
}
let shortstatehash = services
.rooms
.state_accessor
.pdu_shortstatehash(&body.event_id)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Pdu state not found."))?;
.pdu_shortstatehash(&body.event_id)
.await
.map_err(|_| err!(Request(NotFound("PDU state not found."))))?;
let pdus = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.await?
.into_values()
.map(|id| {
.await
.log_err()
.map_err(|_| err!(Request(NotFound("PDU state IDs not found."))))?
.values()
.try_stream()
.and_then(|id| services.rooms.timeline.get_pdu_json(id))
.and_then(|pdu| {
services
.sending
.convert_to_outgoing_federation_event(services.rooms.timeline.get_pdu_json(&id).unwrap().unwrap())
.convert_to_outgoing_federation_event(pdu)
.map(Ok)
})
.collect();
.try_collect()
.await?;
let auth_chain_ids = services
let auth_chain = services
.rooms
.auth_chain
.event_ids_iter(&body.room_id, vec![Arc::from(&*body.event_id)])
.await?
.map(Ok)
.and_then(|id| async move { services.rooms.timeline.get_pdu_json(&id).await })
.and_then(|pdu| {
services
.sending
.convert_to_outgoing_federation_event(pdu)
.map(Ok)
})
.try_collect()
.await?;
Ok(get_room_state::v1::Response {
auth_chain: auth_chain_ids
.filter_map(|id| {
services
.rooms
.timeline
.get_pdu_json(&id)
.ok()?
.map(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
})
.collect(),
auth_chain,
pdus,
})
}

View file

@ -1,9 +1,11 @@
use std::sync::Arc;
use axum::extract::State;
use ruma::api::{client::error::ErrorKind, federation::event::get_room_state_ids};
use conduit::{err, Err};
use futures::StreamExt;
use ruma::api::federation::event::get_room_state_ids;
use crate::{Error, Result, Ruma};
use crate::{Result, Ruma};
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
///
@ -17,31 +19,35 @@ pub(crate) async fn get_room_state_ids_route(
services
.rooms
.event_handler
.acl_check(origin, &body.room_id)?;
.acl_check(origin, &body.room_id)
.await?;
if !services
.rooms
.state_accessor
.is_world_readable(&body.room_id)?
&& !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)?
.is_world_readable(&body.room_id)
.await && !services
.rooms
.state_cache
.server_in_room(origin, &body.room_id)
.await
{
return Err(Error::BadRequest(ErrorKind::forbidden(), "Server is not in room."));
return Err!(Request(Forbidden("Server is not in room.")));
}
let shortstatehash = services
.rooms
.state_accessor
.pdu_shortstatehash(&body.event_id)?
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Pdu state not found."))?;
.pdu_shortstatehash(&body.event_id)
.await
.map_err(|_| err!(Request(NotFound("Pdu state not found."))))?;
let pdu_ids = services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.await?
.await
.map_err(|_| err!(Request(NotFound("State ids not found"))))?
.into_values()
.map(|id| (*id).to_owned())
.collect();
@ -50,10 +56,13 @@ pub(crate) async fn get_room_state_ids_route(
.rooms
.auth_chain
.event_ids_iter(&body.room_id, vec![Arc::from(&*body.event_id)])
.await?;
.await?
.map(|id| (*id).to_owned())
.collect()
.await;
Ok(get_room_state_ids::v1::Response {
auth_chain_ids: auth_chain_ids.map(|id| (*id).to_owned()).collect(),
auth_chain_ids,
pdu_ids,
})
}

View file

@ -1,5 +1,6 @@
use axum::extract::State;
use conduit::{Error, Result};
use futures::{FutureExt, StreamExt, TryFutureExt};
use ruma::api::{
client::error::ErrorKind,
federation::{
@ -28,41 +29,51 @@ pub(crate) async fn get_devices_route(
let origin = body.origin.as_ref().expect("server is authenticated");
let user_id = &body.user_id;
Ok(get_devices::v1::Response {
user_id: body.user_id.clone(),
user_id: user_id.clone(),
stream_id: services
.users
.get_devicelist_version(&body.user_id)?
.get_devicelist_version(user_id)
.await
.unwrap_or(0)
.try_into()
.expect("version will not grow that large"),
.try_into()?,
devices: services
.users
.all_devices_metadata(&body.user_id)
.filter_map(Result::ok)
.filter_map(|metadata| {
let device_id_string = metadata.device_id.as_str().to_owned();
.all_devices_metadata(user_id)
.filter_map(|metadata| async move {
let device_id = metadata.device_id.clone();
let device_id_clone = device_id.clone();
let device_id_string = device_id.as_str().to_owned();
let device_display_name = if services.globals.allow_device_name_federation() {
metadata.display_name
metadata.display_name.clone()
} else {
Some(device_id_string)
};
Some(UserDevice {
keys: services
.users
.get_device_keys(&body.user_id, &metadata.device_id)
.ok()??,
device_id: metadata.device_id,
device_display_name,
})
services
.users
.get_device_keys(user_id, &device_id_clone)
.map_ok(|keys| UserDevice {
device_id,
keys,
device_display_name,
})
.map(Result::ok)
.await
})
.collect(),
.collect()
.await,
master_key: services
.users
.get_master_key(None, &body.user_id, &|u| u.server_name() == origin)?,
.get_master_key(None, &body.user_id, &|u| u.server_name() == origin)
.await
.ok(),
self_signing_key: services
.users
.get_self_signing_key(None, &body.user_id, &|u| u.server_name() == origin)?,
.get_self_signing_key(None, &body.user_id, &|u| u.server_name() == origin)
.await
.ok(),
})
}