-
Notifications
You must be signed in to change notification settings - Fork 280
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
multistream-select 1.0: simultaneous open protocol extension #196
Changes from 3 commits
31b56bf
df1ad98
15eb969
682894e
21be08c
26774a2
ff7a12e
3dd8877
debc8f5
dc663fe
ae86e33
13ea44a
41ce779
77cbb43
dd14a1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,88 @@ | ||||||||||||
# Simultaneous Open for multistream-select | ||||||||||||
vyzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
| Lifecycle Stage | Maturity | Status | Latest Revision | | ||||||||||||
|-----------------|---------------|--------|-----------------| | ||||||||||||
| 1A | Working Draft | Active | DRAFT | | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
Authors: [@vyzo] | ||||||||||||
|
||||||||||||
Interest Group: [@raulk], [@stebalien] | ||||||||||||
|
||||||||||||
[@vyzo]: https://github.com/vyzo | ||||||||||||
[@raulk]: https://github.com/raulk | ||||||||||||
[@stebalien]: https://github.com/stebalien | ||||||||||||
|
||||||||||||
See the [lifecycle document][lifecycle-spec] for context about maturity level | ||||||||||||
and spec status. | ||||||||||||
|
||||||||||||
[lifecycle-spec]: https://github.com/libp2p/specs/blob/master/00-framework-01-spec-lifecycle.md | ||||||||||||
|
||||||||||||
|
||||||||||||
## Introduction | ||||||||||||
|
||||||||||||
In order to support direct connections through NATs with hole | ||||||||||||
punching, we need to account for simultaneous open. In such cases, | ||||||||||||
there is no single initiator and responder, but instead both peers act | ||||||||||||
as initiators. This breaks protocol negotiation in | ||||||||||||
multistream-select, which assumes a single initator. | ||||||||||||
|
||||||||||||
This draft proposes a simple extension to the multistream protocol | ||||||||||||
negotiation in order to select a single initator when both peers are | ||||||||||||
acting as such. | ||||||||||||
|
||||||||||||
## The Protocol | ||||||||||||
|
||||||||||||
When a peer acting as the initiator enters protocol negotiation, it | ||||||||||||
sends the string `iamclient` as first protocol selector. If the other | ||||||||||||
peers is a responder or doesn't support the extension, then it | ||||||||||||
responds with `na` and protocol negotiation continues as normal. | ||||||||||||
mxinden marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
If both peers believe they are the initiator, then they both send | ||||||||||||
`iamclient`. If this is the case, they enter an initiator selection | ||||||||||||
phase, where one of the peers is selected to act as the initiator. In | ||||||||||||
order to do so, they both generate a random 256-bit integer and send | ||||||||||||
it as response to the `iamclient` directive, prefixed with the | ||||||||||||
`select:` string. The peer with the highest integer is selected to act | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how should we encode this int? b64? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, this needs to be encoded! Let's do base64. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to mandate base64. |
||||||||||||
as the initator and sends an `initiator` message. The peer with the | ||||||||||||
lowest integer responds with `responder` message and both peers | ||||||||||||
transition to protocol negotiation with a distinct initiator. | ||||||||||||
|
||||||||||||
Note the importance of the prefix in the random integer, as it allows | ||||||||||||
peers to match the selection token and ignore potentially pipelined | ||||||||||||
security protocol negotiation messages. | ||||||||||||
|
||||||||||||
The following schematic illustrates, for the case where A's integer is | ||||||||||||
higher than B's integer: | ||||||||||||
|
||||||||||||
``` | ||||||||||||
A ---> B: iamclient | ||||||||||||
B ---> A: iamclient | ||||||||||||
A: generate random integer IA | ||||||||||||
B: generate random integer IB | ||||||||||||
A ---> B: select:{IA} | ||||||||||||
B ---> A: select:{IB} | ||||||||||||
A ---> B: initiator | ||||||||||||
B ---> A: responder | ||||||||||||
``` | ||||||||||||
|
||||||||||||
In the unlikely case where both peers selected the same integer, they | ||||||||||||
generate a fresh one and enter another round of the protocol. If | ||||||||||||
mxinden marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
multiple rounds of the protocol result in the same integers, this is | ||||||||||||
indicative of a bug and both peers should abort the connection. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The Golang implementation does not retry. See multiformats/go-multistream#42 (comment). |
||||||||||||
|
||||||||||||
## Implementation Considerations | ||||||||||||
|
||||||||||||
The protocol is simple to implement and is backwards compatible with | ||||||||||||
vanilla multistream-select. An important consideration is avoiding RTT | ||||||||||||
overhead in the common case of a single initiator. In this case, the | ||||||||||||
initiator pipelines the security protocol negotiation together with the | ||||||||||||
selection, sending `multistream,iamclient,secproto`. If the receiving | ||||||||||||
peer is a responder, then it replies with `multistream,na,secproto`, | ||||||||||||
negotiating the security protocol without any overhead. | ||||||||||||
|
||||||||||||
If the peer is also a client, then it also sends | ||||||||||||
`multistream,iamclient,secproto`. On seeing the `iamclient` message, | ||||||||||||
both peers enter the initiator selection protocol and ignore the | ||||||||||||
`secproto` in the original packet. They can do so because the random | ||||||||||||
integer is prefixed with the `select:` string, allowing peers to match | ||||||||||||
the selection and ignore pipelined protocols. |
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.
This spec only applies to connection bootstrapping, whereas multistream-select is used in other contexts too (stream-level protocol negotiation). So I'd title this differently, e.g.:
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.
Sure, we can change the title. Go ahead and pick something you like!
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.
Also, this works for UDP too!