Remove unnecessary report delay.

This commit is contained in:
dasha_uwu
2026-02-03 02:51:34 +05:00
committed by Jason Volk
parent b79920a63b
commit 76dbf4fcb5

View File

@@ -1,15 +1,11 @@
use std::time::Duration;
use axum::extract::State; use axum::extract::State;
use axum_client_ip::InsecureClientIp; use axum_client_ip::InsecureClientIp;
use rand::Rng;
use ruma::{ use ruma::{
EventId, RoomId, UserId, EventId, RoomId, UserId,
api::client::room::{report_content, report_room}, api::client::room::{report_content, report_room},
events::room::message, events::room::message,
int, int,
}; };
use tokio::time::sleep;
use tuwunel_core::{Err, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt}; use tuwunel_core::{Err, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
use tuwunel_service::Services; use tuwunel_service::Services;
@@ -40,8 +36,6 @@ pub(crate) async fn report_room_route(
))); )));
} }
delay_response().await;
if !services if !services
.state_cache .state_cache
.server_in_room(&services.server.name, &body.room_id) .server_in_room(&services.server.name, &body.room_id)
@@ -88,8 +82,6 @@ pub(crate) async fn report_event_route(
body.reason.as_deref().unwrap_or("") body.reason.as_deref().unwrap_or("")
); );
delay_response().await;
// check if we know about the reported event ID or if it's invalid // check if we know about the reported event ID or if it's invalid
let Ok(pdu) = services.timeline.get_pdu(&body.event_id).await else { let Ok(pdu) = services.timeline.get_pdu(&body.event_id).await else {
return Err!(Request(NotFound("Event ID is not known to us or Event ID is invalid"))); return Err!(Request(NotFound("Event ID is not known to us or Event ID is invalid")));
@@ -171,16 +163,3 @@ async fn is_event_report_valid(
Ok(()) Ok(())
} }
/// even though this is kinda security by obscurity, let's still make a small
/// random delay sending a response per spec suggestion regarding
/// enumerating for potential events existing in our server.
async fn delay_response() {
let time_to_wait = rand::thread_rng().gen_range(2..5);
debug_info!(
"Got successful /report request, waiting {time_to_wait} seconds before sending \
successful response."
);
sleep(Duration::from_secs(time_to_wait)).await;
}