fix: element gets stuck in /initialSync

This commit is contained in:
Timo Kösters 2022-10-11 22:37:14 +02:00
parent d3968c2fd1
commit 2b70d9604a
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 19 additions and 3 deletions

View file

@ -342,6 +342,14 @@ fn routes() -> Router {
.ruma_route(server_server::get_profile_information_route) .ruma_route(server_server::get_profile_information_route)
.ruma_route(server_server::get_keys_route) .ruma_route(server_server::get_keys_route)
.ruma_route(server_server::claim_keys_route) .ruma_route(server_server::claim_keys_route)
.route(
"/_matrix/client/r0/rooms/:room_id/initialSync",
get(initial_sync),
)
.route(
"/_matrix/client/v3/rooms/:room_id/initialSync",
get(initial_sync),
)
.fallback(not_found.into_service()) .fallback(not_found.into_service())
} }
@ -375,7 +383,11 @@ async fn shutdown_signal(handle: ServerHandle) {
} }
async fn not_found(_uri: Uri) -> impl IntoResponse { async fn not_found(_uri: Uri) -> impl IntoResponse {
Error::BadRequest(ErrorKind::NotFound, "Unknown or unimplemented route") Error::BadRequest(ErrorKind::Unrecognized, "Unrecognized request")
}
async fn initial_sync(_uri: Uri) -> impl IntoResponse {
Error::BadRequest(ErrorKind::GuestAccessForbidden, "Guest access not implemented")
} }
trait RouterExt { trait RouterExt {

View file

@ -44,6 +44,7 @@ impl Service {
/// When receiving an event one needs to: /// When receiving an event one needs to:
/// 0. Check the server is in the room /// 0. Check the server is in the room
/// 1. Skip the PDU if we already know about it /// 1. Skip the PDU if we already know about it
/// 1.1. Remove unsigned field
/// 2. Check signatures, otherwise drop /// 2. Check signatures, otherwise drop
/// 3. Check content hash, redact if doesn't match /// 3. Check content hash, redact if doesn't match
/// 4. Fetch any missing auth events doing all checks listed here starting at 1. These are not /// 4. Fetch any missing auth events doing all checks listed here starting at 1. These are not
@ -260,10 +261,13 @@ impl Service {
create_event: &'a PduEvent, create_event: &'a PduEvent,
event_id: &'a EventId, event_id: &'a EventId,
room_id: &'a RoomId, room_id: &'a RoomId,
value: BTreeMap<String, CanonicalJsonValue>, mut value: BTreeMap<String, CanonicalJsonValue>,
pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, Base64>>>, pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, Base64>>>,
) -> AsyncRecursiveType<'a, Result<(Arc<PduEvent>, BTreeMap<String, CanonicalJsonValue>)>> { ) -> AsyncRecursiveType<'a, Result<(Arc<PduEvent>, BTreeMap<String, CanonicalJsonValue>)>> {
Box::pin(async move { Box::pin(async move {
// 1.1. Remove unsigned field
value.remove("unsigned");
// TODO: For RoomVersion6 we must check that Raw<..> is canonical do we anywhere?: https://matrix.org/docs/spec/rooms/v6#canonical-json // TODO: For RoomVersion6 we must check that Raw<..> is canonical do we anywhere?: https://matrix.org/docs/spec/rooms/v6#canonical-json
// We go through all the signatures we see on the value and fetch the corresponding signing // We go through all the signatures we see on the value and fetch the corresponding signing

View file

@ -117,7 +117,7 @@ impl Error {
StatusCode::FORBIDDEN StatusCode::FORBIDDEN
} }
Unauthorized | UnknownToken { .. } | MissingToken => StatusCode::UNAUTHORIZED, Unauthorized | UnknownToken { .. } | MissingToken => StatusCode::UNAUTHORIZED,
NotFound => StatusCode::NOT_FOUND, NotFound | Unrecognized => StatusCode::NOT_FOUND,
LimitExceeded { .. } => StatusCode::TOO_MANY_REQUESTS, LimitExceeded { .. } => StatusCode::TOO_MANY_REQUESTS,
UserDeactivated => StatusCode::FORBIDDEN, UserDeactivated => StatusCode::FORBIDDEN,
TooLarge => StatusCode::PAYLOAD_TOO_LARGE, TooLarge => StatusCode::PAYLOAD_TOO_LARGE,