Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple relays in rmb client #947

Merged
merged 17 commits into from
May 7, 2024

Conversation

rawdaGastan
Copy link
Collaborator

rmb-sdk-go/peer/connection.go Outdated Show resolved Hide resolved
@rawdaGastan rawdaGastan marked this pull request as ready for review March 26, 2024 10:51
rmb-sdk-go/peer/connection.go Outdated Show resolved Hide resolved
@rawdaGastan rawdaGastan force-pushed the development_multi_relays_support branch from 00bcbac to 2c2075d Compare April 15, 2024 08:44
@rawdaGastan rawdaGastan force-pushed the development_multi_relays_support branch from 1c7569b to 3b0f53b Compare April 18, 2024 09:47
"test": "wss://relay.test.grid.tf",
"qa": "wss://relay.qa.grid.tf",
"main": "wss://relay.grid.tf",
RelayURLS = map[string][]string{
Copy link
Member

Choose a reason for hiding this comment

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

@@ -73,7 +81,28 @@ func (c *InnerConnection) reader(ctx context.Context, cancel context.CancelFunc,
}
}

func (c *InnerConnection) loop(ctx context.Context, con *websocket.Conn, output, input chan []byte) error {
func (c *InnerConnection) send(ctx context.Context, data []byte) error {
if c.busy {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest u use an atomic bool like here https://pkg.go.dev/sync/atomic#Bool so we don't run into race conditions

Comment on lines 138 to 140
defer func() {
c.busy = false
}()
Copy link
Member

Choose a reason for hiding this comment

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

You can't use a defer in a loop. this is wrong. Read about it

This is why u still had to set c.busy=false later in the code at line (152)

I suggest that u move this entire branch logic to a function so u can use the defer to release the busy flag.

Copy link
Member

Choose a reason for hiding this comment

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

As i remember the busy flag was intended to make a quick return if the connection is not established so senders can already try another connection until this one is restored. It means it shouldn't be turned on/off inside the branch, but instead ONLY when that connection instance is reconnecting to relay.

case <-ctx.Done():
return ctx.Err()
var errs error
for _, con := range d.cons {
Copy link
Member

Choose a reason for hiding this comment

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

may be should be a ring instead of a list, so on next send u try to use another relay? to balance message sending over multiple relays! Not sure if this is the best approach

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Result of connections used after using ring:

con.url: wss://relay.dev.grid.tf
con.url: wss://relay.02.dev.grid.tf
con.url: wss://relay.dev.grid.tf
con.url: wss://relay.02.dev.grid.tf
con.url: wss://relay.dev.grid.tf
con.url: wss://relay.02.dev.grid.tf
con.url: wss://relay.dev.grid.tf
con.url: wss://relay.02.dev.grid.tf
con.url: wss://relay.dev.grid.tf
con.url: wss://relay.02.dev.grid.tf

@rawdaGastan
Copy link
Collaborator Author

Note: for the atomic boolean before and after connect, connection tries to send before connection so, It always returns it is busy
I left it in the code to be discussed

@rawdaGastan rawdaGastan force-pushed the development_multi_relays_support branch 2 times, most recently from bbd7e29 to f421d0a Compare May 1, 2024 13:31
…n, add atomic bool to watch busy connections
@rawdaGastan rawdaGastan force-pushed the development_multi_relays_support branch from f421d0a to c8ee297 Compare May 2, 2024 07:40
@rawdaGastan rawdaGastan merged commit d96c7e4 into development May 7, 2024
39 checks passed
@rawdaGastan rawdaGastan deleted the development_multi_relays_support branch May 7, 2024 10:08
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.

None yet

4 participants