Skip to content

Conversation

sameh-farouk
Copy link
Member

@sameh-farouk sameh-farouk commented Aug 10, 2025

Description

Small fix and refactor include:

  • Export the validation logic in getRelayConnections to a new validateRelayURLs
  • Add scheme validation
  • Returns hosts and connections with 1:1 alignment and no duplicates.

Changes

  • Builds exactly one InnerConnection per unique host using the aligned URLs, to prevent the peer from starting multiple connection goroutines for the same relay disrupting each other.

Related Issues

More context

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstring

sort.Slice(validRelayURLs, func(i, j int) bool {
return strings.ToLower(validRelayURLs[i]) < strings.ToLower(validRelayURLs[j])
slices.SortFunc(validRelayURLs, func(a, b *url.URL) int {
return strings.Compare(a.Host, b.Host)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also we depend on hosts only ignoring ports

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


for _, relayURL := range relayURLs {
parsedURL, err := url.Parse(relayURL)
parsedURL, err := url.Parse(strings.ToLower(relayURL))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we only lowercase Hostname

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is better imo since I convert to lower case once, hostname() will be inherently lowercase when I do sort or compact later

sort.Slice(validRelayURLs, func(i, j int) bool {
return strings.ToLower(validRelayURLs[i]) < strings.ToLower(validRelayURLs[j])
validRelayURLs = slices.CompactFunc(validRelayURLs, func(a, b *url.URL) bool {
return a.Hostname() == b.Hostname()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it ignoring ws and wss for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@sameh-farouk sameh-farouk mentioned this pull request Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants