feat: Move resolve-true-destination to federation

This commit is contained in:
timedout committed 2026-11-02 05:05:36 +00:00
1 parent 4ac23d8649
commit 5773914c9d
6 files changed
+54 -59

No files matched your search

+1 -44
View File
@@ -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<String>) -> Result {
const OPTS: &str = "abcdefghijklmnopqrstuvwxyz";
-12
View File
@@ -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<String>,
},
/// 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
+36
View File
@@ -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
}
}
+3
View File
@@ -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,
},
+10
View File
@@ -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,
+4 -3
View File
@@ -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),
]
};