feat: Move ping command to federation group

This commit is contained in:
timedout committed 2026-10-31 21:16:07 +00:00
1 parent 84d4c1c19e
commit a748115ab5
4 files changed
+45 -45

No files matched your search

-35
View File
@@ -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
-7
View File
@@ -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,
+31
View File
@@ -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
}
}
+14 -3
View File
@@ -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,
},
}