Merge remote-tracking branch 'upstream/master' into correct-sendtxn
This commit is contained in:
commit
d0df8b495c
49 changed files with 747 additions and 281 deletions
|
@ -40,6 +40,7 @@ const GUEST_NAME_LENGTH: usize = 10;
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/register/available", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_register_available_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_username_availability::Request<'_>>,
|
||||
|
@ -82,6 +83,7 @@ pub async fn get_register_available_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/register", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn register_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<register::Request<'_>>,
|
||||
|
@ -498,6 +500,7 @@ pub async fn register_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/account/password", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn change_password_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<change_password::Request<'_>>,
|
||||
|
@ -562,6 +565,7 @@ pub async fn change_password_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/account/whoami", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(body))]
|
||||
pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
Ok(whoami::Response {
|
||||
|
@ -582,6 +586,7 @@ pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/account/deactivate", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn deactivate_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<deactivate::Request<'_>>,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use regex::Regex;
|
||||
use ruma::{
|
||||
api::{
|
||||
appservice,
|
||||
|
@ -19,6 +20,7 @@ use rocket::{delete, get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/directory/room/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_alias::Request<'_>>,
|
||||
|
@ -39,6 +41,7 @@ pub async fn create_alias_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/r0/directory/room/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_alias::Request<'_>>,
|
||||
|
@ -54,6 +57,7 @@ pub async fn delete_alias_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/directory/room/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_alias::Request<'_>>,
|
||||
|
@ -83,15 +87,23 @@ pub async fn get_alias_helper(
|
|||
Some(r) => room_id = Some(r),
|
||||
None => {
|
||||
for (_id, registration) in db.appservice.iter_all().filter_map(|r| r.ok()) {
|
||||
if db
|
||||
.sending
|
||||
.send_appservice_request(
|
||||
&db.globals,
|
||||
registration,
|
||||
appservice::query::query_room_alias::v1::Request { room_alias },
|
||||
)
|
||||
.await
|
||||
.is_ok()
|
||||
let aliases = registration
|
||||
.get("namespaces")
|
||||
.and_then(|ns| ns.get("aliases"))
|
||||
.and_then(|users| users.get("regex"))
|
||||
.and_then(|regex| regex.as_str())
|
||||
.and_then(|regex| Regex::new(regex).ok());
|
||||
|
||||
if aliases.map_or(false, |aliases| aliases.is_match(room_alias.as_str()))
|
||||
&& db
|
||||
.sending
|
||||
.send_appservice_request(
|
||||
&db.globals,
|
||||
registration,
|
||||
appservice::query::query_room_alias::v1::Request { room_alias },
|
||||
)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
room_id = Some(db.rooms.id_from_alias(&room_alias)?.ok_or_else(|| {
|
||||
Error::bad_config("Appservice lied to us. Room does not exist.")
|
||||
|
|
|
@ -17,6 +17,7 @@ use rocket::{delete, get, post, put};
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/unstable/room_keys/version", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_backup_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_backup::Request>,
|
||||
|
@ -35,6 +36,7 @@ pub async fn create_backup_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_backup_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<update_backup::Request<'_>>,
|
||||
|
@ -52,6 +54,7 @@ pub async fn update_backup_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/unstable/room_keys/version", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_latest_backup_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_latest_backup::Request>,
|
||||
|
@ -79,6 +82,7 @@ pub async fn get_latest_backup_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_backup::Request<'_>>,
|
||||
|
@ -105,6 +109,7 @@ pub async fn get_backup_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_backup::Request<'_>>,
|
||||
|
@ -123,6 +128,7 @@ pub async fn delete_backup_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/unstable/room_keys/keys", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<add_backup_keys::Request<'_>>,
|
||||
|
@ -156,6 +162,7 @@ pub async fn add_backup_keys_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_key_sessions_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<add_backup_key_sessions::Request<'_>>,
|
||||
|
@ -187,6 +194,7 @@ pub async fn add_backup_key_sessions_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_key_session_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<add_backup_key_session::Request<'_>>,
|
||||
|
@ -215,6 +223,7 @@ pub async fn add_backup_key_session_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/unstable/room_keys/keys", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_backup_keys::Request<'_>>,
|
||||
|
@ -230,6 +239,7 @@ pub async fn get_backup_keys_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_key_sessions_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_backup_key_sessions::Request<'_>>,
|
||||
|
@ -247,6 +257,7 @@ pub async fn get_backup_key_sessions_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_key_session_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_backup_key_session::Request<'_>>,
|
||||
|
@ -270,6 +281,7 @@ pub async fn get_backup_key_session_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/unstable/room_keys/keys", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_backup_keys::Request<'_>>,
|
||||
|
@ -292,6 +304,7 @@ pub async fn delete_backup_keys_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_key_sessions_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_backup_key_sessions::Request<'_>>,
|
||||
|
@ -314,6 +327,7 @@ pub async fn delete_backup_key_sessions_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_key_session_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_backup_key_session::Request<'_>>,
|
||||
|
|
|
@ -9,6 +9,7 @@ use rocket::get;
|
|||
///
|
||||
/// Get information on this server's supported feature set and other relevent capabilities.
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/capabilities"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn get_capabilities_route() -> ConduitResult<get_capabilities::Response> {
|
||||
let mut available = BTreeMap::new();
|
||||
available.insert(
|
||||
|
|
|
@ -16,6 +16,7 @@ use rocket::{get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/user/<_>/account_data/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_global_account_data_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_global_account_data::Request<'_>>,
|
||||
|
@ -49,6 +50,7 @@ pub async fn set_global_account_data_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/user/<_>/account_data/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_global_account_data_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_global_account_data::Request<'_>>,
|
||||
|
|
|
@ -10,6 +10,7 @@ use rocket::get;
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/context/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_context_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_context::Request<'_>>,
|
||||
|
|
|
@ -16,6 +16,7 @@ use rocket::{delete, get, post, put};
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/devices", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_devices_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_devices::Request>,
|
||||
|
@ -35,6 +36,7 @@ pub async fn get_devices_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/devices/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_device::Request<'_>>,
|
||||
|
@ -53,6 +55,7 @@ pub async fn get_device_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/devices/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<update_device::Request<'_>>,
|
||||
|
@ -78,6 +81,7 @@ pub async fn update_device_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/r0/devices/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_device::Request<'_>>,
|
||||
|
@ -126,6 +130,7 @@ pub async fn delete_device_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/delete_devices", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_devices_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_devices::Request<'_>>,
|
||||
|
|
|
@ -21,7 +21,7 @@ use ruma::{
|
|||
EventType,
|
||||
},
|
||||
serde::Raw,
|
||||
ServerName,
|
||||
ServerName, UInt,
|
||||
};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
|
@ -31,6 +31,7 @@ use rocket::{get, post, put};
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/publicRooms", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_public_rooms_filtered::Request<'_>>,
|
||||
|
@ -50,6 +51,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/publicRooms", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_public_rooms::Request<'_>>,
|
||||
|
@ -78,6 +80,7 @@ pub async fn get_public_rooms_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/directory/list/room/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_room_visibility_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_room_visibility::Request<'_>>,
|
||||
|
@ -107,6 +110,7 @@ pub async fn set_room_visibility_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/directory/list/room/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_visibility_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_room_visibility::Request<'_>>,
|
||||
|
@ -124,7 +128,7 @@ pub async fn get_room_visibility_route(
|
|||
pub async fn get_public_rooms_filtered_helper(
|
||||
db: &Database,
|
||||
server: Option<&ServerName>,
|
||||
limit: Option<ruma::UInt>,
|
||||
limit: Option<UInt>,
|
||||
since: Option<&str>,
|
||||
filter: &IncomingFilter,
|
||||
_network: &IncomingRoomNetwork,
|
||||
|
|
|
@ -5,6 +5,7 @@ use ruma::api::client::r0::filter::{self, create_filter, get_filter};
|
|||
use rocket::{get, post};
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/user/<_>/filter/<_>"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn get_filter_route() -> ConduitResult<get_filter::Response> {
|
||||
// TODO
|
||||
Ok(get_filter::Response::new(filter::IncomingFilterDefinition {
|
||||
|
@ -18,6 +19,7 @@ pub async fn get_filter_route() -> ConduitResult<get_filter::Response> {
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/user/<_>/filter"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn create_filter_route() -> ConduitResult<create_filter::Response> {
|
||||
// TODO
|
||||
Ok(create_filter::Response::new(utils::random_string(10)).into())
|
||||
|
|
|
@ -22,6 +22,7 @@ use rocket::{get, post};
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/keys/upload", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<upload_keys::Request>,
|
||||
|
@ -70,6 +71,7 @@ pub async fn upload_keys_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/keys/query", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_keys::Request<'_>>,
|
||||
|
@ -150,6 +152,7 @@ pub async fn get_keys_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/keys/claim", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn claim_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<claim_keys::Request>,
|
||||
|
@ -183,6 +186,7 @@ pub async fn claim_keys_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/unstable/keys/device_signing/upload", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_signing_keys_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<upload_signing_keys::Request<'_>>,
|
||||
|
@ -240,6 +244,7 @@ pub async fn upload_signing_keys_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/unstable/keys/signatures/upload", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_signatures_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<upload_signatures::Request>,
|
||||
|
@ -300,6 +305,7 @@ pub async fn upload_signatures_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/keys/changes", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_key_changes_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_key_changes::Request<'_>>,
|
||||
|
|
|
@ -12,6 +12,7 @@ use std::convert::TryInto;
|
|||
const MXC_LENGTH: usize = 32;
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/media/r0/config"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub async fn get_media_config_route(
|
||||
db: State<'_, Database>,
|
||||
) -> ConduitResult<get_media_config::Response> {
|
||||
|
@ -25,6 +26,7 @@ pub async fn get_media_config_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/media/r0/upload", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_content_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_content::Request<'_>>,
|
||||
|
@ -54,6 +56,7 @@ pub async fn create_content_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/media/r0/download/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_content_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_content::Request<'_>>,
|
||||
|
@ -103,6 +106,7 @@ pub async fn get_content_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/media/r0/thumbnail/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_content_thumbnail_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_content_thumbnail::Request<'_>>,
|
||||
|
|
|
@ -36,6 +36,7 @@ use rocket::{get, post};
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/join", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn join_room_by_id_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<join_room_by_id::Request<'_>>,
|
||||
|
@ -54,6 +55,7 @@ pub async fn join_room_by_id_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/join/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn join_room_by_id_or_alias_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<join_room_by_id_or_alias::Request<'_>>,
|
||||
|
@ -88,6 +90,7 @@ pub async fn join_room_by_id_or_alias_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/leave", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn leave_room_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<leave_room::Request<'_>>,
|
||||
|
@ -136,6 +139,7 @@ pub async fn leave_room_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/invite", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn invite_user_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<invite_user::Request<'_>>,
|
||||
|
@ -175,6 +179,7 @@ pub async fn invite_user_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/kick", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn kick_user_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<kick_user::Request<'_>>,
|
||||
|
@ -224,6 +229,7 @@ pub async fn kick_user_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/ban", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn ban_user_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<ban_user::Request<'_>>,
|
||||
|
@ -280,6 +286,7 @@ pub async fn ban_user_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/unban", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn unban_user_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<unban_user::Request<'_>>,
|
||||
|
@ -328,6 +335,7 @@ pub async fn unban_user_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/forget", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn forget_room_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<forget_room::Request<'_>>,
|
||||
|
@ -345,6 +353,7 @@ pub async fn forget_room_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/joined_rooms", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn joined_rooms_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<joined_rooms::Request>,
|
||||
|
@ -365,6 +374,7 @@ pub async fn joined_rooms_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/members", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_member_events_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_member_events::Request<'_>>,
|
||||
|
@ -394,6 +404,7 @@ pub async fn get_member_events_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/joined_members", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn joined_members_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<joined_members::Request<'_>>,
|
||||
|
|
|
@ -20,6 +20,7 @@ use rocket::{get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/send/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_message_event_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<send_message_event::Request<'_>>,
|
||||
|
@ -87,6 +88,7 @@ pub async fn send_message_event_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/messages", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_message_events_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_message_events::Request<'_>>,
|
||||
|
|
|
@ -75,6 +75,7 @@ const SESSION_ID_LENGTH: usize = 256;
|
|||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
#[options("/<_..>")]
|
||||
#[tracing::instrument]
|
||||
pub async fn options_route() -> ConduitResult<send_event_to_device::Response> {
|
||||
Ok(send_event_to_device::Response.into())
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use rocket::put;
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/presence/<_>/status", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_presence_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_presence::Request<'_>>,
|
||||
|
|
|
@ -19,6 +19,7 @@ use std::convert::TryInto;
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/profile/<_>/displayname", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_displayname_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_display_name::Request<'_>>,
|
||||
|
@ -98,6 +99,7 @@ pub async fn set_displayname_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/profile/<_>/displayname", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_displayname_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_display_name::Request<'_>>,
|
||||
|
@ -112,6 +114,7 @@ pub async fn get_displayname_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/profile/<_>/avatar_url", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_avatar_url_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_avatar_url::Request<'_>>,
|
||||
|
@ -191,6 +194,7 @@ pub async fn set_avatar_url_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/profile/<_>/avatar_url", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_avatar_url_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_avatar_url::Request<'_>>,
|
||||
|
@ -205,6 +209,7 @@ pub async fn get_avatar_url_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/profile/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_profile_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_profile::Request<'_>>,
|
||||
|
|
|
@ -22,6 +22,7 @@ use rocket::{delete, get, post, put};
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/pushrules", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrules_all_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_pushrules_all::Request>,
|
||||
|
@ -46,6 +47,7 @@ pub async fn get_pushrules_all_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_pushrule::Request<'_>>,
|
||||
|
@ -104,6 +106,7 @@ pub async fn get_pushrule_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_pushrule::Request<'_>>,
|
||||
|
@ -250,6 +253,7 @@ pub async fn set_pushrule_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/pushrules/<_>/<_>/<_>/actions", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_actions_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_pushrule_actions::Request<'_>>,
|
||||
|
@ -313,6 +317,7 @@ pub async fn get_pushrule_actions_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/pushrules/<_>/<_>/<_>/actions", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_actions_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_pushrule_actions::Request<'_>>,
|
||||
|
@ -416,6 +421,7 @@ pub async fn set_pushrule_actions_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/pushrules/<_>/<_>/<_>/enabled", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_enabled_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_pushrule_enabled::Request<'_>>,
|
||||
|
@ -476,6 +482,7 @@ pub async fn get_pushrule_enabled_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/pushrules/<_>/<_>/<_>/enabled", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_enabled_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_pushrule_enabled::Request<'_>>,
|
||||
|
@ -579,6 +586,7 @@ pub async fn set_pushrule_enabled_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_pushrule_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_pushrule::Request<'_>>,
|
||||
|
@ -669,6 +677,7 @@ pub async fn delete_pushrule_route(
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/pushers"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn get_pushers_route() -> ConduitResult<get_pushers::Response> {
|
||||
Ok(get_pushers::Response {
|
||||
pushers: Vec::new(),
|
||||
|
@ -677,6 +686,7 @@ pub async fn get_pushers_route() -> ConduitResult<get_pushers::Response> {
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/pushers/set"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub async fn set_pushers_route(db: State<'_, Database>) -> ConduitResult<get_pushers::Response> {
|
||||
db.flush().await?;
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ use super::State;
|
|||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind, r0::capabilities::get_capabilities, r0::read_marker::set_read_marker,
|
||||
error::ErrorKind,
|
||||
r0::{read_marker::set_read_marker, receipt::create_receipt},
|
||||
},
|
||||
events::{AnyEphemeralRoomEvent, AnyEvent, EventType},
|
||||
};
|
||||
|
@ -15,6 +16,7 @@ use std::{collections::BTreeMap, time::SystemTime};
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/read_markers", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_read_marker_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_read_marker::Request<'_>>,
|
||||
|
@ -83,13 +85,53 @@ pub async fn set_read_marker_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_>/receipt/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
pub async fn set_receipt_route(
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_receipt_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_capabilities::Request>,
|
||||
) -> ConduitResult<set_read_marker::Response> {
|
||||
let _sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
body: Ruma<create_receipt::Request<'_>>,
|
||||
) -> ConduitResult<create_receipt::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.rooms.edus.private_read_set(
|
||||
&body.room_id,
|
||||
&sender_user,
|
||||
db.rooms
|
||||
.get_pdu_count(&body.event_id)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Event does not exist.",
|
||||
))?,
|
||||
&db.globals,
|
||||
)?;
|
||||
|
||||
let mut user_receipts = BTreeMap::new();
|
||||
user_receipts.insert(
|
||||
sender_user.clone(),
|
||||
ruma::events::receipt::Receipt {
|
||||
ts: Some(SystemTime::now()),
|
||||
},
|
||||
);
|
||||
let mut receipt_content = BTreeMap::new();
|
||||
receipt_content.insert(
|
||||
body.event_id.to_owned(),
|
||||
ruma::events::receipt::Receipts {
|
||||
read: Some(user_receipts),
|
||||
},
|
||||
);
|
||||
|
||||
db.rooms.edus.readreceipt_update(
|
||||
&sender_user,
|
||||
&body.room_id,
|
||||
AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt(
|
||||
ruma::events::receipt::ReceiptEvent {
|
||||
content: ruma::events::receipt::ReceiptEventContent(receipt_content),
|
||||
room_id: body.room_id.clone(),
|
||||
},
|
||||
)),
|
||||
&db.globals,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_read_marker::Response.into())
|
||||
Ok(create_receipt::Response.into())
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use rocket::put;
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/redact/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn redact_event_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<redact_event::Request<'_>>,
|
||||
|
|
|
@ -22,6 +22,7 @@ use rocket::{get, post};
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/createRoom", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_room_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_room::Request<'_>>,
|
||||
|
@ -306,6 +307,7 @@ pub async fn create_room_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/event/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_event_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_room_event::Request<'_>>,
|
||||
|
@ -333,6 +335,7 @@ pub async fn get_room_event_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/rooms/<_room_id>/upgrade", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upgrade_room_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<upgrade_room::Request<'_>>,
|
||||
|
|
|
@ -11,6 +11,7 @@ use std::collections::BTreeMap;
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/search", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn search_events_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<search_events::Request<'_>>,
|
||||
|
|
|
@ -24,6 +24,7 @@ use rocket::{get, post};
|
|||
/// Get the homeserver's supported login types. One of these should be used as the `type` field
|
||||
/// when logging in.
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/login"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response> {
|
||||
Ok(get_login_types::Response::new(vec![get_login_types::LoginType::Password]).into())
|
||||
}
|
||||
|
@ -42,6 +43,7 @@ pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response>
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/login", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn login_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<login::Request<'_>>,
|
||||
|
@ -155,6 +157,7 @@ pub async fn login_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/logout", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn logout_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<logout::Request>,
|
||||
|
@ -182,6 +185,7 @@ pub async fn logout_route(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/logout/all", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn logout_all_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<logout_all::Request>,
|
||||
|
|
|
@ -22,6 +22,7 @@ use rocket::{get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_state_event_for_key_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<send_state_event_for_key::Request<'_>>,
|
||||
|
@ -55,6 +56,7 @@ pub async fn send_state_event_for_key_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/state/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_state_event_for_empty_key_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<send_state_event_for_empty_key::Request<'_>>,
|
||||
|
@ -96,6 +98,7 @@ pub async fn send_state_event_for_empty_key_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/state", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_state_events::Request<'_>>,
|
||||
|
@ -142,6 +145,7 @@ pub async fn get_state_events_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_for_key_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||
|
@ -193,6 +197,7 @@ pub async fn get_state_events_for_key_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/rooms/<_>/state/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_for_empty_key_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_state_events_for_empty_key::Request<'_>>,
|
||||
|
|
|
@ -30,6 +30,7 @@ use std::{
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/sync", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn sync_events_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<sync_events::Request<'_>>,
|
||||
|
@ -310,8 +311,7 @@ pub async fn sync_events_route(
|
|||
};
|
||||
|
||||
let state_events = if joined_since_last_sync {
|
||||
db.rooms
|
||||
.room_state_full(&room_id)?
|
||||
current_state
|
||||
.into_iter()
|
||||
.map(|(_, pdu)| pdu.to_sync_state_event())
|
||||
.collect()
|
||||
|
@ -709,6 +709,7 @@ pub async fn sync_events_route(
|
|||
Ok(response.into())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(db))]
|
||||
fn share_encrypted_room(
|
||||
db: &Database,
|
||||
sender_user: &UserId,
|
||||
|
|
|
@ -13,6 +13,7 @@ use rocket::{delete, get, put};
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_tag_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_tag::Request<'_>>,
|
||||
|
@ -49,6 +50,7 @@ pub async fn update_tag_route(
|
|||
feature = "conduit_bin",
|
||||
delete("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_tag_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_tag::Request<'_>>,
|
||||
|
@ -82,6 +84,7 @@ pub async fn delete_tag_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/user/<_>/rooms/<_>/tags", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_tags_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_tags::Request<'_>>,
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::collections::BTreeMap;
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/thirdparty/protocols")
|
||||
)]
|
||||
#[tracing::instrument]
|
||||
pub async fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
|
||||
warn!("TODO: get_protocols_route");
|
||||
Ok(get_protocols::Response {
|
||||
|
|
|
@ -12,6 +12,7 @@ use rocket::put;
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/sendToDevice/<_>/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_event_to_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<send_event_to_device::Request<'_>>,
|
||||
|
|
|
@ -10,6 +10,7 @@ use rocket::put;
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/rooms/<_>/typing/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn create_typing_event_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<create_typing_event::Request<'_>>,
|
||||
|
|
|
@ -15,6 +15,7 @@ use rocket::get;
|
|||
/// Note: Unstable features are used while developing new features. Clients should avoid using
|
||||
/// unstable features in their stable releases
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/versions"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> {
|
||||
let mut resp =
|
||||
get_supported_versions::Response::new(vec!["r0.5.0".to_owned(), "r0.6.0".to_owned()]);
|
||||
|
|
|
@ -9,6 +9,7 @@ use rocket::post;
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/client/r0/user_directory/search", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn search_users_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<search_users::Request<'_>>,
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::time::Duration;
|
|||
use rocket::get;
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/voip/turnServer"))]
|
||||
#[tracing::instrument]
|
||||
pub async fn turn_server_route() -> ConduitResult<get_turn_server_info::Response> {
|
||||
Ok(get_turn_server_info::Response {
|
||||
username: "".to_owned(),
|
||||
|
|
|
@ -38,6 +38,8 @@ pub struct Config {
|
|||
allow_encryption: bool,
|
||||
#[serde(default = "false_fn")]
|
||||
allow_federation: bool,
|
||||
#[serde(default = "false_fn")]
|
||||
pub allow_jaeger: bool,
|
||||
jwt_secret: Option<String>,
|
||||
#[serde(default = "Vec::new")]
|
||||
trusted_servers: Vec<Box<ServerName>>,
|
||||
|
|
|
@ -74,6 +74,7 @@ impl AccountData {
|
|||
}
|
||||
|
||||
/// Returns all changes to the account data that happened after `since`.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn changes_since(
|
||||
&self,
|
||||
room_id: Option<&RoomId>,
|
||||
|
|
|
@ -7,7 +7,6 @@ use ruma::{
|
|||
events::{room::message, EventType},
|
||||
UserId,
|
||||
};
|
||||
use tokio::select;
|
||||
|
||||
pub enum AdminCommand {
|
||||
RegisterAppservice(serde_yaml::Value),
|
||||
|
@ -67,7 +66,7 @@ impl Admin {
|
|||
};
|
||||
|
||||
loop {
|
||||
select! {
|
||||
tokio::select! {
|
||||
Some(event) = receiver.next() => {
|
||||
match event {
|
||||
AdminCommand::RegisterAppservice(yaml) => {
|
||||
|
|
|
@ -12,11 +12,11 @@ use trust_dns_resolver::TokioAsyncResolver;
|
|||
|
||||
pub const COUNTER: &str = "c";
|
||||
|
||||
pub type DestinationCache = Arc<RwLock<HashMap<Box<ServerName>, (String, Option<String>)>>>;
|
||||
type WellKnownMap = HashMap<Box<ServerName>, (String, Option<String>)>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Globals {
|
||||
pub actual_destination_cache: DestinationCache, // actual_destination, host
|
||||
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
|
||||
pub(super) globals: sled::Tree,
|
||||
config: Config,
|
||||
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
||||
|
|
|
@ -83,8 +83,7 @@ pub struct Rooms {
|
|||
impl Rooms {
|
||||
/// Builds a StateMap by iterating over all keys that start
|
||||
/// with state_hash, this gives the full state for the given state_hash.
|
||||
///
|
||||
/// TODO: Should this check for outliers, it does now.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn state_full(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
@ -129,6 +128,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn state_get(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
@ -178,11 +178,13 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns the state hash for this pdu.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn pdu_state_hash(&self, pdu_id: &[u8]) -> Result<Option<StateHashId>> {
|
||||
Ok(self.pduid_statehash.get(pdu_id)?)
|
||||
}
|
||||
|
||||
/// Returns the last state hash key added to the db for the given room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn current_state_hash(&self, room_id: &RoomId) -> Result<Option<StateHashId>> {
|
||||
Ok(self.roomid_statehash.get(room_id.as_bytes())?)
|
||||
}
|
||||
|
@ -290,6 +292,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns the full room state.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_state_full(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
@ -302,6 +305,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_state_get(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
@ -316,6 +320,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns the `count` of this pdu's id.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn pdu_count(&self, pdu_id: &[u8]) -> Result<u64> {
|
||||
Ok(
|
||||
utils::u64_from_bytes(&pdu_id[pdu_id.len() - mem::size_of::<u64>()..pdu_id.len()])
|
||||
|
@ -515,6 +520,7 @@ impl Rooms {
|
|||
///
|
||||
/// By this point the incoming event should be fully authenticated, no auth happens
|
||||
/// in `append_pdu`.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn append_pdu(
|
||||
&self,
|
||||
pdu: &PduEvent,
|
||||
|
@ -1113,6 +1119,7 @@ impl Rooms {
|
|||
|
||||
let user_is_joined =
|
||||
|bridge_user_id| self.is_joined(&bridge_user_id, room_id).unwrap_or(false);
|
||||
|
||||
let matching_users = |users: &Regex| {
|
||||
users.is_match(pdu.sender.as_str())
|
||||
|| pdu.kind == EventType::RoomMember
|
||||
|
@ -1141,6 +1148,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all PDUs in a room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn all_pdus(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
@ -1151,6 +1159,7 @@ impl Rooms {
|
|||
|
||||
/// Returns a double-ended iterator over all events in a room that happened after the event with id `since`
|
||||
/// in chronological order.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn pdus_since(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
@ -1217,6 +1226,7 @@ impl Rooms {
|
|||
|
||||
/// Returns an iterator over all events and their token in a room that happened after the event
|
||||
/// with id `from` in chronological order.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn pdus_after(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
@ -1566,6 +1576,7 @@ impl Rooms {
|
|||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_shared_rooms<'a>(
|
||||
&'a self,
|
||||
users: Vec<UserId>,
|
||||
|
@ -1627,6 +1638,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all joined members of a room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_members(&self, room_id: &RoomId) -> impl Iterator<Item = Result<UserId>> {
|
||||
let mut prefix = room_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
@ -1675,6 +1687,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all invited members of a room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_members_invited(&self, room_id: &RoomId) -> impl Iterator<Item = Result<UserId>> {
|
||||
let mut prefix = room_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
@ -1699,6 +1712,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all rooms this user joined.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn rooms_joined(&self, user_id: &UserId) -> impl Iterator<Item = Result<RoomId>> {
|
||||
self.userroomid_joined
|
||||
.scan_prefix(user_id.as_bytes())
|
||||
|
@ -1720,6 +1734,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all rooms a user was invited to.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn rooms_invited(&self, user_id: &UserId) -> impl Iterator<Item = Result<RoomId>> {
|
||||
let mut prefix = user_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
@ -1744,6 +1759,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all rooms a user left.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn rooms_left(&self, user_id: &UserId) -> impl Iterator<Item = Result<RoomId>> {
|
||||
let mut prefix = user_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
|
|
@ -70,6 +70,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
/// Returns an iterator over the most recent read_receipts in a room that happened after the event with id `since`.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn readreceipts_since(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
@ -115,6 +116,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
/// Returns the private read marker.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
|
||||
let mut key = room_id.to_string().as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
|
@ -256,6 +258,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
/// Returns the count of the last typing update in this room.
|
||||
#[tracing::instrument(skip(self, globals))]
|
||||
pub fn last_typing_update(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
@ -339,6 +342,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
/// Resets the presence timeout, so the user will stay in their current presence state.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn ping_presence(&self, user_id: &UserId) -> Result<()> {
|
||||
self.userid_lastpresenceupdate.insert(
|
||||
&user_id.to_string().as_bytes(),
|
||||
|
@ -429,6 +433,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
/// Returns an iterator over the most recent presence updates that happened after the event with id `since`.
|
||||
#[tracing::instrument(skip(self, globals, rooms))]
|
||||
pub fn presence_since(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
|
@ -8,7 +8,8 @@ use std::{
|
|||
|
||||
use crate::{appservice_server, server_server, utils, Error, PduEvent, Result};
|
||||
use federation::transactions::send_transaction_message;
|
||||
use log::info;
|
||||
use log::{info, warn};
|
||||
use ring::digest;
|
||||
use rocket::futures::stream::{FuturesUnordered, StreamExt};
|
||||
use ruma::{
|
||||
api::{appservice, federation, OutgoingRequest},
|
||||
|
@ -35,6 +36,7 @@ impl Sending {
|
|||
) {
|
||||
let servernamepduids = self.servernamepduids.clone();
|
||||
let servercurrentpdus = self.servercurrentpdus.clone();
|
||||
let maximum_requests = self.maximum_requests.clone();
|
||||
let rooms = rooms.clone();
|
||||
let globals = globals.clone();
|
||||
let appservice = appservice.clone();
|
||||
|
@ -43,23 +45,43 @@ impl Sending {
|
|||
let mut futures = FuturesUnordered::new();
|
||||
|
||||
// Retry requests we could not finish yet
|
||||
let mut current_transactions = HashMap::new();
|
||||
let mut current_transactions = HashMap::<(Box<ServerName>, bool), Vec<IVec>>::new();
|
||||
|
||||
for (server, pdu, is_appservice) in servercurrentpdus
|
||||
for (key, server, pdu, is_appservice) in servercurrentpdus
|
||||
.iter()
|
||||
.filter_map(|r| r.ok())
|
||||
.filter_map(|(key, _)| Self::parse_servercurrentpdus(key).ok())
|
||||
.filter(|(_, pdu, _)| !pdu.is_empty()) // Skip reservation key
|
||||
.take(50)
|
||||
// This should not contain more than 50 anyway
|
||||
{
|
||||
current_transactions
|
||||
if pdu.is_empty() {
|
||||
// Remove old reservation key
|
||||
servercurrentpdus.remove(key).unwrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
let entry = current_transactions
|
||||
.entry((server, is_appservice))
|
||||
.or_insert_with(Vec::new)
|
||||
.push(pdu);
|
||||
.or_insert_with(Vec::new);
|
||||
|
||||
if entry.len() > 30 {
|
||||
warn!("Dropping some current pdus because too many were queued. This should not happen.");
|
||||
servercurrentpdus.remove(key).unwrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.push(pdu);
|
||||
}
|
||||
|
||||
for ((server, is_appservice), pdus) in current_transactions {
|
||||
// Create new reservation
|
||||
let mut prefix = if is_appservice {
|
||||
b"+".to_vec()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
prefix.extend_from_slice(server.as_bytes());
|
||||
prefix.push(0xff);
|
||||
servercurrentpdus.insert(prefix, &[]).unwrap();
|
||||
|
||||
futures.push(Self::handle_event(
|
||||
server,
|
||||
is_appservice,
|
||||
|
@ -67,6 +89,7 @@ impl Sending {
|
|||
&globals,
|
||||
&rooms,
|
||||
&appservice,
|
||||
&maximum_requests,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -105,7 +128,7 @@ impl Sending {
|
|||
.map(|k| {
|
||||
k.subslice(prefix.len(), k.len() - prefix.len())
|
||||
})
|
||||
.take(50)
|
||||
.take(30)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !new_pdus.is_empty() {
|
||||
|
@ -116,7 +139,7 @@ impl Sending {
|
|||
servernamepduids.remove(¤t_key).unwrap();
|
||||
}
|
||||
|
||||
futures.push(Self::handle_event(server, is_appservice, new_pdus, &globals, &rooms, &appservice));
|
||||
futures.push(Self::handle_event(server, is_appservice, new_pdus, &globals, &rooms, &appservice, &maximum_requests));
|
||||
} else {
|
||||
servercurrentpdus.remove(&prefix).unwrap();
|
||||
// servercurrentpdus with the prefix should be empty now
|
||||
|
@ -202,7 +225,7 @@ impl Sending {
|
|||
servercurrentpdus.insert(&key, &[]).unwrap();
|
||||
servernamepduids.remove(&key).unwrap();
|
||||
|
||||
futures.push(Self::handle_event(server, is_appservice, vec![pdu_id.into()], &globals, &rooms, &appservice));
|
||||
futures.push(Self::handle_event(server, is_appservice, vec![pdu_id.into()], &globals, &rooms, &appservice, &maximum_requests));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -211,6 +234,7 @@ impl Sending {
|
|||
});
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn send_pdu(&self, server: &ServerName, pdu_id: &[u8]) -> Result<()> {
|
||||
let mut key = server.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
|
@ -220,6 +244,7 @@ impl Sending {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn send_pdu_appservice(&self, appservice_id: &str, pdu_id: &[u8]) -> Result<()> {
|
||||
let mut key = b"+".to_vec();
|
||||
key.extend_from_slice(appservice_id.as_bytes());
|
||||
|
@ -230,6 +255,15 @@ impl Sending {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
fn calculate_hash(keys: &[IVec]) -> Vec<u8> {
|
||||
// We only hash the pdu's event ids, not the whole pdu
|
||||
let bytes = keys.join(&0xff);
|
||||
let hash = digest::digest(&digest::SHA256, &bytes);
|
||||
hash.as_ref().to_owned()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(globals, rooms, appservice))]
|
||||
async fn handle_event(
|
||||
server: Box<ServerName>,
|
||||
is_appservice: bool,
|
||||
|
@ -237,6 +271,7 @@ impl Sending {
|
|||
globals: &super::globals::Globals,
|
||||
rooms: &super::rooms::Rooms,
|
||||
appservice: &super::appservice::Appservice,
|
||||
maximum_requests: &Semaphore,
|
||||
) -> std::result::Result<(Box<ServerName>, bool), (Box<ServerName>, bool, Error)> {
|
||||
if is_appservice {
|
||||
let pdu_jsons = pdu_ids
|
||||
|
@ -259,7 +294,9 @@ impl Sending {
|
|||
})
|
||||
.filter_map(|r| r.ok())
|
||||
.collect::<Vec<_>>();
|
||||
appservice_server::send_request(
|
||||
|
||||
let permit = maximum_requests.acquire().await;
|
||||
let response = appservice_server::send_request(
|
||||
&globals,
|
||||
appservice
|
||||
.get_registration(server.as_str())
|
||||
|
@ -267,12 +304,19 @@ impl Sending {
|
|||
.unwrap(), // TODO: handle error
|
||||
appservice::event::push_events::v1::Request {
|
||||
events: &pdu_jsons,
|
||||
txn_id: &utils::random_string(16),
|
||||
txn_id: &base64::encode_config(
|
||||
Self::calculate_hash(&pdu_ids),
|
||||
base64::URL_SAFE_NO_PAD,
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(|_response| (server.clone(), is_appservice))
|
||||
.map_err(|e| (server, is_appservice, e))
|
||||
.map_err(|e| (server, is_appservice, e));
|
||||
|
||||
drop(permit);
|
||||
|
||||
response
|
||||
} else {
|
||||
let pdu_jsons = pdu_ids
|
||||
.iter()
|
||||
|
@ -302,7 +346,8 @@ impl Sending {
|
|||
.filter_map(|r| r.ok())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
server_server::send_request(
|
||||
let permit = maximum_requests.acquire().await;
|
||||
let response = server_server::send_request(
|
||||
&globals,
|
||||
&*server,
|
||||
send_transaction_message::v1::Request {
|
||||
|
@ -310,17 +355,25 @@ impl Sending {
|
|||
pdus: &pdu_jsons,
|
||||
edus: &[],
|
||||
origin_server_ts: SystemTime::now(),
|
||||
transaction_id: &utils::random_string(16),
|
||||
transaction_id: &base64::encode_config(
|
||||
Self::calculate_hash(&pdu_ids),
|
||||
base64::URL_SAFE_NO_PAD,
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(|_response| (server.clone(), is_appservice))
|
||||
.map_err(|e| (server, is_appservice, e))
|
||||
.map_err(|e| (server, is_appservice, e));
|
||||
|
||||
drop(permit);
|
||||
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_servercurrentpdus(key: IVec) -> Result<(Box<ServerName>, IVec, bool)> {
|
||||
let mut parts = key.splitn(2, |&b| b == 0xff);
|
||||
fn parse_servercurrentpdus(key: IVec) -> Result<(IVec, Box<ServerName>, IVec, bool)> {
|
||||
let key2 = key.clone();
|
||||
let mut parts = key2.splitn(2, |&b| b == 0xff);
|
||||
let server = parts.next().expect("splitn always returns one element");
|
||||
let pdu = parts
|
||||
.next()
|
||||
|
@ -338,6 +391,7 @@ impl Sending {
|
|||
};
|
||||
|
||||
Ok::<_, Error>((
|
||||
key,
|
||||
Box::<ServerName>::try_from(server).map_err(|_| {
|
||||
Error::bad_database("Invalid server string in server_currenttransaction")
|
||||
})?,
|
||||
|
@ -346,6 +400,7 @@ impl Sending {
|
|||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, globals))]
|
||||
pub async fn send_federation_request<T: OutgoingRequest>(
|
||||
&self,
|
||||
globals: &crate::database::globals::Globals,
|
||||
|
@ -362,6 +417,7 @@ impl Sending {
|
|||
response
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, globals))]
|
||||
pub async fn send_appservice_request<T: OutgoingRequest>(
|
||||
&self,
|
||||
globals: &crate::database::globals::Globals,
|
||||
|
|
|
@ -311,6 +311,7 @@ impl Users {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> {
|
||||
self.userid_lastonetimekeyupdate
|
||||
.get(&user_id.to_string().as_bytes())?
|
||||
|
@ -364,6 +365,7 @@ impl Users {
|
|||
.transpose()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn count_one_time_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
@ -563,6 +565,7 @@ impl Users {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn keys_changed(
|
||||
&self,
|
||||
user_or_room_id: &str,
|
||||
|
@ -738,6 +741,7 @@ impl Users {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_to_device_events(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
@ -760,6 +764,7 @@ impl Users {
|
|||
Ok(events)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn remove_to_device_events(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
55
src/main.rs
55
src/main.rs
|
@ -11,21 +11,23 @@ mod push_rules;
|
|||
mod ruma_wrapper;
|
||||
mod utils;
|
||||
|
||||
use database::Config;
|
||||
pub use database::Database;
|
||||
pub use error::{ConduitLogger, Error, Result};
|
||||
pub use error::{Error, Result};
|
||||
pub use pdu::PduEvent;
|
||||
pub use rocket::State;
|
||||
use ruma::api::client::error::ErrorKind;
|
||||
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
||||
|
||||
use log::LevelFilter;
|
||||
use rocket::figment::{
|
||||
providers::{Env, Format, Toml},
|
||||
Figment,
|
||||
};
|
||||
use rocket::{catch, catchers, fairing::AdHoc, routes, Request};
|
||||
use tracing::span;
|
||||
use tracing_subscriber::{prelude::*, Registry};
|
||||
|
||||
fn setup_rocket() -> rocket::Rocket {
|
||||
fn setup_rocket() -> (rocket::Rocket, Config) {
|
||||
// Force log level off, so we can use our own logger
|
||||
std::env::set_var("CONDUIT_LOG_LEVEL", "off");
|
||||
|
||||
|
@ -39,7 +41,12 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
)
|
||||
.merge(Env::prefixed("CONDUIT_").global());
|
||||
|
||||
rocket::custom(config)
|
||||
let parsed_config = config
|
||||
.extract::<Config>()
|
||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||
let parsed_config2 = parsed_config.clone();
|
||||
|
||||
let rocket = rocket::custom(config)
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
|
@ -90,7 +97,7 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
client_server::get_backup_key_sessions_route,
|
||||
client_server::get_backup_keys_route,
|
||||
client_server::set_read_marker_route,
|
||||
client_server::set_receipt_route,
|
||||
client_server::create_receipt_route,
|
||||
client_server::create_typing_event_route,
|
||||
client_server::create_room_route,
|
||||
client_server::redact_event_route,
|
||||
|
@ -163,31 +170,41 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
bad_json_catcher
|
||||
])
|
||||
.attach(AdHoc::on_attach("Config", |rocket| async {
|
||||
let config = rocket
|
||||
.figment()
|
||||
.extract()
|
||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||
|
||||
let data = Database::load_or_create(config)
|
||||
let data = Database::load_or_create(parsed_config2)
|
||||
.await
|
||||
.expect("config is valid");
|
||||
|
||||
data.sending
|
||||
.start_handler(&data.globals, &data.rooms, &data.appservice);
|
||||
log::set_boxed_logger(Box::new(ConduitLogger {
|
||||
db: data.clone(),
|
||||
last_logs: Default::default(),
|
||||
}))
|
||||
.unwrap();
|
||||
log::set_max_level(LevelFilter::Info);
|
||||
|
||||
Ok(rocket.manage(data))
|
||||
}))
|
||||
}));
|
||||
|
||||
(rocket, parsed_config)
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
setup_rocket().launch().await.unwrap();
|
||||
let (rocket, config) = setup_rocket();
|
||||
|
||||
if config.allow_jaeger {
|
||||
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||
.with_service_name("conduit")
|
||||
.install()
|
||||
.unwrap();
|
||||
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||
Registry::default().with(telemetry).try_init().unwrap();
|
||||
|
||||
let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
||||
let _enter = root.enter();
|
||||
|
||||
rocket.launch().await.unwrap();
|
||||
} else {
|
||||
let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
||||
let _enter = root.enter();
|
||||
|
||||
rocket.launch().await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
|
|
38
src/pdu.rs
38
src/pdu.rs
|
@ -4,7 +4,7 @@ use ruma::{
|
|||
pdu::EventHash, room::member::MemberEventContent, AnyEvent, AnyRoomEvent, AnyStateEvent,
|
||||
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
|
||||
},
|
||||
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -34,6 +34,7 @@ pub struct PduEvent {
|
|||
}
|
||||
|
||||
impl PduEvent {
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn redact(&mut self, reason: &PduEvent) -> crate::Result<()> {
|
||||
self.unsigned.clear();
|
||||
|
||||
|
@ -80,6 +81,7 @@ impl PduEvent {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_sync_room_event(&self) -> Raw<AnySyncRoomEvent> {
|
||||
let mut json = json!({
|
||||
"content": self.content,
|
||||
|
@ -101,6 +103,7 @@ impl PduEvent {
|
|||
}
|
||||
|
||||
/// This only works for events that are also AnyRoomEvents.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_any_event(&self) -> Raw<AnyEvent> {
|
||||
let mut json = json!({
|
||||
"content": self.content,
|
||||
|
@ -122,6 +125,7 @@ impl PduEvent {
|
|||
serde_json::from_value(json).expect("Raw::from_value always works")
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_room_event(&self) -> Raw<AnyRoomEvent> {
|
||||
let mut json = json!({
|
||||
"content": self.content,
|
||||
|
@ -143,6 +147,7 @@ impl PduEvent {
|
|||
serde_json::from_value(json).expect("Raw::from_value always works")
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_state_event(&self) -> Raw<AnyStateEvent> {
|
||||
let json = json!({
|
||||
"content": self.content,
|
||||
|
@ -158,20 +163,27 @@ impl PduEvent {
|
|||
serde_json::from_value(json).expect("Raw::from_value always works")
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> {
|
||||
let json = json!({
|
||||
"content": self.content,
|
||||
"type": self.kind,
|
||||
"event_id": self.event_id,
|
||||
"sender": self.sender,
|
||||
"origin_server_ts": self.origin_server_ts,
|
||||
"unsigned": self.unsigned,
|
||||
"state_key": self.state_key,
|
||||
});
|
||||
let json = format!(
|
||||
r#"{{"content":{},"type":"{}","event_id":"{}","sender":"{}","origin_server_ts":{},"unsigned":{},"state_key":"{}"}}"#,
|
||||
self.content,
|
||||
self.kind,
|
||||
self.event_id,
|
||||
self.sender,
|
||||
self.origin_server_ts,
|
||||
serde_json::to_string(&self.unsigned).expect("Map::to_string always works"),
|
||||
self.state_key
|
||||
.as_ref()
|
||||
.expect("state events have state keys")
|
||||
);
|
||||
|
||||
serde_json::from_value(json).expect("Raw::from_value always works")
|
||||
Raw::from_json(
|
||||
serde_json::value::RawValue::from_string(json).expect("our string is valid json"),
|
||||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> {
|
||||
let json = json!({
|
||||
"content": self.content,
|
||||
|
@ -183,6 +195,7 @@ impl PduEvent {
|
|||
serde_json::from_value(json).expect("Raw::from_value always works")
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn to_member_event(&self) -> Raw<StateEvent<MemberEventContent>> {
|
||||
let json = json!({
|
||||
"content": self.content,
|
||||
|
@ -200,6 +213,7 @@ impl PduEvent {
|
|||
}
|
||||
|
||||
/// This does not return a full `Pdu` it is only to satisfy ruma's types.
|
||||
#[tracing::instrument]
|
||||
pub fn convert_to_outgoing_federation_event(
|
||||
mut pdu_json: CanonicalJsonObject,
|
||||
) -> Raw<ruma::events::pdu::Pdu> {
|
||||
|
@ -228,7 +242,7 @@ impl PduEvent {
|
|||
) -> Result<Self, serde_json::Error> {
|
||||
json.insert(
|
||||
"event_id".to_string(),
|
||||
ruma::serde::to_canonical_value(event_id).expect("event_id is a valid Value"),
|
||||
to_canonical_value(event_id).expect("event_id is a valid Value"),
|
||||
);
|
||||
|
||||
serde_json::from_value(serde_json::to_value(json).expect("valid JSON"))
|
||||
|
|
|
@ -79,9 +79,7 @@ where
|
|||
registration
|
||||
.get("as_token")
|
||||
.and_then(|as_token| as_token.as_str())
|
||||
.map_or(false, |as_token| {
|
||||
dbg!(token.as_deref()) == dbg!(Some(as_token))
|
||||
})
|
||||
.map_or(false, |as_token| token.as_deref() == Some(as_token))
|
||||
}) {
|
||||
match T::METADATA.authentication {
|
||||
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::{client_server, utils, ConduitResult, Database, Error, PduEvent, Resu
|
|||
use get_profile_information::v1::ProfileField;
|
||||
use http::header::{HeaderValue, AUTHORIZATION, HOST};
|
||||
use log::{error, info, warn};
|
||||
use regex::Regex;
|
||||
use rocket::{get, post, put, response::content::Json, State};
|
||||
use ruma::{
|
||||
api::{
|
||||
|
@ -18,6 +19,7 @@ use ruma::{
|
|||
OutgoingRequest,
|
||||
},
|
||||
directory::{IncomingFilter, IncomingRoomNetwork},
|
||||
events::EventType,
|
||||
serde::to_canonical_value,
|
||||
signatures::{CanonicalJsonObject, CanonicalJsonValue, PublicKeyMap},
|
||||
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
|
||||
|
@ -35,6 +37,7 @@ use std::{
|
|||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
#[tracing::instrument(skip(globals))]
|
||||
pub async fn send_request<T: OutgoingRequest>(
|
||||
globals: &crate::database::globals::Globals,
|
||||
destination: &ServerName,
|
||||
|
@ -201,6 +204,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
fn get_ip_with_port(destination_str: String) -> Option<String> {
|
||||
if destination_str.parse::<SocketAddr>().is_ok() {
|
||||
Some(destination_str)
|
||||
|
@ -211,6 +215,7 @@ fn get_ip_with_port(destination_str: String) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
fn add_port_to_hostname(destination_str: String) -> String {
|
||||
match destination_str.find(':') {
|
||||
None => destination_str.to_owned() + ":8448",
|
||||
|
@ -221,9 +226,10 @@ fn add_port_to_hostname(destination_str: String) -> String {
|
|||
/// Returns: actual_destination, host header
|
||||
/// Implemented according to the specification at https://matrix.org/docs/spec/server_server/r0.1.4#resolving-server-names
|
||||
/// Numbers in comments below refer to bullet points in linked section of specification
|
||||
#[tracing::instrument(skip(globals))]
|
||||
async fn find_actual_destination(
|
||||
globals: &crate::database::globals::Globals,
|
||||
destination: &ServerName,
|
||||
destination: &'_ ServerName,
|
||||
) -> (String, Option<String>) {
|
||||
let mut host = None;
|
||||
|
||||
|
@ -279,9 +285,10 @@ async fn find_actual_destination(
|
|||
(actual_destination, host)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(globals))]
|
||||
async fn query_srv_record(
|
||||
globals: &crate::database::globals::Globals,
|
||||
hostname: &str,
|
||||
hostname: &'_ str,
|
||||
) -> Option<String> {
|
||||
if let Ok(Some(host_port)) = globals
|
||||
.dns_resolver()
|
||||
|
@ -303,6 +310,7 @@ async fn query_srv_record(
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(globals))]
|
||||
pub async fn request_well_known(
|
||||
globals: &crate::database::globals::Globals,
|
||||
destination: &str,
|
||||
|
@ -326,6 +334,7 @@ pub async fn request_well_known(
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/federation/v1/version"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_version_route(
|
||||
db: State<'_, Database>,
|
||||
) -> ConduitResult<get_server_version::Response> {
|
||||
|
@ -343,6 +352,7 @@ pub fn get_server_version_route(
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/key/v2/server"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_keys_route(db: State<'_, Database>) -> Json<String> {
|
||||
if !db.globals.allow_federation() {
|
||||
// TODO: Use proper types
|
||||
|
@ -385,6 +395,7 @@ pub fn get_server_keys_route(db: State<'_, Database>) -> Json<String> {
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/key/v2/server/<_>"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_keys_deprecated_route(db: State<'_, Database>) -> Json<String> {
|
||||
get_server_keys_route(db)
|
||||
}
|
||||
|
@ -393,6 +404,7 @@ pub fn get_server_keys_deprecated_route(db: State<'_, Database>) -> Json<String>
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/federation/v1/publicRooms", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_public_rooms_filtered::v1::Request<'_>>,
|
||||
|
@ -440,6 +452,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/federation/v1/publicRooms", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_public_rooms::v1::Request<'_>>,
|
||||
|
@ -487,6 +500,7 @@ pub async fn get_public_rooms_route(
|
|||
feature = "conduit_bin",
|
||||
put("/_matrix/federation/v1/send/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_transaction_message_route<'a>(
|
||||
db: State<'a, Database>,
|
||||
body: Ruma<send_transaction_message::v1::Request<'_>>,
|
||||
|
@ -1428,7 +1442,67 @@ pub(crate) fn append_incoming_pdu(
|
|||
db.rooms.set_room_state(pdu.room_id(), &state_hash)?;
|
||||
|
||||
for appservice in db.appservice.iter_all().filter_map(|r| r.ok()) {
|
||||
db.sending.send_pdu_appservice(&appservice.0, &pdu_id)?;
|
||||
if let Some(namespaces) = appservice.1.get("namespaces") {
|
||||
let users = namespaces
|
||||
.get("users")
|
||||
.and_then(|users| users.as_sequence())
|
||||
.map_or_else(Vec::new, |users| {
|
||||
users
|
||||
.iter()
|
||||
.map(|users| {
|
||||
users
|
||||
.get("regex")
|
||||
.and_then(|regex| regex.as_str())
|
||||
.and_then(|regex| Regex::new(regex).ok())
|
||||
})
|
||||
.filter_map(|o| o)
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
let aliases = namespaces
|
||||
.get("aliases")
|
||||
.and_then(|users| users.get("regex"))
|
||||
.and_then(|regex| regex.as_str())
|
||||
.and_then(|regex| Regex::new(regex).ok());
|
||||
let rooms = namespaces
|
||||
.get("rooms")
|
||||
.and_then(|rooms| rooms.as_sequence());
|
||||
|
||||
let room_aliases = db.rooms.room_aliases(&pdu.room_id);
|
||||
|
||||
let bridge_user_id = appservice
|
||||
.1
|
||||
.get("sender_localpart")
|
||||
.and_then(|string| string.as_str())
|
||||
.and_then(|string| {
|
||||
UserId::parse_with_server_name(string, db.globals.server_name()).ok()
|
||||
});
|
||||
|
||||
#[allow(clippy::blocks_in_if_conditions)]
|
||||
if bridge_user_id.map_or(false, |bridge_user_id| {
|
||||
db.rooms
|
||||
.is_joined(&bridge_user_id, &pdu.room_id)
|
||||
.unwrap_or(false)
|
||||
}) || users.iter().any(|users| {
|
||||
users.is_match(pdu.sender.as_str())
|
||||
|| pdu.kind == EventType::RoomMember
|
||||
&& pdu
|
||||
.state_key
|
||||
.as_ref()
|
||||
.map_or(false, |state_key| users.is_match(&state_key))
|
||||
}) || aliases.map_or(false, |aliases| {
|
||||
room_aliases
|
||||
.filter_map(|r| r.ok())
|
||||
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
||||
}) || rooms.map_or(false, |rooms| rooms.contains(&pdu.room_id.as_str().into()))
|
||||
|| db
|
||||
.rooms
|
||||
.room_members(&pdu.room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.any(|member| users.iter().any(|regex| regex.is_match(member.as_str())))
|
||||
{
|
||||
db.sending.send_pdu_appservice(&appservice.0, &pdu_id)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1438,6 +1512,7 @@ pub(crate) fn append_incoming_pdu(
|
|||
feature = "conduit_bin",
|
||||
post("/_matrix/federation/v1/get_missing_events/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_missing_events_route<'a>(
|
||||
db: State<'a, Database>,
|
||||
body: Ruma<get_missing_events::v1::Request<'_>>,
|
||||
|
@ -1483,6 +1558,7 @@ pub fn get_missing_events_route<'a>(
|
|||
feature = "conduit_bin",
|
||||
get("/_matrix/federation/v1/query/profile", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_profile_information_route<'a>(
|
||||
db: State<'a, Database>,
|
||||
body: Ruma<get_profile_information::v1::Request<'_>>,
|
||||
|
|
|
@ -55,6 +55,7 @@ pub fn random_string(length: usize) -> String {
|
|||
thread_rng()
|
||||
.sample_iter(&rand::distributions::Alphanumeric)
|
||||
.take(length)
|
||||
.map(char::from)
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue