remove eldrich being and install good being
This commit is contained in:
parent
9df86c2c1e
commit
14e6afc45e
34 changed files with 371 additions and 315 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -59,6 +59,7 @@ $RECYCLE.BIN/
|
|||
# Conduit
|
||||
Rocket.toml
|
||||
conduit.toml
|
||||
conduit.db
|
||||
|
||||
# Etc.
|
||||
**/*.rs.bk
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{collections::BTreeMap, convert::TryInto, sync::Arc};
|
||||
|
||||
use super::{State, DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
|
@ -42,7 +42,7 @@ const GUEST_NAME_LENGTH: usize = 10;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_register_available_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_username_availability::Request<'_>>,
|
||||
) -> ConduitResult<get_username_availability::Response> {
|
||||
// Validate user id
|
||||
|
@ -85,7 +85,7 @@ pub async fn get_register_available_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn register_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<register::Request<'_>>,
|
||||
) -> ConduitResult<register::Response> {
|
||||
if !db.globals.allow_registration() && !body.from_appservice {
|
||||
|
@ -496,7 +496,7 @@ pub async fn register_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn change_password_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<change_password::Request<'_>>,
|
||||
) -> ConduitResult<change_password::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -588,7 +588,7 @@ pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn deactivate_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<deactivate::Request<'_>>,
|
||||
) -> ConduitResult<deactivate::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use regex::Regex;
|
||||
use ruma::{
|
||||
api::{
|
||||
|
@ -24,7 +24,7 @@ use rocket::{delete, get, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_alias_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_alias::Request<'_>>,
|
||||
) -> ConduitResult<create_alias::Response> {
|
||||
if db.rooms.id_from_alias(&body.room_alias)?.is_some() {
|
||||
|
@ -45,7 +45,7 @@ pub async fn create_alias_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_alias_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_alias::Request<'_>>,
|
||||
) -> ConduitResult<delete_alias::Response> {
|
||||
db.rooms.set_alias(&body.room_alias, None, &db.globals)?;
|
||||
|
@ -61,7 +61,7 @@ pub async fn delete_alias_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_alias_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_alias::Request<'_>>,
|
||||
) -> ConduitResult<get_alias::Response> {
|
||||
get_alias_helper(&db, &body.room_alias).await
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::backup::{
|
||||
|
@ -21,7 +21,7 @@ use rocket::{delete, get, post, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_backup_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_backup::Request>,
|
||||
) -> ConduitResult<create_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -40,7 +40,7 @@ pub async fn create_backup_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_backup_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<update_backup::Request<'_>>,
|
||||
) -> ConduitResult<update_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -58,7 +58,7 @@ pub async fn update_backup_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_latest_backup_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_latest_backup::Request>,
|
||||
) -> ConduitResult<get_latest_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -86,7 +86,7 @@ pub async fn get_latest_backup_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_backup::Request<'_>>,
|
||||
) -> ConduitResult<get_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -113,7 +113,7 @@ pub async fn get_backup_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_backup::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -132,7 +132,7 @@ pub async fn delete_backup_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<add_backup_keys::Request<'_>>,
|
||||
) -> ConduitResult<add_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -166,7 +166,7 @@ pub async fn add_backup_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_key_sessions_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<add_backup_key_sessions::Request<'_>>,
|
||||
) -> ConduitResult<add_backup_key_sessions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -198,7 +198,7 @@ pub async fn add_backup_key_sessions_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_key_session_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<add_backup_key_session::Request<'_>>,
|
||||
) -> ConduitResult<add_backup_key_session::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -227,7 +227,7 @@ pub async fn add_backup_key_session_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_backup_keys::Request<'_>>,
|
||||
) -> ConduitResult<get_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -243,7 +243,7 @@ pub async fn get_backup_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_key_sessions_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_backup_key_sessions::Request<'_>>,
|
||||
) -> ConduitResult<get_backup_key_sessions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -261,7 +261,7 @@ pub async fn get_backup_key_sessions_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_key_session_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_backup_key_session::Request<'_>>,
|
||||
) -> ConduitResult<get_backup_key_session::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -283,7 +283,7 @@ pub async fn get_backup_key_session_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_backup_keys::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -306,7 +306,7 @@ pub async fn delete_backup_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_key_sessions_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_backup_key_sessions::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup_key_sessions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -329,7 +329,7 @@ pub async fn delete_backup_key_sessions_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_key_session_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_backup_key_session::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup_key_session::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -25,7 +25,7 @@ use rocket::{get, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_global_account_data_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_global_account_data::Request<'_>>,
|
||||
) -> ConduitResult<set_global_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -60,7 +60,7 @@ pub async fn set_global_account_data_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_room_account_data_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_room_account_data::Request<'_>>,
|
||||
) -> ConduitResult<set_room_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -92,7 +92,7 @@ pub async fn set_room_account_data_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_global_account_data_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_global_account_data::Request<'_>>,
|
||||
) -> ConduitResult<get_global_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -119,7 +119,7 @@ pub async fn get_global_account_data_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_account_data_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_room_account_data::Request<'_>>,
|
||||
) -> ConduitResult<get_room_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{error::ErrorKind, r0::context::get_context};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
|
||||
|
@ -12,7 +12,7 @@ use rocket::get;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_context_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_context::Request<'_>>,
|
||||
) -> ConduitResult<get_context::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::{
|
||||
|
@ -20,7 +20,7 @@ use rocket::{delete, get, post, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_devices_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_devices::Request>,
|
||||
) -> ConduitResult<get_devices::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -40,7 +40,7 @@ pub async fn get_devices_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_device_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_device::Request<'_>>,
|
||||
) -> ConduitResult<get_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -59,7 +59,7 @@ pub async fn get_device_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_device_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<update_device::Request<'_>>,
|
||||
) -> ConduitResult<update_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -85,7 +85,7 @@ pub async fn update_device_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_device_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_device::Request<'_>>,
|
||||
) -> ConduitResult<delete_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -139,7 +139,7 @@ pub async fn delete_device_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_devices_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_devices::Request<'_>>,
|
||||
) -> ConduitResult<delete_devices::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Result, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Result, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::{
|
||||
|
@ -35,7 +35,7 @@ use rocket::{get, post, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_public_rooms_filtered::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms_filtered::Response> {
|
||||
get_public_rooms_filtered_helper(
|
||||
|
@ -55,7 +55,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_public_rooms::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms::Response> {
|
||||
let response = get_public_rooms_filtered_helper(
|
||||
|
@ -84,7 +84,7 @@ pub async fn get_public_rooms_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_room_visibility_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_room_visibility::Request<'_>>,
|
||||
) -> ConduitResult<set_room_visibility::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -114,7 +114,7 @@ pub async fn set_room_visibility_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_visibility_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_room_visibility::Request<'_>>,
|
||||
) -> ConduitResult<get_room_visibility::Response> {
|
||||
Ok(get_room_visibility::Response {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::{State, SESSION_ID_LENGTH};
|
||||
use crate::{utils, ConduitResult, Database, Error, Result, Ruma};
|
||||
use crate::{database::ReadGuard, utils, ConduitResult, Database, Error, Result, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -28,7 +28,7 @@ use rocket::{get, post};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<upload_keys::Request>,
|
||||
) -> ConduitResult<upload_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -77,7 +77,7 @@ pub async fn upload_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_keys::Request<'_>>,
|
||||
) -> ConduitResult<get_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -98,7 +98,7 @@ pub async fn get_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn claim_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<claim_keys::Request>,
|
||||
) -> ConduitResult<claim_keys::Response> {
|
||||
let response = claim_keys_helper(&body.one_time_keys, &db)?;
|
||||
|
@ -114,7 +114,7 @@ pub async fn claim_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_signing_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<upload_signing_keys::Request<'_>>,
|
||||
) -> ConduitResult<upload_signing_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -177,7 +177,7 @@ pub async fn upload_signing_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_signatures_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<upload_signatures::Request>,
|
||||
) -> ConduitResult<upload_signatures::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -238,7 +238,7 @@ pub async fn upload_signatures_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_key_changes_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_key_changes::Request<'_>>,
|
||||
) -> ConduitResult<get_key_changes::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use super::State;
|
||||
use crate::{database::media::FileMeta, utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{
|
||||
database::media::FileMeta, database::ReadGuard, utils, ConduitResult, Database, Error, Ruma,
|
||||
};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::media::{create_content, get_content, get_content_thumbnail, get_media_config},
|
||||
|
@ -13,9 +15,7 @@ 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<'_, Arc<Database>>,
|
||||
) -> ConduitResult<get_media_config::Response> {
|
||||
pub async fn get_media_config_route(db: ReadGuard) -> ConduitResult<get_media_config::Response> {
|
||||
Ok(get_media_config::Response {
|
||||
upload_size: db.globals.max_request_size().into(),
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ pub async fn get_media_config_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_content_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_content::Request<'_>>,
|
||||
) -> ConduitResult<create_content::Response> {
|
||||
let mxc = format!(
|
||||
|
@ -66,7 +66,7 @@ pub async fn create_content_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_content_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_content::Request<'_>>,
|
||||
) -> ConduitResult<get_content::Response> {
|
||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||
|
@ -119,7 +119,7 @@ pub async fn get_content_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_content_thumbnail_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_content_thumbnail::Request<'_>>,
|
||||
) -> ConduitResult<get_content_thumbnail::Response> {
|
||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use super::State;
|
||||
use crate::{
|
||||
client_server,
|
||||
database::ReadGuard,
|
||||
pdu::{PduBuilder, PduEvent},
|
||||
server_server, utils, ConduitResult, Database, Error, Result, Ruma,
|
||||
};
|
||||
|
@ -44,7 +45,7 @@ use rocket::{get, post};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn join_room_by_id_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<join_room_by_id::Request<'_>>,
|
||||
) -> ConduitResult<join_room_by_id::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -81,7 +82,7 @@ pub async fn join_room_by_id_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn join_room_by_id_or_alias_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<join_room_by_id_or_alias::Request<'_>>,
|
||||
) -> ConduitResult<join_room_by_id_or_alias::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -135,7 +136,7 @@ pub async fn join_room_by_id_or_alias_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn leave_room_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<leave_room::Request<'_>>,
|
||||
) -> ConduitResult<leave_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -153,7 +154,7 @@ pub async fn leave_room_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn invite_user_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<invite_user::Request<'_>>,
|
||||
) -> ConduitResult<invite_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -173,7 +174,7 @@ pub async fn invite_user_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn kick_user_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<kick_user::Request<'_>>,
|
||||
) -> ConduitResult<kick_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -223,7 +224,7 @@ pub async fn kick_user_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn ban_user_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<ban_user::Request<'_>>,
|
||||
) -> ConduitResult<ban_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -281,7 +282,7 @@ pub async fn ban_user_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn unban_user_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<unban_user::Request<'_>>,
|
||||
) -> ConduitResult<unban_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -330,7 +331,7 @@ pub async fn unban_user_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn forget_room_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<forget_room::Request<'_>>,
|
||||
) -> ConduitResult<forget_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -348,7 +349,7 @@ pub async fn forget_room_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn joined_rooms_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<joined_rooms::Request>,
|
||||
) -> ConduitResult<joined_rooms::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -369,7 +370,7 @@ pub async fn joined_rooms_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_member_events_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_member_events::Request<'_>>,
|
||||
) -> ConduitResult<get_member_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -399,7 +400,7 @@ pub async fn get_member_events_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn joined_members_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<joined_members::Request<'_>>,
|
||||
) -> ConduitResult<joined_members::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -23,7 +23,7 @@ use rocket::{get, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_message_event_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<send_message_event::Request<'_>>,
|
||||
) -> ConduitResult<send_message_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -86,7 +86,7 @@ pub async fn send_message_event_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_message_events_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_message_events::Request<'_>>,
|
||||
) -> ConduitResult<get_message_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Ruma};
|
||||
use crate::{database::ReadGuard, utils, ConduitResult, Database, Ruma};
|
||||
use ruma::api::client::r0::presence::{get_presence, set_presence};
|
||||
use std::{convert::TryInto, sync::Arc, time::Duration};
|
||||
|
||||
|
@ -12,7 +12,7 @@ use rocket::{get, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_presence_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_presence::Request<'_>>,
|
||||
) -> ConduitResult<set_presence::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -53,7 +53,7 @@ pub async fn set_presence_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_presence_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_presence::Request<'_>>,
|
||||
) -> ConduitResult<get_presence::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -21,7 +21,7 @@ use std::{convert::TryInto, sync::Arc};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_displayname_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_display_name::Request<'_>>,
|
||||
) -> ConduitResult<set_display_name::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -108,7 +108,7 @@ pub async fn set_displayname_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_displayname_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_display_name::Request<'_>>,
|
||||
) -> ConduitResult<get_display_name::Response> {
|
||||
Ok(get_display_name::Response {
|
||||
|
@ -123,7 +123,7 @@ pub async fn get_displayname_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_avatar_url_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_avatar_url::Request<'_>>,
|
||||
) -> ConduitResult<set_avatar_url::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -210,7 +210,7 @@ pub async fn set_avatar_url_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_avatar_url_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_avatar_url::Request<'_>>,
|
||||
) -> ConduitResult<get_avatar_url::Response> {
|
||||
Ok(get_avatar_url::Response {
|
||||
|
@ -225,7 +225,7 @@ pub async fn get_avatar_url_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_profile_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_profile::Request<'_>>,
|
||||
) -> ConduitResult<get_profile::Response> {
|
||||
if !db.users.exists(&body.user_id)? {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -24,7 +24,7 @@ use rocket::{delete, get, post, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrules_all_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_pushrules_all::Request>,
|
||||
) -> ConduitResult<get_pushrules_all::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -49,7 +49,7 @@ pub async fn get_pushrules_all_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_pushrule::Request<'_>>,
|
||||
) -> ConduitResult<get_pushrule::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -103,7 +103,7 @@ pub async fn get_pushrule_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, req))]
|
||||
pub async fn set_pushrule_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
req: Ruma<set_pushrule::Request<'_>>,
|
||||
) -> ConduitResult<set_pushrule::Response> {
|
||||
let sender_user = req.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -206,7 +206,7 @@ pub async fn set_pushrule_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_actions_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_pushrule_actions::Request<'_>>,
|
||||
) -> ConduitResult<get_pushrule_actions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -265,7 +265,7 @@ pub async fn get_pushrule_actions_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_actions_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_pushrule_actions::Request<'_>>,
|
||||
) -> ConduitResult<set_pushrule_actions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -339,7 +339,7 @@ pub async fn set_pushrule_actions_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_enabled_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_pushrule_enabled::Request<'_>>,
|
||||
) -> ConduitResult<get_pushrule_enabled::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -400,7 +400,7 @@ pub async fn get_pushrule_enabled_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_enabled_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_pushrule_enabled::Request<'_>>,
|
||||
) -> ConduitResult<set_pushrule_enabled::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -479,7 +479,7 @@ pub async fn set_pushrule_enabled_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_pushrule_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_pushrule::Request<'_>>,
|
||||
) -> ConduitResult<delete_pushrule::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -548,7 +548,7 @@ pub async fn delete_pushrule_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushers_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_pushers::Request>,
|
||||
) -> ConduitResult<get_pushers::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -565,7 +565,7 @@ pub async fn get_pushers_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushers_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_pusher::Request>,
|
||||
) -> ConduitResult<set_pusher::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -20,7 +20,7 @@ use std::{collections::BTreeMap, sync::Arc};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_read_marker_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<set_read_marker::Request<'_>>,
|
||||
) -> ConduitResult<set_read_marker::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -87,7 +87,7 @@ pub async fn set_read_marker_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_receipt_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_receipt::Request<'_>>,
|
||||
) -> ConduitResult<create_receipt::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{pdu::PduBuilder, ConduitResult, Database, Ruma};
|
||||
use crate::{database::ReadGuard, pdu::PduBuilder, ConduitResult, Database, Ruma};
|
||||
use ruma::{
|
||||
api::client::r0::redact::redact_event,
|
||||
events::{room::redaction, EventType},
|
||||
|
@ -15,7 +15,7 @@ use rocket::put;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn redact_event_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<redact_event::Request<'_>>,
|
||||
) -> ConduitResult<redact_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use super::State;
|
||||
use crate::{client_server::invite_helper, pdu::PduBuilder, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{
|
||||
client_server::invite_helper, database::ReadGuard, pdu::PduBuilder, ConduitResult, Database,
|
||||
Error, Ruma,
|
||||
};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
|
@ -24,7 +27,7 @@ use rocket::{get, post};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_room_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_room::Request<'_>>,
|
||||
) -> ConduitResult<create_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -294,7 +297,7 @@ pub async fn create_room_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_event_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_room_event::Request<'_>>,
|
||||
) -> ConduitResult<get_room_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -322,7 +325,7 @@ pub async fn get_room_event_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upgrade_room_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<upgrade_room::Request<'_>>,
|
||||
_room_id: String,
|
||||
) -> ConduitResult<upgrade_room::Response> {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{error::ErrorKind, r0::search::search_events};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -14,7 +14,7 @@ use std::collections::BTreeMap;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn search_events_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<search_events::Request<'_>>,
|
||||
) -> ConduitResult<search_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::{State, DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, utils, ConduitResult, Database, Error, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
|
@ -52,7 +52,7 @@ pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response>
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn login_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<login::Request<'_>>,
|
||||
) -> ConduitResult<login::Response> {
|
||||
// Validate login method
|
||||
|
@ -169,7 +169,7 @@ pub async fn login_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn logout_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<logout::Request>,
|
||||
) -> ConduitResult<logout::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -197,7 +197,7 @@ pub async fn logout_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn logout_all_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<logout_all::Request>,
|
||||
) -> ConduitResult<logout_all::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma};
|
||||
use crate::{database::ReadGuard, pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -27,7 +27,7 @@ use rocket::{get, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_state_event_for_key_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<send_state_event::Request<'_>>,
|
||||
) -> ConduitResult<send_state_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -53,7 +53,7 @@ pub async fn send_state_event_for_key_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_state_event_for_empty_key_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<send_state_event::Request<'_>>,
|
||||
) -> ConduitResult<send_state_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -79,7 +79,7 @@ pub async fn send_state_event_for_empty_key_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_state_events::Request<'_>>,
|
||||
) -> ConduitResult<get_state_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -126,7 +126,7 @@ pub async fn get_state_events_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_for_key_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -177,7 +177,7 @@ pub async fn get_state_events_for_key_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_for_empty_key_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Result, Ruma, RumaResponse};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Result, Ruma, RumaResponse};
|
||||
use log::error;
|
||||
use ruma::{
|
||||
api::client::r0::{sync::sync_events, uiaa::UiaaResponse},
|
||||
|
@ -35,13 +35,15 @@ use rocket::{get, tokio};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn sync_events_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<sync_events::Request<'_>>,
|
||||
) -> std::result::Result<RumaResponse<sync_events::Response>, RumaResponse<UiaaResponse>> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
|
||||
let mut rx = match db
|
||||
let arc_db = Arc::new(db);
|
||||
|
||||
let mut rx = match arc_db
|
||||
.globals
|
||||
.sync_receivers
|
||||
.write()
|
||||
|
@ -52,7 +54,7 @@ pub async fn sync_events_route(
|
|||
let (tx, rx) = tokio::sync::watch::channel(None);
|
||||
|
||||
tokio::spawn(sync_helper_wrapper(
|
||||
Arc::clone(&db),
|
||||
Arc::clone(&arc_db),
|
||||
sender_user.clone(),
|
||||
sender_device.clone(),
|
||||
body.since.clone(),
|
||||
|
@ -68,7 +70,7 @@ pub async fn sync_events_route(
|
|||
let (tx, rx) = tokio::sync::watch::channel(None);
|
||||
|
||||
tokio::spawn(sync_helper_wrapper(
|
||||
Arc::clone(&db),
|
||||
Arc::clone(&arc_db),
|
||||
sender_user.clone(),
|
||||
sender_device.clone(),
|
||||
body.since.clone(),
|
||||
|
@ -104,7 +106,7 @@ pub async fn sync_events_route(
|
|||
}
|
||||
|
||||
pub async fn sync_helper_wrapper(
|
||||
db: Arc<Database>,
|
||||
db: Arc<ReadGuard>,
|
||||
sender_user: UserId,
|
||||
sender_device: Box<DeviceId>,
|
||||
since: Option<String>,
|
||||
|
@ -146,7 +148,7 @@ pub async fn sync_helper_wrapper(
|
|||
}
|
||||
|
||||
async fn sync_helper(
|
||||
db: Arc<Database>,
|
||||
db: Arc<ReadGuard>,
|
||||
sender_user: UserId,
|
||||
sender_device: Box<DeviceId>,
|
||||
since: Option<String>,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::State;
|
||||
use crate::{ConduitResult, Database, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Ruma};
|
||||
use ruma::{
|
||||
api::client::r0::tag::{create_tag, delete_tag, get_tags},
|
||||
events::EventType,
|
||||
|
@ -15,7 +15,7 @@ use rocket::{delete, get, put};
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_tag_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_tag::Request<'_>>,
|
||||
) -> ConduitResult<create_tag::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -52,7 +52,7 @@ pub async fn update_tag_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_tag_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<delete_tag::Request<'_>>,
|
||||
) -> ConduitResult<delete_tag::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
@ -86,7 +86,7 @@ pub async fn delete_tag_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_tags_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_tags::Request<'_>>,
|
||||
) -> ConduitResult<get_tags::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{error::ErrorKind, r0::to_device::send_event_to_device},
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
|
@ -16,7 +16,7 @@ use rocket::put;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_event_to_device_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<send_event_to_device::Request<'_>>,
|
||||
) -> ConduitResult<send_event_to_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Ruma};
|
||||
use crate::{database::ReadGuard, utils, ConduitResult, Database, Ruma};
|
||||
use create_typing_event::Typing;
|
||||
use ruma::api::client::r0::typing::create_typing_event;
|
||||
|
||||
|
@ -14,7 +14,7 @@ use rocket::put;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn create_typing_event_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_typing_event::Request<'_>>,
|
||||
) -> ConduitResult<create_typing_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Ruma};
|
||||
use crate::{database::ReadGuard, ConduitResult, Database, Ruma};
|
||||
use ruma::api::client::r0::user_directory::search_users;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
|
@ -13,7 +13,7 @@ use rocket::post;
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn search_users_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<search_users::Request<'_>>,
|
||||
) -> ConduitResult<search_users::Response> {
|
||||
let limit = u64::from(body.limit) as usize;
|
||||
|
|
|
@ -19,16 +19,22 @@ use abstraction::DatabaseEngine;
|
|||
use directories::ProjectDirs;
|
||||
use log::error;
|
||||
use lru_cache::LruCache;
|
||||
use rocket::futures::{channel::mpsc, stream::FuturesUnordered, StreamExt};
|
||||
use rocket::{
|
||||
futures::{channel::mpsc, stream::FuturesUnordered, StreamExt},
|
||||
outcome::IntoOutcome,
|
||||
request::{FromRequest, Request},
|
||||
try_outcome, State,
|
||||
};
|
||||
use ruma::{DeviceId, ServerName, UserId};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::{self, remove_dir_all},
|
||||
io::Write,
|
||||
ops::Deref,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use tokio::sync::Semaphore;
|
||||
use tokio::sync::{OwnedRwLockReadGuard, RwLock as TokioRwLock, RwLockReadGuard, Semaphore};
|
||||
|
||||
use self::proxy::ProxyConfig;
|
||||
|
||||
|
@ -122,7 +128,7 @@ impl Database {
|
|||
}
|
||||
|
||||
/// Load an existing database or create a new one.
|
||||
pub async fn load_or_create(config: Config) -> Result<Arc<Self>> {
|
||||
pub async fn load_or_create(config: Config) -> Result<Arc<TokioRwLock<Self>>> {
|
||||
let builder = Engine::open(&config)?;
|
||||
|
||||
if config.max_request_size < 1024 {
|
||||
|
@ -132,7 +138,7 @@ impl Database {
|
|||
let (admin_sender, admin_receiver) = mpsc::unbounded();
|
||||
let (sending_sender, sending_receiver) = mpsc::unbounded();
|
||||
|
||||
let db = Arc::new(Self {
|
||||
let db = Arc::new(TokioRwLock::from(Self {
|
||||
_db: builder.clone(),
|
||||
users: users::Users {
|
||||
userid_password: builder.open_tree("userid_password")?,
|
||||
|
@ -238,8 +244,10 @@ impl Database {
|
|||
builder.open_tree("server_signingkeys")?,
|
||||
config,
|
||||
)?,
|
||||
});
|
||||
}));
|
||||
|
||||
{
|
||||
let db = db.read().await;
|
||||
// MIGRATIONS
|
||||
// TODO: database versions of new dbs should probably not be 0
|
||||
if db.globals.database_version()? < 1 {
|
||||
|
@ -324,12 +332,17 @@ impl Database {
|
|||
|
||||
println!("Migration: 3 -> 4 finished");
|
||||
}
|
||||
}
|
||||
|
||||
let guard = db.read().await;
|
||||
|
||||
// This data is probably outdated
|
||||
db.rooms.edus.presenceid_presence.clear()?;
|
||||
guard.rooms.edus.presenceid_presence.clear()?;
|
||||
|
||||
db.admin.start_handler(Arc::clone(&db), admin_receiver);
|
||||
db.sending.start_handler(Arc::clone(&db), sending_receiver);
|
||||
guard.admin.start_handler(Arc::clone(&db), admin_receiver);
|
||||
guard.sending.start_handler(Arc::clone(&db), sending_receiver);
|
||||
|
||||
drop(guard);
|
||||
|
||||
Ok(db)
|
||||
}
|
||||
|
@ -431,4 +444,30 @@ impl Database {
|
|||
|
||||
res
|
||||
}
|
||||
|
||||
pub fn flush_wal(&self) -> Result<()> {
|
||||
self._db.flush_wal()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReadGuard(OwnedRwLockReadGuard<Database>);
|
||||
|
||||
impl Deref for ReadGuard {
|
||||
type Target = OwnedRwLockReadGuard<Database>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
#[rocket::async_trait]
|
||||
impl<'r> FromRequest<'r> for ReadGuard {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(req: &'r Request<'_>) -> rocket::request::Outcome<Self, ()> {
|
||||
let db = try_outcome!(req.guard::<State<'_, Arc<TokioRwLock<Database>>>>().await);
|
||||
|
||||
Ok(ReadGuard(Arc::clone(&db).read_owned().await)).or_forward(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
ops::Deref,
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
sync::{Arc, Weak},
|
||||
sync::Arc,
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
@ -36,7 +36,6 @@ use tokio::sync::oneshot::Sender;
|
|||
struct Pool {
|
||||
writer: Mutex<Connection>,
|
||||
readers: Vec<Mutex<Connection>>,
|
||||
reader_rwlock: RwLock<()>,
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
|
@ -71,7 +70,6 @@ impl Pool {
|
|||
Ok(Self {
|
||||
writer,
|
||||
readers,
|
||||
reader_rwlock: RwLock::new(()),
|
||||
path: path.as_ref().to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
@ -95,16 +93,12 @@ impl Pool {
|
|||
}
|
||||
|
||||
fn read_lock(&self) -> HoldingConn<'_> {
|
||||
let _guard = self.reader_rwlock.read();
|
||||
|
||||
for r in &self.readers {
|
||||
if let Some(reader) = r.try_lock() {
|
||||
return HoldingConn::FromGuard(reader);
|
||||
}
|
||||
}
|
||||
|
||||
drop(_guard);
|
||||
|
||||
log::warn!("all readers locked, creating spillover reader...");
|
||||
|
||||
let spilled = Self::prepare_conn(&self.path).unwrap();
|
||||
|
@ -115,7 +109,6 @@ impl Pool {
|
|||
|
||||
pub struct SqliteEngine {
|
||||
pool: Pool,
|
||||
iterator_lock: RwLock<()>,
|
||||
}
|
||||
|
||||
impl DatabaseEngine for SqliteEngine {
|
||||
|
@ -128,36 +121,7 @@ impl DatabaseEngine for SqliteEngine {
|
|||
pool.write_lock()
|
||||
.execute("CREATE TABLE IF NOT EXISTS _noop (\"key\" INT)", params![])?;
|
||||
|
||||
let arc = Arc::new(SqliteEngine {
|
||||
pool,
|
||||
iterator_lock: RwLock::new(()),
|
||||
});
|
||||
|
||||
let weak: Weak<SqliteEngine> = Arc::downgrade(&arc);
|
||||
|
||||
thread::spawn(move || {
|
||||
let r = crossbeam::channel::tick(Duration::from_secs(60));
|
||||
|
||||
let weak = weak;
|
||||
|
||||
loop {
|
||||
let _ = r.recv();
|
||||
|
||||
if let Some(arc) = Weak::upgrade(&weak) {
|
||||
log::warn!("wal-trunc: locking...");
|
||||
let iterator_guard = arc.iterator_lock.write();
|
||||
let read_guard = arc.pool.reader_rwlock.write();
|
||||
log::warn!("wal-trunc: locked, flushing...");
|
||||
let start = Instant::now();
|
||||
arc.flush_wal().unwrap();
|
||||
log::warn!("wal-trunc: locked, flushed in {:?}", start.elapsed());
|
||||
drop(read_guard);
|
||||
drop(iterator_guard);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
let arc = Arc::new(SqliteEngine { pool });
|
||||
|
||||
Ok(arc)
|
||||
}
|
||||
|
@ -190,7 +154,7 @@ impl DatabaseEngine for SqliteEngine {
|
|||
}
|
||||
|
||||
impl SqliteEngine {
|
||||
fn flush_wal(self: &Arc<Self>) -> Result<()> {
|
||||
pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
|
||||
self.pool
|
||||
.write_lock()
|
||||
.execute_batch(
|
||||
|
@ -244,9 +208,7 @@ impl SqliteTable {
|
|||
let engine = self.engine.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
let guard = engine.iterator_lock.read();
|
||||
let _ = f(&engine.pool.read_lock(), s);
|
||||
drop(guard);
|
||||
});
|
||||
|
||||
Box::new(r.into_iter())
|
||||
|
|
|
@ -10,6 +10,7 @@ use ruma::{
|
|||
events::{room::message, EventType},
|
||||
UserId,
|
||||
};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub enum AdminCommand {
|
||||
RegisterAppservice(serde_yaml::Value),
|
||||
|
@ -25,20 +26,22 @@ pub struct Admin {
|
|||
impl Admin {
|
||||
pub fn start_handler(
|
||||
&self,
|
||||
db: Arc<Database>,
|
||||
db: Arc<RwLock<Database>>,
|
||||
mut receiver: mpsc::UnboundedReceiver<AdminCommand>,
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
// TODO: Use futures when we have long admin commands
|
||||
//let mut futures = FuturesUnordered::new();
|
||||
|
||||
let conduit_user = UserId::try_from(format!("@conduit:{}", db.globals.server_name()))
|
||||
let guard = db.read().await;
|
||||
|
||||
let conduit_user = UserId::try_from(format!("@conduit:{}", guard.globals.server_name()))
|
||||
.expect("@conduit:server_name is valid");
|
||||
|
||||
let conduit_room = db
|
||||
let conduit_room = guard
|
||||
.rooms
|
||||
.id_from_alias(
|
||||
&format!("#admins:{}", db.globals.server_name())
|
||||
&format!("#admins:{}", guard.globals.server_name())
|
||||
.try_into()
|
||||
.expect("#admins:server_name is a valid room alias"),
|
||||
)
|
||||
|
@ -48,24 +51,10 @@ impl Admin {
|
|||
warn!("Conduit instance does not have an #admins room. Logging to that room will not work. Restart Conduit after creating a user to fix this.");
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
let send_message = |message: message::MessageEventContent| {
|
||||
if let Some(conduit_room) = &conduit_room {
|
||||
db.rooms
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMessage,
|
||||
content: serde_json::to_value(message)
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: None,
|
||||
redacts: None,
|
||||
},
|
||||
&conduit_user,
|
||||
&conduit_room,
|
||||
&db,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
loop {
|
||||
|
@ -73,10 +62,10 @@ impl Admin {
|
|||
Some(event) = receiver.next() => {
|
||||
match event {
|
||||
AdminCommand::RegisterAppservice(yaml) => {
|
||||
db.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||
db.read().await.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||
}
|
||||
AdminCommand::ListAppservices => {
|
||||
if let Ok(appservices) = db.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
||||
if let Ok(appservices) = db.read().await.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
||||
let count = appservices.len();
|
||||
let output = format!(
|
||||
"Appservices ({}): {}",
|
||||
|
@ -89,7 +78,24 @@ impl Admin {
|
|||
}
|
||||
}
|
||||
AdminCommand::SendMessage(message) => {
|
||||
send_message(message);
|
||||
if let Some(conduit_room) = &conduit_room {
|
||||
let guard = db.read().await;
|
||||
guard.rooms
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMessage,
|
||||
content: serde_json::to_value(message)
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: None,
|
||||
redacts: None,
|
||||
},
|
||||
&conduit_user,
|
||||
&conduit_room,
|
||||
&guard,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ use ruma::{
|
|||
receipt::ReceiptType,
|
||||
MilliSecondsSinceUnixEpoch, ServerName, UInt, UserId,
|
||||
};
|
||||
use tokio::{select, sync::Semaphore};
|
||||
use tokio::{select, sync::{Semaphore, RwLock}};
|
||||
|
||||
use super::abstraction::Tree;
|
||||
|
||||
|
@ -90,7 +90,7 @@ enum TransactionStatus {
|
|||
}
|
||||
|
||||
impl Sending {
|
||||
pub fn start_handler(&self, db: Arc<Database>, mut receiver: mpsc::UnboundedReceiver<Vec<u8>>) {
|
||||
pub fn start_handler(&self, db: Arc<RwLock<Database>>, mut receiver: mpsc::UnboundedReceiver<Vec<u8>>) {
|
||||
tokio::spawn(async move {
|
||||
let mut futures = FuturesUnordered::new();
|
||||
|
||||
|
@ -98,8 +98,11 @@ impl Sending {
|
|||
|
||||
// Retry requests we could not finish yet
|
||||
let mut initial_transactions = HashMap::<OutgoingKind, Vec<SendingEventType>>::new();
|
||||
|
||||
let guard = db.read().await;
|
||||
|
||||
for (key, outgoing_kind, event) in
|
||||
db.sending
|
||||
guard.sending
|
||||
.servercurrentevents
|
||||
.iter()
|
||||
.filter_map(|(key, _)| {
|
||||
|
@ -117,17 +120,19 @@ impl Sending {
|
|||
"Dropping some current events: {:?} {:?} {:?}",
|
||||
key, outgoing_kind, event
|
||||
);
|
||||
db.sending.servercurrentevents.remove(&key).unwrap();
|
||||
guard.sending.servercurrentevents.remove(&key).unwrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.push(event);
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
for (outgoing_kind, events) in initial_transactions {
|
||||
current_transaction_status
|
||||
.insert(outgoing_kind.get_prefix(), TransactionStatus::Running);
|
||||
futures.push(Self::handle_events(outgoing_kind.clone(), events, &db));
|
||||
futures.push(Self::handle_events(outgoing_kind.clone(), events, Arc::clone(&db)));
|
||||
}
|
||||
|
||||
loop {
|
||||
|
@ -135,15 +140,17 @@ impl Sending {
|
|||
Some(response) = futures.next() => {
|
||||
match response {
|
||||
Ok(outgoing_kind) => {
|
||||
let guard = db.read().await;
|
||||
|
||||
let prefix = outgoing_kind.get_prefix();
|
||||
for (key, _) in db.sending.servercurrentevents
|
||||
for (key, _) in guard.sending.servercurrentevents
|
||||
.scan_prefix(prefix.clone())
|
||||
{
|
||||
db.sending.servercurrentevents.remove(&key).unwrap();
|
||||
guard.sending.servercurrentevents.remove(&key).unwrap();
|
||||
}
|
||||
|
||||
// Find events that have been added since starting the last request
|
||||
let new_events = db.sending.servernamepduids
|
||||
let new_events = guard.sending.servernamepduids
|
||||
.scan_prefix(prefix.clone())
|
||||
.map(|(k, _)| {
|
||||
SendingEventType::Pdu(k[prefix.len()..].to_vec())
|
||||
|
@ -161,17 +168,19 @@ impl Sending {
|
|||
SendingEventType::Pdu(b) |
|
||||
SendingEventType::Edu(b) => {
|
||||
current_key.extend_from_slice(&b);
|
||||
db.sending.servercurrentevents.insert(¤t_key, &[]).unwrap();
|
||||
db.sending.servernamepduids.remove(¤t_key).unwrap();
|
||||
guard.sending.servercurrentevents.insert(¤t_key, &[]).unwrap();
|
||||
guard.sending.servernamepduids.remove(¤t_key).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
futures.push(
|
||||
Self::handle_events(
|
||||
outgoing_kind.clone(),
|
||||
new_events,
|
||||
&db,
|
||||
Arc::clone(&db),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
@ -192,13 +201,15 @@ impl Sending {
|
|||
},
|
||||
Some(key) = receiver.next() => {
|
||||
if let Ok((outgoing_kind, event)) = Self::parse_servercurrentevent(&key) {
|
||||
let guard = db.read().await;
|
||||
|
||||
if let Ok(Some(events)) = Self::select_events(
|
||||
&outgoing_kind,
|
||||
vec![(event, key)],
|
||||
&mut current_transaction_status,
|
||||
&db
|
||||
&guard
|
||||
) {
|
||||
futures.push(Self::handle_events(outgoing_kind, events, &db));
|
||||
futures.push(Self::handle_events(outgoing_kind, events, Arc::clone(&db)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -403,8 +414,10 @@ impl Sending {
|
|||
async fn handle_events(
|
||||
kind: OutgoingKind,
|
||||
events: Vec<SendingEventType>,
|
||||
db: &Database,
|
||||
db: Arc<RwLock<Database>>,
|
||||
) -> std::result::Result<OutgoingKind, (OutgoingKind, Error)> {
|
||||
let db = db.read().await;
|
||||
|
||||
match &kind {
|
||||
OutgoingKind::Appservice(server) => {
|
||||
let mut pdu_jsons = Vec::new();
|
||||
|
@ -543,7 +556,7 @@ impl Sending {
|
|||
&pusher,
|
||||
rules_for_user,
|
||||
&pdu,
|
||||
db,
|
||||
&db,
|
||||
)
|
||||
.await
|
||||
.map(|_response| kind.clone())
|
||||
|
|
|
@ -15,7 +15,8 @@ pub use error::{Error, Result};
|
|||
pub use pdu::PduEvent;
|
||||
pub use rocket::Config;
|
||||
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
||||
use std::ops::Deref;
|
||||
use std::{ops::Deref, sync::Arc};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct State<'r, T: Send + Sync + 'static>(pub &'r T);
|
||||
|
||||
|
|
33
src/main.rs
33
src/main.rs
|
@ -12,7 +12,7 @@ mod pdu;
|
|||
mod ruma_wrapper;
|
||||
mod utils;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::{sync::{Arc, Weak}, time::{Duration, Instant}};
|
||||
|
||||
use database::Config;
|
||||
pub use database::Database;
|
||||
|
@ -30,10 +30,14 @@ use rocket::{
|
|||
},
|
||||
routes, Request,
|
||||
};
|
||||
use tokio::{
|
||||
sync::RwLock,
|
||||
time::{interval, Interval},
|
||||
};
|
||||
use tracing::span;
|
||||
use tracing_subscriber::{prelude::*, Registry};
|
||||
|
||||
fn setup_rocket(config: Figment, data: Arc<Database>) -> rocket::Rocket<rocket::Build> {
|
||||
fn setup_rocket(config: Figment, data: Arc<RwLock<Database>>) -> rocket::Rocket<rocket::Build> {
|
||||
rocket::custom(config)
|
||||
.manage(data)
|
||||
.mount(
|
||||
|
@ -201,6 +205,31 @@ async fn main() {
|
|||
.await
|
||||
.expect("config is valid");
|
||||
|
||||
{
|
||||
let weak: Weak<RwLock<Database>> = Arc::downgrade(&db);
|
||||
|
||||
tokio::spawn(async {
|
||||
let weak = weak;
|
||||
|
||||
let mut i = interval(Duration::from_secs(10));
|
||||
|
||||
loop {
|
||||
i.tick().await;
|
||||
|
||||
if let Some(arc) = Weak::upgrade(&weak) {
|
||||
log::warn!("wal-trunc: locking...");
|
||||
let guard = arc.write().await;
|
||||
log::warn!("wal-trunc: locked, flushing...");
|
||||
let start = Instant::now();
|
||||
guard.flush_wal();
|
||||
log::warn!("wal-trunc: locked, flushed in {:?}", start.elapsed());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if config.allow_jaeger {
|
||||
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||
.with_service_name("conduit")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::Error;
|
||||
use crate::{database::ReadGuard, Error};
|
||||
use ruma::{
|
||||
api::{client::r0::uiaa::UiaaResponse, OutgoingResponse},
|
||||
identifiers::{DeviceId, UserId},
|
||||
|
@ -49,7 +49,7 @@ where
|
|||
async fn from_data(request: &'a Request<'_>, data: Data) -> data::Outcome<Self, Self::Error> {
|
||||
let metadata = T::Incoming::METADATA;
|
||||
let db = request
|
||||
.guard::<State<'_, Arc<Database>>>()
|
||||
.guard::<ReadGuard>()
|
||||
.await
|
||||
.expect("database was loaded");
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{
|
||||
client_server::{self, claim_keys_helper, get_keys_helper},
|
||||
database::ReadGuard,
|
||||
utils, ConduitResult, Database, Error, PduEvent, Result, Ruma,
|
||||
};
|
||||
use get_profile_information::v1::ProfileField;
|
||||
|
@ -431,9 +432,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<'_, Arc<Database>>,
|
||||
) -> ConduitResult<get_server_version::v1::Response> {
|
||||
pub fn get_server_version_route(db: ReadGuard) -> ConduitResult<get_server_version::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
}
|
||||
|
@ -450,7 +449,7 @@ pub fn get_server_version_route(
|
|||
// Response type for this endpoint is Json because we need to calculate a signature for the response
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/key/v2/server"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_keys_route(db: State<'_, Arc<Database>>) -> Json<String> {
|
||||
pub fn get_server_keys_route(db: ReadGuard) -> Json<String> {
|
||||
if !db.globals.allow_federation() {
|
||||
// TODO: Use proper types
|
||||
return Json("Federation is disabled.".to_owned());
|
||||
|
@ -497,7 +496,7 @@ pub fn get_server_keys_route(db: State<'_, Arc<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<'_, Arc<Database>>) -> Json<String> {
|
||||
pub fn get_server_keys_deprecated_route(db: ReadGuard) -> Json<String> {
|
||||
get_server_keys_route(db)
|
||||
}
|
||||
|
||||
|
@ -507,7 +506,7 @@ pub fn get_server_keys_deprecated_route(db: State<'_, Arc<Database>>) -> Json<St
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_public_rooms_filtered::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms_filtered::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -551,7 +550,7 @@ pub async fn get_public_rooms_filtered_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_public_rooms::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -595,7 +594,7 @@ pub async fn get_public_rooms_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_transaction_message_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<send_transaction_message::v1::Request<'_>>,
|
||||
) -> ConduitResult<send_transaction_message::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -1674,7 +1673,7 @@ pub(crate) fn append_incoming_pdu(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_event_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_event::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_event::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -1699,7 +1698,7 @@ pub fn get_event_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_missing_events_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_missing_events::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_missing_events::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -1748,7 +1747,7 @@ pub fn get_missing_events_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_event_authorization_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_event_authorization::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_event_authorization::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -1792,7 +1791,7 @@ pub fn get_event_authorization_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_room_state_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_room_state::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_room_state::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -1855,7 +1854,7 @@ pub fn get_room_state_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_room_state_ids_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_room_state_ids::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_room_state_ids::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -1907,7 +1906,7 @@ pub fn get_room_state_ids_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn create_join_event_template_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_join_event_template::v1::Request<'_>>,
|
||||
) -> ConduitResult<create_join_event_template::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2076,7 +2075,7 @@ pub fn create_join_event_template_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_join_event_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_join_event::v2::Request<'_>>,
|
||||
) -> ConduitResult<create_join_event::v2::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2184,7 +2183,7 @@ pub async fn create_join_event_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_invite_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<create_invite::v2::Request>,
|
||||
) -> ConduitResult<create_invite::v2::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2289,7 +2288,7 @@ pub async fn create_invite_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_devices_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_devices::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_devices::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2329,7 +2328,7 @@ pub fn get_devices_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_room_information_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_room_information::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_room_information::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2357,7 +2356,7 @@ pub fn get_room_information_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_profile_information_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_profile_information::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_profile_information::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2391,7 +2390,7 @@ pub fn get_profile_information_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<get_keys::v1::Request>,
|
||||
) -> ConduitResult<get_keys::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
@ -2419,7 +2418,7 @@ pub fn get_keys_route(
|
|||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn claim_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
db: ReadGuard,
|
||||
body: Ruma<claim_keys::v1::Request>,
|
||||
) -> ConduitResult<claim_keys::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
|
Loading…
Add table
Reference in a new issue