From 5773914c9da7672f3272de3d3686822642c9ed37 Mon Sep 17 00:00:00 2001 From: timedout Date: Mon, 2 Nov 2026 05:05:36 +0000 Subject: [PATCH] feat: Move `resolve-true-destination` to `federation` --- src/admin/debug/commands.rs | 45 +------------------------------- src/admin/debug/mod.rs | 12 --------- src/admin/federation/commands.rs | 36 +++++++++++++++++++++++++ src/admin/federation/health.rs | 3 +++ src/admin/federation/mod.rs | 10 +++++++ src/service/migrations.rs | 7 ++--- 6 files changed, 54 insertions(+), 59 deletions(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 3f5021c8f..db904ae3a 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -9,11 +9,7 @@ use conduwuit::{ }; use futures::{StreamExt, TryStreamExt}; use lettre::message::Mailbox; -use resolvematrix::{ - resolution::ResolvedDestination, - server::{MatrixResolver, MatrixResolverBuilder}, -}; -use ruma::{OwnedRoomId, OwnedServerName}; +use ruma::OwnedRoomId; use crate::PAGE_SIZE; @@ -23,45 +19,6 @@ impl crate::Context<'_> { self.write_str(&message).await } - pub(super) async fn resolve_true_destination( - &self, - server_name: OwnedServerName, - no_cache: bool, - ) -> Result { - if !self.services.server.config.allow_federation { - return Err!("Federation is disabled on this homeserver.",); - } - - if server_name == self.services.server.name { - return Err!( - "Not allowed to send federation requests to ourselves. Please use `get-pdu` for \ - fetching local PDUs.", - ); - } - - let resolver: &MatrixResolver = if no_cache { - &MatrixResolverBuilder::new() - .dangerous_tls_accept_invalid_certs(self.services.server.config.allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure) - .http_client(self.services.client.dns.clone()) - .build()? - } else { - &self.services.client.matrix_resolver - }; - - let actual = resolver.resolve_server(server_name.as_str()).await?; - - let destination = match actual.destination { - | ResolvedDestination::Literal(addr) => addr.to_string(), - | ResolvedDestination::Named(host, port) => format!("{host}:{port}"), - }; - - let msg = format!( - "Destination: {}\nHostname URI (SNI): {}\nIs override?: {}\nResolution step: {}", - destination, actual.host, actual.is_override, actual.resolution_step - ); - self.write_str(&msg).await - } - pub(super) async fn memory_stats(&self, opts: Option) -> Result { const OPTS: &str = "abcdefghijklmnopqrstuvwxyz"; diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 5dc09bb02..c94fe2842 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -2,7 +2,6 @@ mod commands; use clap::Subcommand; use conduwuit::Result; -use ruma::OwnedServerName; use crate::admin_command_dispatch; @@ -14,17 +13,6 @@ pub enum DebugCommand { message: Vec, }, - /// Runs a server name through Continuwuity's true destination resolution - /// process - /// - /// Useful for debugging well-known issues - ResolveTrueDestination { - server_name: OwnedServerName, - - #[arg(short, long)] - no_cache: bool, - }, - /// Print extended memory usage /// /// Optional argument is a character mask (a sequence of characters in any diff --git a/src/admin/federation/commands.rs b/src/admin/federation/commands.rs index 7a4ae2708..426bfab10 100644 --- a/src/admin/federation/commands.rs +++ b/src/admin/federation/commands.rs @@ -1,6 +1,10 @@ use std::fmt::Write; use conduwuit::{Err, Result, utils::response::LimitReadExt}; +use resolvematrix::{ + resolution::ResolvedDestination, + server::{MatrixResolver, MatrixResolverBuilder}, +}; use ruma::{MilliSecondsSinceUnixEpoch, OwnedRoomOrAliasId, OwnedServerName}; impl crate::Context<'_> { @@ -152,4 +156,36 @@ impl crate::Context<'_> { } .await } + + pub(super) async fn resolve_true_destination( + &self, + server_name: OwnedServerName, + no_cache: bool, + ) -> Result { + if !self.services.server.config.allow_federation { + return Err!("Federation is disabled on this homeserver.",); + } + + let resolver: &MatrixResolver = if no_cache { + &MatrixResolverBuilder::new() + .dangerous_tls_accept_invalid_certs(self.services.server.config.allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure) + .http_client(self.services.client.dns.clone()) + .build()? + } else { + &self.services.client.matrix_resolver + }; + + let actual = resolver.resolve_server(server_name.as_str()).await?; + + let destination = match actual.destination { + | ResolvedDestination::Literal(addr) => addr.to_string(), + | ResolvedDestination::Named(host, port) => format!("{host}:{port}"), + }; + + let msg = format!( + "Destination: {}\nHostname URI (SNI): {}\nIs override?: {}\nResolution step: {}", + destination, actual.host, actual.is_override, actual.resolution_step + ); + self.write_str(&msg).await + } } diff --git a/src/admin/federation/health.rs b/src/admin/federation/health.rs index 8b1feaec7..f1697848d 100644 --- a/src/admin/federation/health.rs +++ b/src/admin/federation/health.rs @@ -42,6 +42,9 @@ pub enum HealthCommand { /// the `forbidden_remote_server_names` configuration option. ForceUnhealthy { server_name: OwnedServerName, + /// If set, the server will also be marked as having stale routing + /// information. This means the address will be re-resolved on the next + /// connection attempt. #[arg(long)] stale: bool, }, diff --git a/src/admin/federation/mod.rs b/src/admin/federation/mod.rs index 8107cf362..f0dc625bf 100644 --- a/src/admin/federation/mod.rs +++ b/src/admin/federation/mod.rs @@ -37,6 +37,16 @@ pub enum FederationCommand { server_name: OwnedServerName, }, + /// Runs a server name through Continuwuity's server-to-server address + /// resolution process. + #[clap(name = "resolve")] + ResolveTrueDestination { + server_name: OwnedServerName, + + #[arg(short, long)] + skip_cache: bool, + }, + /// Queries the remote server for their current signing keys. GetSigningKeys { server_name: OwnedServerName, diff --git a/src/service/migrations.rs b/src/service/migrations.rs index 86690bc52..727bcce17 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -167,10 +167,11 @@ migration!(stringify!($name) => $name) // names, preventing users from signing in. VersionBump(22), migration!(fix_oauth_scope_names), - // Removes any extremities in roomid_pduleaves that we do not know about (and - // consequently should not reference). + // Removes any extremities in roomid_pduleaves that we do not know about + // (and consequently should not reference). migration!(remove_unknown_extremities), - // Re-calculates extremities for any rooms that actually lack any extremities at all. + // Re-calculates extremities for any rooms that actually lack any + // extremities at all. migration!(consistency_check_extremity_tracker), ] };