diff --git a/src/api/server/get_missing_events.rs b/src/api/server/get_missing_events.rs index a4915bb8b..9a42db4c5 100644 --- a/src/api/server/get_missing_events.rs +++ b/src/api/server/get_missing_events.rs @@ -4,15 +4,11 @@ use axum::extract::State; use conduwuit::{Err, Event, Result, debug, info, trace, utils::to_canonical_object, warn}; use ruma::{OwnedEventId, api::federation::event::get_missing_events}; use serde_json::{json, value::RawValue}; +use service::rooms::event_handler::GET_MISSING_EVENTS_MAX_BATCH_SIZE; use super::AccessCheck; use crate::Ruma; -/// arbitrary number but synapse's is 20 and we can handle lots of these anyways -const LIMIT_MAX: usize = 50; -/// spec says default is 10 -const LIMIT_DEFAULT: usize = 10; - /// # `POST /_matrix/federation/v1/get_missing_events/{roomId}` /// /// Retrieves events that the sender is missing. @@ -45,8 +41,8 @@ pub(crate) async fn get_missing_events_route( let limit = body .limit .try_into() - .unwrap_or(LIMIT_DEFAULT) - .min(LIMIT_MAX); + .unwrap_or(10) + .min(GET_MISSING_EVENTS_MAX_BATCH_SIZE); let room_version = services.rooms.state.get_room_version(&body.room_id).await?; diff --git a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs index 63bb6deeb..35d96962a 100644 --- a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs +++ b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs @@ -25,7 +25,7 @@ use ruma::{ use super::get_room_version_rules; use crate::rooms::event_handler::parse_incoming_pdu::expect_event_id_array; -const GET_MISSING_EVENTS_MAX_BATCH_SIZE: u16 = 50; // matches src/server/get_missing_events.rs#LIMIT_MAX +pub const GET_MISSING_EVENTS_MAX_BATCH_SIZE: usize = 50; /// Attempts to build a localised directed acyclic graph out of the given PDUs, /// returning them in a topologically sorted order. @@ -175,7 +175,9 @@ impl super::Service { let limit = iteration .expected_add(1) .saturating_mul(10) - .min(GET_MISSING_EVENTS_MAX_BATCH_SIZE) + .min(GET_MISSING_EVENTS_MAX_BATCH_SIZE.try_into().expect( + "GET_MISSING_EVENTS_MAX_BATCH_SIZE (usize) should fit in u16 (<=65536)", + )) .max( // This max call ensures we fetch *at least* all the prev events the // head has. diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index f51d701f0..c11853ecd 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -14,7 +14,7 @@ use std::{collections::HashMap, fmt::Write, sync::Arc, time::Instant}; use async_trait::async_trait; use conduwuit::{Err, Event, PduEvent, Result, Server, SyncRwLock, utils::MutexMap}; -pub use fetch_and_handle_outliers::build_local_dag; +pub use fetch_and_handle_outliers::{GET_MISSING_EVENTS_MAX_BATCH_SIZE, build_local_dag}; use ruma::{ OwnedEventId, OwnedRoomId, RoomId, events::room::create::RoomCreateEventContent, room_version_rules::RoomVersionRules,