mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 20:56:49 +00:00
style: Remove duplicate pdu check 1 call in handle_incoming_pdu
This commit is contained in:
3 files changed
+4
-27
No files matched your search
@@ -5,15 +5,16 @@ use std::{
|
|||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Event, Result, debug, debug_error, debug_warn, defer, error, matrix::PartialPdu,
|
Err, Event, Result, debug, debug_error, debug_warn, defer, error, matrix::PartialPdu,
|
||||||
result::DebugInspect, trace, utils::time::jitter, warn,
|
result::DebugInspect, trace, utils::time::jitter,
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt, future::try_join3};
|
use futures::{FutureExt, StreamExt, future::try_join3};
|
||||||
use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UserId};
|
use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UserId};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::rooms::timeline::{RawPduId, pdu_fits};
|
use crate::rooms::timeline::RawPduId;
|
||||||
|
|
||||||
impl super::Service {
|
impl super::Service {
|
||||||
|
/// Handles an incoming PDU from federation.
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
name = "pdu",
|
name = "pdu",
|
||||||
skip_all,
|
skip_all,
|
||||||
@@ -32,13 +33,6 @@ impl super::Service {
|
|||||||
if let Ok(pdu_id) = self.services.timeline.get_pdu_id(event_id).await {
|
if let Ok(pdu_id) = self.services.timeline.get_pdu_id(event_id).await {
|
||||||
return Ok(Some(pdu_id));
|
return Ok(Some(pdu_id));
|
||||||
}
|
}
|
||||||
if !pdu_fits(&value) {
|
|
||||||
warn!(
|
|
||||||
"dropping incoming PDU {event_id} in room {room_id} from {origin} because it \
|
|
||||||
exceeds 65535 bytes or is otherwise too large."
|
|
||||||
);
|
|
||||||
return Err!(Request(TooLarge("PDU is too large")));
|
|
||||||
}
|
|
||||||
trace!(
|
trace!(
|
||||||
"processing incoming PDU from {origin} for room {room_id} with event id {event_id}"
|
"processing incoming PDU from {origin} for room {room_id} with event id {event_id}"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use conduwuit::{
|
|||||||
};
|
};
|
||||||
use ruma::{CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, RoomId, ServerName};
|
use ruma::{CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, RoomId, ServerName};
|
||||||
|
|
||||||
use super::{check_room_id, get_room_version_rules};
|
use super::get_room_version_rules;
|
||||||
|
|
||||||
impl super::Service {
|
impl super::Service {
|
||||||
/// Handles a PDU as an outlier, performing basic checks like signatures and
|
/// Handles a PDU as an outlier, performing basic checks like signatures and
|
||||||
@@ -39,7 +39,6 @@ impl super::Service {
|
|||||||
"event_id".to_owned(),
|
"event_id".to_owned(),
|
||||||
CanonicalJsonValue::String(event_id.as_str().to_owned()),
|
CanonicalJsonValue::String(event_id.as_str().to_owned()),
|
||||||
);
|
);
|
||||||
check_room_id(room_id, &pdu_event)?;
|
|
||||||
return Ok((pdu_event, value));
|
return Ok((pdu_event, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,22 +115,6 @@ impl Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_room_id<Pdu: Event>(room_id: &RoomId, pdu: &Pdu) -> Result {
|
|
||||||
if pdu
|
|
||||||
.room_id()
|
|
||||||
.is_some_and(|claimed_room_id| claimed_room_id != room_id)
|
|
||||||
{
|
|
||||||
return Err!(Request(InvalidParam(error!(
|
|
||||||
pdu_event_id = %pdu.event_id(),
|
|
||||||
pdu_room_id = pdu.room_id().map(tracing::field::display),
|
|
||||||
%room_id,
|
|
||||||
"Found event from room in room",
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_room_version_rules<Pdu: Event>(create_event: &Pdu) -> Result<RoomVersionRules> {
|
fn get_room_version_rules<Pdu: Event>(create_event: &Pdu) -> Result<RoomVersionRules> {
|
||||||
let content: RoomCreateEventContent = create_event.get_content()?;
|
let content: RoomCreateEventContent = create_event.get_content()?;
|
||||||
let Some(room_version_rules) = content.room_version.rules() else {
|
let Some(room_version_rules) = content.room_version.rules() else {
|
||||||
|
|||||||
Reference in new issue
Block a user