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

swarm: delay /webrtc-direct dials by 1 second #3078

Merged
merged 5 commits into from
Dec 5, 2024
Merged

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Dec 3, 2024

Previously these addresses weren't delayed at all. When I initially did the ranker implementation, I was too conservative regarding what to delay. So, non QUIC, WebTransport, TCP, WS addresses were ignored in ranking. We only ever need to dial /webrtc-direct when there's no other address available for the peer, in which case we will dial the addresses immediately.

This would have helped with libp2p/js-libp2p#2805 as there would have been fewer peers dialing webrtc and then cancelling because they connected on a better transport.

This also introduces an additional 1 second delay for any fancy non IP transports

Previously these addresses weren't delayed at all. When I initially did the
ranker implementation, I was too conservative regarding what to delay. So,
non QUIC, WebTransport, TCP, WS addresses were ignored in ranking. We only
ever need to dial /webrtc-direct when there's no other address available
for the peer, in which case we will dial the addresses immediately.

This would have helped with libp2p/js-libp2p#2805
as there would have been fewer peers dialing webrtc and then cancelling
because they connected on a better transport.

This also introduces an additional 1 second delay for any fancy non IP
transports
@sukunrt sukunrt requested a review from MarcoPolo December 3, 2024 10:09
@sukunrt sukunrt self-assigned this Dec 3, 2024
@p-shahi p-shahi mentioned this pull request Dec 3, 2024
26 tasks
@sukunrt sukunrt force-pushed the sukun/webrtc-delay branch from 9796b8d to 0df12d6 Compare December 3, 2024 17:52
@sukunrt sukunrt force-pushed the sukun/webrtc-delay branch from 0df12d6 to b352a54 Compare December 3, 2024 17:53
Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

The changes make sense, just a question about the test

@@ -199,3 +203,72 @@ func TestAddrFactorCertHashAppend(t *testing.T) {
return hasWebRTC && hasWebTransport
}, 5*time.Second, 100*time.Millisecond)
}

func TestWebRTCDirectDialDelay(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this test. Is it trying to make sure that if many peers are connected to a server (via QUIC?), that another peer can also connect to that server via WebRTC?

Copy link
Member Author

@sukunrt sukunrt Dec 4, 2024

Choose a reason for hiding this comment

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

There are two tests.

  1. TestOnlyWebRTCDirectDialNoDelay: Tests that dials to a peer with only webrtc address aren't delayed.
  2. TestWebRTCWithManyQUICConnections: Tests that in presence of quic addresses webrtc dials are actually delayed. In case there's no happy eyeballs, the 200 initial dials would have taken up all the goroutines available for handshakes in the webrtc listener.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In case there's no happy eyeballs, the 200 initial dials would have taken up all the goroutines available for handshakes in the webrtc listener.

But you wait for the Connect to finish, so wouldn't the handshake be complete at this point?

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, the QUIC handshake will complete not the webrtc one. The webrtc handshake will be cancelled. As there's no way to signal this cancellation in webrtc, the server will have to wait for timeout on this handshake. So, at this point if we get a new webrtc handshake attempt, it'll fail because there were no free listener goroutines. This all happens when there's no happy eyeballs.

With happy eyeballs, the quic handshake should complete without any webrtc dials.

@MarcoPolo MarcoPolo self-requested a review December 4, 2024 20:41
@sukunrt sukunrt force-pushed the sukun/webrtc-delay branch 18 times, most recently from 4114296 to a28ecec Compare December 5, 2024 10:27
@sukunrt sukunrt force-pushed the sukun/webrtc-delay branch from a28ecec to e675e4b Compare December 5, 2024 10:28
@MarcoPolo MarcoPolo merged commit 31b9d3a into master Dec 5, 2024
11 checks passed
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