diff --git a/src/api/appservice_server.rs b/src/api/appservice_server.rs index f9807846345fcad245b4dd95f2a26e31b13aa2d6..9d47f8b6670b9367d30db8666e944edc92df5b1c 100644 --- a/src/api/appservice_server.rs +++ b/src/api/appservice_server.rs @@ -21,7 +21,10 @@ pub(crate) async fn send_request<T: OutgoingRequest>( SendAccessToken::IfRequired(hs_token), &[MatrixVersion::V1_0], ) - .unwrap() + .map_err(|e| { + warn!("Failed to find destination {}: {}", destination, e); + Error::BadServerResponse("Invalid destination") + })? .map(|body| body.freeze()); let mut parts = http_request.uri().clone().into_parts(); diff --git a/src/api/client_server/profile.rs b/src/api/client_server/profile.rs index a899122c3d91d666e0708e517070cb3eaab0ef70..bb06dbfc3cd94c3a075a0c207296af81328c3518 100644 --- a/src/api/client_server/profile.rs +++ b/src/api/client_server/profile.rs @@ -84,12 +84,11 @@ pub async fn set_displayname_route( ); let state_lock = mutex_state.lock().await; - let _ = services().rooms.timeline.build_and_append_pdu( - pdu_builder, - sender_user, - &room_id, - &state_lock, - ); + let _ = services() + .rooms + .timeline + .build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock) + .await; } if services().globals.allow_local_presence() { @@ -207,12 +206,11 @@ pub async fn set_avatar_url_route( ); let state_lock = mutex_state.lock().await; - let _ = services().rooms.timeline.build_and_append_pdu( - pdu_builder, - sender_user, - &room_id, - &state_lock, - ); + let _ = services() + .rooms + .timeline + .build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock) + .await; } if services().globals.allow_local_presence() { diff --git a/src/database/mod.rs b/src/database/mod.rs index 08d8e66686596e7209959385be860d12b3eec040..a36e66c39a4ae195c2b813ebcb76ddfd8653d190 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -427,7 +427,14 @@ pub async fn load_or_create(config: Config) -> Result<()> { } // If the database has any data, perform data migrations before starting - let latest_database_version = 13; + let latest_database_version: u64; + + // do not increment the db version if the user is not using sha256_media + if cfg!(feature = "sha256_media") { + latest_database_version = 14; + } else { + latest_database_version = 13; + } if services().users.count()? > 0 { // MIGRATIONS @@ -959,7 +966,7 @@ pub async fn load_or_create(config: Config) -> Result<()> { } } - services().globals.bump_database_version(13)?; + services().globals.bump_database_version(14)?; warn!("Migration: 13 -> 14 finished"); } else { diff --git a/src/main.rs b/src/main.rs index 2ea7e84b1ad79bb0cb955c169fc48aaa68f62e4a..b97903cd98fa94273af49cb8624f0de9c306b7f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ extract::{DefaultBodyLimit, FromRequestParts, MatchedPath}, response::IntoResponse, routing::{get, on, MethodFilter}, - Router, + Json, Router, }; use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle}; use conduit::api::{client_server, server_server}; @@ -38,6 +38,7 @@ }, IncomingRequest, }; +use serde::Deserialize; use tokio::{net::UnixListener, signal, sync::oneshot}; use tower::ServiceBuilder; use tower_http::{ @@ -214,7 +215,7 @@ async fn run_server() -> io::Result<()> { let app: axum::routing::IntoMakeService<Router>; - if cfg!(feature = "zstd_compression") && config.zstd_compression == true { + if cfg!(feature = "zstd_compression") && config.zstd_compression { debug!("zstd body compression is enabled"); app = routes() .layer(middlewares.compression()) @@ -489,6 +490,7 @@ fn routes() -> Router { "/_matrix/client/v3/rooms/:room_id/initialSync", get(initial_sync), ) + //.route("/client/server.json", get(syncv3_client_server_json)) .route("/", get(it_works)) .fallback(not_found) } @@ -543,9 +545,22 @@ async fn initial_sync(_uri: Uri) -> impl IntoResponse { } async fn it_works() -> &'static str { - "Hello from Conduit!" + "hewwo from cowonduit woof!" } +/* +// TODO: add /client/server.json support by querying our client well-known for the true matrix homeserver URL +async fn syncv3_client_server_json(uri: Uri) -> impl IntoResponse { + let server_name = services().globals.server_name().to_string(); + let response = services().globals.default_client().get(&format!("https://{server_name")) + let server = uri.scheme_str().unwrap_or("https").to_owned() + "://" + uri.host().unwrap(); + let version = format!("cowonduit {}", env!("CARGO_PKG_VERSION").to_owned()); + let body = format!("{{\"server\":\"{server}\",\"version\":\"{version}\"}}"); + + Json(body) +} +*/ + trait RouterExt { fn ruma_route<H, T>(self, handler: H) -> Self where diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index cbf854579c55dbfc3e09404499d8eb886c2f0b0d..3b3ddc1a43c36c894bd31bd858704b9337620d46 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -490,7 +490,7 @@ pub fn shutdown(&self) { if self.unix_socket_path().is_some() { match &self.unix_socket_path() { Some(path) => { - std::fs::remove_file(path.to_owned()).unwrap(); + std::fs::remove_file(path).unwrap(); } None => error!( "Unable to remove socket file at {:?} during shutdown.", diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 534dbdf6a2e348c99da559ce8b4ed2a3bf86bb3c..342d00cd27b8f94e284d9d64897596ef9fef31b0 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -149,7 +149,9 @@ pub async fn get_hierarchy( // TODO: Sort children children_ids.reverse(); - let chunk = self.get_room_chunk(sender_user, ¤t_room, children_pdus); + let chunk = self + .get_room_chunk(sender_user, ¤t_room, children_pdus) + .await; if let Ok(chunk) = chunk { if left_to_skip > 0 { left_to_skip -= 1; @@ -303,7 +305,7 @@ pub async fn get_hierarchy( }) } - fn get_room_chunk( + async fn get_room_chunk( &self, sender_user: &UserId, room_id: &RoomId, diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index c9cff180d2048c1411d4e3486953ef5c0b819fd3..3deac75debe99305c26fbca3064609f41811adda 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -859,7 +859,7 @@ struct ExtractMembership { let target = pdu .state_key() - .filter(|v| v.starts_with("@")) + .filter(|v| v.starts_with('@')) .unwrap_or(sender.as_str()); let server_name = services().globals.server_name(); let server_user = format!("@conduit:{}", server_name);