cleanup and fix backfill from server getting

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-07-05 21:11:54 -04:00 committed by June 🍓🦴
parent 68ad351f84
commit 373991a8d6
2 changed files with 33 additions and 59 deletions

View file

@ -309,7 +309,7 @@ pub(crate) async fn register_route(
// log in conduit admin channel if a guest registered // log in conduit admin channel if a guest registered
if body.appservice_info.is_none() && is_guest && services().globals.log_guest_registrations() { if body.appservice_info.is_none() && is_guest && services().globals.log_guest_registrations() {
info!("New guest user \"{user_id}\" registered on this server from IP."); info!("New guest user \"{user_id}\" registered on this server.");
if let Some(device_display_name) = &body.initial_device_display_name { if let Some(device_display_name) = &body.initial_device_display_name {
if body if body

View file

@ -9,7 +9,6 @@ use std::{
use conduit::{debug, error, info, utils, utils::mutex_map, validated, warn, Error, Result}; use conduit::{debug, error, info, utils, utils::mutex_map, validated, warn, Error, Result};
use data::Data; use data::Data;
use itertools::Itertools; use itertools::Itertools;
use rand::prelude::SliceRandom;
use ruma::{ use ruma::{
api::{client::error::ErrorKind, federation}, api::{client::error::ErrorKind, federation},
canonical_json::to_canonical_value, canonical_json::to_canonical_value,
@ -1081,7 +1080,7 @@ impl Service {
Ok(()) Ok(())
} }
#[tracing::instrument(skip(self, room_id))] #[tracing::instrument(skip(self))]
pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result<()> { pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result<()> {
let first_pdu = self let first_pdu = self
.all_pdus(user_id!("@doesntmatter:conduit.rs"), room_id)? .all_pdus(user_id!("@doesntmatter:conduit.rs"), room_id)?
@ -1093,41 +1092,6 @@ impl Service {
return Ok(()); return Ok(());
} }
let mut servers: Vec<OwnedServerName> = vec![];
// add server names of any trusted key servers if they're in the room
servers.extend(
services()
.rooms
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server_name| {
services().globals.trusted_servers().contains(server_name) && !server_is_ours(server_name)
}),
);
// add server names from room aliases on the room ID
let room_aliases = services()
.rooms
.alias
.local_aliases_for_room(room_id)
.collect::<Result<Vec<_>, _>>();
if let Ok(aliases) = &room_aliases {
for alias in aliases {
if !server_is_ours(alias.server_name()) {
servers.push(alias.server_name().to_owned());
}
}
}
// add room ID server name for backfill server
if let Some(server_name) = room_id.server_name() {
if !server_is_ours(server_name) {
servers.push(server_name.to_owned());
}
}
let power_levels: RoomPowerLevelsEventContent = services() let power_levels: RoomPowerLevelsEventContent = services()
.rooms .rooms
.state_accessor .state_accessor
@ -1139,29 +1103,39 @@ impl Service {
.transpose()? .transpose()?
.unwrap_or_default(); .unwrap_or_default();
// add server names of the list of admins in the room for backfill server let room_mods = power_levels.users.iter().filter_map(|(user_id, level)| {
servers.extend( if level > &power_levels.users_default && !server_is_ours(user_id.server_name()) {
power_levels Some(user_id.server_name().to_owned())
.users } else {
.iter() None
.filter(|(_, level)| **level > power_levels.users_default) }
.map(|(user_id, _)| user_id.server_name()) });
.filter(|server_name| !server_is_ours(server_name))
.map(ToOwned::to_owned),
);
// don't backfill from ourselves (might be noop if we checked it above already) let room_alias_servers = services()
if let Some(server_index) = servers .rooms
.clone() .alias
.into_iter() .local_aliases_for_room(room_id)
.position(|server_name| server_is_ours(&server_name)) .filter_map(|alias| {
{ alias
servers.swap_remove(server_index); .ok()
} .filter(|alias| !server_is_ours(alias.server_name()))
.map(|alias| alias.server_name().to_owned())
});
servers.sort_unstable(); let servers = room_mods
servers.dedup(); .chain(room_alias_servers)
servers.shuffle(&mut rand::thread_rng()); .chain(services().globals.config.trusted_servers.clone())
.filter(|server_name| {
if server_is_ours(server_name) {
return false;
}
services()
.rooms
.state_cache
.server_in_room(server_name, room_id)
.unwrap_or(false)
});
for backfill_server in servers { for backfill_server in servers {
info!("Asking {backfill_server} for backfill"); info!("Asking {backfill_server} for backfill");