From 67f9592b177b41537e50cfb624d56f15b84a6875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Mon, 14 Jun 2021 11:36:18 +0200 Subject: [PATCH] feat: /event_auth --- src/main.rs | 3 ++- src/server_server.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8a19f13..99d4560 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,8 +153,9 @@ fn setup_rocket(config: Figment, data: Arc) -> rocket::Rocket/<_>", data = "") +)] +#[tracing::instrument(skip(db, body))] +pub fn get_event_authorization_route( + db: State<'_, Arc>, + body: Ruma>, +) -> ConduitResult { + if !db.globals.allow_federation() { + return Err(Error::bad_config("Federation is disabled.")); + } + + let mut auth_chain = Vec::new(); + let mut auth_chain_ids = BTreeSet::::new(); + let mut todo = BTreeSet::new(); + todo.insert(body.event_id.clone()); + + while let Some(event_id) = todo.iter().next().cloned() { + if let Some(pdu) = db.rooms.get_pdu(&event_id)? { + todo.extend( + pdu.auth_events + .clone() + .into_iter() + .collect::>() + .difference(&auth_chain_ids) + .cloned(), + ); + auth_chain_ids.extend(pdu.auth_events.into_iter()); + + let pdu_json = PduEvent::convert_to_outgoing_federation_event( + db.rooms.get_pdu_json(&event_id)?.unwrap(), + ); + auth_chain.push(pdu_json); + } else { + warn!("Could not find pdu mentioned in auth events."); + } + + todo.remove(&event_id); + } + + Ok(get_event_authorization::v1::Response { auth_chain }.into()) +} + #[cfg_attr( feature = "conduit_bin", get("/_matrix/federation/v1/state/<_>", data = "")