From fd1ccbd3ad474e2eac801a01ca71748827dce92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Wed, 28 Jun 2023 17:41:55 +0200 Subject: [PATCH] improvement: randomize server order for alias joins --- src/api/client_server/alias.rs | 9 +++++---- src/api/client_server/membership.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index ab51b506..7660ca2f 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -1,4 +1,5 @@ use crate::{services, Error, Result, Ruma}; +use rand::seq::SliceRandom; use regex::Regex; use ruma::{ api::{ @@ -90,10 +91,10 @@ pub(crate) async fn get_alias_helper( ) .await?; - return Ok(get_alias::v3::Response::new( - response.room_id, - response.servers, - )); + let mut servers = response.servers; + servers.shuffle(&mut rand::thread_rng()); + + return Ok(get_alias::v3::Response::new(response.room_id, servers)); } let mut room_id = None; diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index ccd8d7a1..c9357b20 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -112,7 +112,7 @@ pub async fn join_room_by_id_or_alias_route( Err(room_alias) => { let response = get_alias_helper(room_alias).await?; - (response.servers.into_iter().collect(), response.room_id) + (response.servers, response.room_id) } };