-
Notifications
You must be signed in to change notification settings - Fork 93
feat: early muxer negotiation #274
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
125c384
add content on early muxer negotiation
salmad3 880dae7
edits
salmad3 a5de7a0
edits
salmad3 6d1f5be
Apply suggestions from code review
salmad3 5bbc446
Apply suggestions from code review
salmad3 ca7a545
lint, formatting
salmad3 1aaf98e
fix alert href
salmad3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: "Early Multiplexer Negotiation" | ||
description: "Early stream multiplexer negotiation is an optimization in libp2p where peers can negotiate which multiplexer to use during the security protocol handshake, saving one round trip." | ||
weight: 162 | ||
--- | ||
|
||
## Vanilla stream multiplexer selection process | ||
|
||
One of libp2p's main guarantees is that no data sent over the wire is unencrypted. | ||
This means that transport protocols, like TCP or WebSocket, that don't support encryption | ||
by default must complete a cryptographic handshake. This process of adding the secure channel | ||
on top of the raw transport is called upgrading the connections and happens via the | ||
[multistream-select protocol](https://github.com/multiformats/multistream-select). | ||
|
||
In the unoptimized libp2p connection upgrade process, the security or encryption is negotiated | ||
first. After that is agreed upon, the stream multiplexer is negotiated. Again this only happens | ||
for transports that don't have native stream multiplexing. | ||
|
||
A standard connection upgrade process that negotiates the secure channel first and the multiplexer | ||
second | ||
[is shown in a diagram here](https://github.com/libp2p/specs/tree/master/connections#upgrading-connections). | ||
|
||
First, the security protocol is negotiated, then this protocol is used to perform a cryptographic | ||
handshake. libp2p currently supports [Noise](../secure-comm/noise) and [TLS 1.3](../secure-comm/tls). | ||
Once the cryptographic handshake completes, multistream-select runs again on top of | ||
the secured connection to negotiate a steam multiplexer, like [yamux](yamux) or [mplex](mplex). | ||
|
||
<!-- ADD DIAGRAM --> | ||
|
||
## Early muxer negotiation | ||
|
||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The libp2p project eliminates an unnecessary round trip in the standard negotiation protocol | ||
for selecting a stream multiplexer. This is achieved by combining the steps of agreeing on a | ||
secure channel and multiplexer. This is called "early" or "inlined" muxer negotiation. | ||
|
||
Early muxer negotiation is a feature in libp2p that allows for the simultaneous selection of a | ||
stream multiplexer during the cryptographic handshake of the TLS and Noise security protocols. | ||
This is achieved by sharing a list of supported muxer protocols as a part of the handshake payload. | ||
|
||
For example, if a libp2p node supports mplex and yamux, it will advertise both in the list. | ||
This **eliminates an extra round trip**, improving TTFB (time to first byte) in the libp2p handshake. | ||
Currently, this feature is only supported in go-libp2p and for TCP and WebSocket transports that do | ||
not have native encryption or multiplexing. | ||
|
||
<!-- ADD DIAGRAM --> | ||
|
||
### ALPN extension in TLS | ||
|
||
The [Application-Layer Protocol Negotiation (ALPN) extension](https://datatracker.ietf.org/doc/html/rfc7301) | ||
is a feature of TLS that allows for the negotiation of application-layer protocols during the TLS handshake. | ||
This allows the client and server to agree on the application-layer protocol for the rest of the TLS session. | ||
ALPN is typically used to negotiate the application-layer protocol for applications that use TLS, such as HTTP/2 | ||
or QUIC. libp2p uses ALPN to negotiate the stream muxer and saves a roundtrip when upgrading a raw connection. | ||
|
||
### Extension registry in Noise | ||
|
||
Since there's no commonly used extension mechanism in Noise, libp2p defines an extension registry. | ||
We then defined an extension to negotiate the stream multiplexer, that is conceptually the equivalent | ||
of the ALPN extension in TLS. | ||
|
||
> The extension registry is modeled after | ||
> [RFC 6066](https://www.rfc-editor.org/rfc/rfc6066) (for TLS) and | ||
> [RFC 9000](https://datatracker.ietf.org/doc/html/rfc9000#section-19.21) | ||
> (for QUIC). | ||
|
||
More information is available in the | ||
[Noise specification](https://github.com/libp2p/specs/blob/master/noise/README.md#libp2p-data-in-handshake-messages). | ||
salmad3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{{< alert icon="💡" context="note" text="See the inclined muxer negotiation <a class=\"text-muted\" href=\"https://github.com/libp2p/specs/blob/master/connections/inlined-muxer-negotiation.md\">specification</a> for more details." />}} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we planning to merge without resolving this TODO? Should we create an issue so we don't forget?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have them noted down, and will also add to the issue open about unified diagrams.