mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-12 19:56:48 +00:00
feat: Move resolve-true-destination to federation
This commit is contained in:
6 files changed
+54
-59
No files matched your search
@@ -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";
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
]
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user