Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
6aaf169c
Commit
6aaf169c
authored
1 year ago
by
🥺
Committed by
🥺
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
fix wrong order of logic, prefer room alias server first if available
Signed-off-by:
strawberry
<
strawberry@puppygock.gay
>
parent
e9793868
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api/client_server/alias.rs
+24
-13
24 additions, 13 deletions
src/api/client_server/alias.rs
with
24 additions
and
13 deletions
src/api/client_server/alias.rs
+
24
−
13
View file @
6aaf169c
...
@@ -113,6 +113,9 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
...
@@ -113,6 +113,9 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
let
mut
servers
=
response
.servers
;
let
mut
servers
=
response
.servers
;
// since the room alias server_name responded, insert it into the list
servers
.push
(
room_alias
.server_name
()
.into
());
// find active servers in room state cache to suggest
// find active servers in room state cache to suggest
for
extra_servers
in
services
()
for
extra_servers
in
services
()
.rooms
.rooms
...
@@ -123,7 +126,14 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
...
@@ -123,7 +126,14 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
servers
.push
(
extra_servers
);
servers
.push
(
extra_servers
);
}
}
// insert our server as the very first choice if in list
servers
.sort_unstable
();
servers
.dedup
();
// shuffle list of servers randomly after sort and dedupe
servers
.shuffle
(
&
mut
rand
::
thread_rng
());
// prefer the very first server to be ourselves if available, else prefer the
// room alias server first
if
let
Some
(
server_index
)
=
servers
if
let
Some
(
server_index
)
=
servers
.clone
()
.clone
()
.into_iter
()
.into_iter
()
...
@@ -131,14 +141,15 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
...
@@ -131,14 +141,15 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
{
{
servers
.remove
(
server_index
);
servers
.remove
(
server_index
);
servers
.insert
(
0
,
services
()
.globals
.server_name
()
.to_owned
());
servers
.insert
(
0
,
services
()
.globals
.server_name
()
.to_owned
());
}
else
if
let
Some
(
alias_server_index
)
=
servers
.clone
()
.into_iter
()
.position
(|
server
|
server
==
room_alias
.server_name
())
{
servers
.remove
(
alias_server_index
);
servers
.insert
(
0
,
room_alias
.server_name
()
.into
());
}
}
servers
.sort_unstable
();
servers
.dedup
();
// shuffle list of servers randomly after sort and dedupe
servers
.shuffle
(
&
mut
rand
::
thread_rng
());
return
Ok
(
get_alias
::
v3
::
Response
::
new
(
room_id
,
servers
));
return
Ok
(
get_alias
::
v3
::
Response
::
new
(
room_id
,
servers
));
}
}
...
@@ -191,6 +202,12 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
...
@@ -191,6 +202,12 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
servers
.push
(
extra_servers
);
servers
.push
(
extra_servers
);
}
}
servers
.sort_unstable
();
servers
.dedup
();
// shuffle list of servers randomly after sort and dedupe
servers
.shuffle
(
&
mut
rand
::
thread_rng
());
// insert our server as the very first choice if in list
// insert our server as the very first choice if in list
if
let
Some
(
server_index
)
=
servers
if
let
Some
(
server_index
)
=
servers
.clone
()
.clone
()
...
@@ -201,11 +218,5 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
...
@@ -201,11 +218,5 @@ pub(crate) async fn get_alias_helper(room_alias: OwnedRoomAliasId) -> Result<get
servers
.insert
(
0
,
services
()
.globals
.server_name
()
.to_owned
());
servers
.insert
(
0
,
services
()
.globals
.server_name
()
.to_owned
());
}
}
servers
.sort_unstable
();
servers
.dedup
();
// shuffle list of servers randomly after sort and dedupe
servers
.shuffle
(
&
mut
rand
::
thread_rng
());
Ok
(
get_alias
::
v3
::
Response
::
new
(
room_id
,
servers
))
Ok
(
get_alias
::
v3
::
Response
::
new
(
room_id
,
servers
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment