Make PlatformRef::connect_*
instantaneously return
#1279
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #1249
When it comes to TCP connections, the connection process follows the three way handshake. Once finished, we are now "connected" to the remote and can exchange messages. The same exists for WebSocket, where the server sends back an HTTP response signalling that we're now "connected".
However, when it comes to connections such as QUIC or WebRTC, it's less clear what "connected" means. QUIC supports 0-RTT connections, meaning that you're "instantaneously" connected. Similarly, WebRTC only actually does things once you try opening a channel, and it's not clear when you're actually "connected" or not.
Because of this, the word "connected" is a bit blurry.
In #1200, I've realized that we don't actually care whether we're "connected". Libp2p requires an extra handshake (Noise and maybe Yamux) anyway, and I don't see any advantage in differentiating the moment when the TCP handshake has finished and when the libp2p handshake has finished.
For this reason, in #1200, the concept of "pending connections" is gone. Instead, connections are instantaneously "connected", or, more precisely, there's no concept of "connected" anymore. There are only connections before their (libp2p) handshake and connections after their (libp2p) handshake.
#1200, however, introduced two issues:
While the second point could be solved with more code in the
light-base
library, I've instead decided to solve both by propagating the removal of the concept of "connected" to thePlatformRef
trait.cc @lexnv @skunert
What that means, pragmatically speaking, is:
PlatformRef::connect_stream
andconnect_multistream
must now return as soon as possible. They're still returning futures, but it's done for API reasons. These futures must not wait for the connection to be established or something.WithBuffers
(the helper to help implementPlatformRef
) now stores aFuture<Output = Socket>
instead of just aSocket
.So in order to update after this change, you should now return a
WithBuffer<Future<Output = Socket>>
fromPlatformRef::connect_*
, instead of aFuture<Output = WithBuffer<Socket>>
.See the changes to
default.rs
for an illustration.This change made it possible to significantly simplify the WebRTC browser implementation, as at the moment we open a hacky preliminary substream just to detect when we reach the remote.