From a748115ab5783e912c36bfaeeb36d01ecda66221 Mon Sep 17 00:00:00 2001 From: timedout Date: Sat, 31 Oct 2026 21:16:07 +0000 Subject: [PATCH] feat: Move ping command to federation group --- src/admin/debug/commands.rs | 35 -------------------------------- src/admin/debug/mod.rs | 7 ------- src/admin/federation/commands.rs | 31 ++++++++++++++++++++++++++++ src/admin/federation/mod.rs | 17 +++++++++++++--- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index aa122a08b..97ba37fa7 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -513,41 +513,6 @@ impl crate::Context<'_> { .await } - pub(super) async fn ping(&self, server: OwnedServerName) -> Result { - if server == self.services.globals.server_name() { - return Err!("Not allowed to send federation requests to ourselves."); - } - - let timer = tokio::time::Instant::now(); - - match self - .services - .sending - .send_unauthenticated_request( - &server, - ruma::api::federation::discovery::get_server_version::v1::Request::new(), - ) - .await - { - | Err(e) => { - return Err!("Failed sending federation request to specified server:\n\n{e}"); - }, - | Ok(response) => { - let ping_time = timer.elapsed(); - let json_text_res = serde_json::to_string_pretty(&response.server); - - let out = if let Ok(json) = json_text_res { - format!("Got response which took {ping_time:?} time:\n```json\n{json}\n```") - } else { - format!("Got non-JSON response which took {ping_time:?} time:\n{response:?}") - }; - - write!(self, "{out}") - }, - } - .await - } - pub(super) async fn force_device_list_updates(&self) -> Result { // Force E2EE device list updates for all users self.services diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 396e98616..d61f15407 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -80,13 +80,6 @@ pub enum DebugCommand { force: bool, }, - /// Sends a federation request to the remote server's - /// `/_matrix/federation/v1/version` endpoint and measures the latency it - /// took for the server to respond - Ping { - server: OwnedServerName, - }, - /// Forces device lists for all local and remote users to be updated (as /// having new keys available) ForceDeviceListUpdates, diff --git a/src/admin/federation/commands.rs b/src/admin/federation/commands.rs index 786d2e325..7a4ae2708 100644 --- a/src/admin/federation/commands.rs +++ b/src/admin/federation/commands.rs @@ -121,4 +121,35 @@ impl crate::Context<'_> { Ok(()) } + + pub(super) async fn ping(&self, server: OwnedServerName) -> Result { + let timer = tokio::time::Instant::now(); + + match self + .services + .sending + .send_unauthenticated_request( + &server, + ruma::api::federation::discovery::get_server_version::v1::Request::new(), + ) + .await + { + | Err(e) => { + return Err!("Failed sending federation request to specified server:\n\n{e}"); + }, + | Ok(response) => { + let ping_time = timer.elapsed(); + let json_text_res = serde_json::to_string_pretty(&response.server); + + let out = if let Ok(json) = json_text_res { + format!("Got response which took {ping_time:?} time:\n```json\n{json}\n```") + } else { + format!("Got non-JSON response which took {ping_time:?} time:\n{response:?}") + }; + + write!(self, "{out}") + }, + } + .await + } } diff --git a/src/admin/federation/mod.rs b/src/admin/federation/mod.rs index 88f321c4d..df1c49cbc 100644 --- a/src/admin/federation/mod.rs +++ b/src/admin/federation/mod.rs @@ -10,19 +10,21 @@ use crate::admin_command_dispatch; #[derive(Debug, Subcommand)] pub enum FederationCommand { /// List all rooms we are currently handling an incoming pdu from - #[clap(name="incoming", alias="inbound")] + #[clap(name = "incoming", alias = "inbound")] IncomingFederation, /// Disables incoming federation handling for a room. /// - /// The room can still be used locally, but events from other servers will stop being received. + /// The room can still be used locally, but events from other servers will + /// stop being received. DisableRoom { room: OwnedRoomOrAliasId, }, /// Enables incoming federation handling for a room again. /// - /// This does not unban the room if it was banned, it only re-enables incoming events. + /// This does not unban the room if it was banned, it only re-enables + /// incoming events. EnableRoom { room: OwnedRoomOrAliasId, }, @@ -38,4 +40,13 @@ pub enum FederationCommand { GetSigningKeys { server_name: OwnedServerName, }, + + /// Makes a federation request to the remote server, to test connectivity. + /// + /// The request is made to the federation version endpoint, which if + /// successful, will also reveal how long the request took and what the + /// remote server's software is. + Ping { + server_name: OwnedServerName, + }, }