spec: document optimistic multistream-select (issue #643)#721
spec: document optimistic multistream-select (issue #643)#721Devguru-codes wants to merge 3 commits into
Conversation
Add new Working Draft specification for optimistic (lazy) multistream-select protocol negotiation, documenting the behavior already implemented in go-libp2p and rust-libp2p. - New: connections/optimistic-multistream.md - Modified: connections/README.md (ToC entry + cross-reference) Refs: multiformats/go-multistream#115, multiformats/go-multistream#87, multiformats/go-multistream#20, libp2p/go-libp2p#3038
|
Hello @MarcoPolo, I have created a draft pr so that you can review the work. I also had some doubts while I worked on this.
After the review and my doubts cleared - I will do final fixes and make the pr. Thank you. |
|
hello @MarcoPolo , i am sorry to disturb you, please review my draft and help me with my doubts. Thank you. |
|
hello @MarcoPolo, just a ping to review my work. Thank you. |
|
|
||
| In standard [multistream-select][mss] negotiation, the dialer (initiator) sends | ||
| its protocol proposal and **waits** for the listener (responder) to echo the | ||
| protocol ID back before sending any application data. This costs two full |
There was a problem hiding this comment.
Just one round trip:
A -> <multistream-header> <protocol> -> B
A <- <multistream-header> <protocol> <- B
A -> Application data
There was a problem hiding this comment.
This was my main doubt. I have now updated it to 1 RTT count
| [multistream-select][mss]. Messages are UTF-8 strings, newline-terminated, and | ||
| prefixed with their length as an [unsigned varint][uvarint]. The difference is | ||
| purely in the **sequencing** of messages. | ||
|
|
There was a problem hiding this comment.
| [multistream-select][mss]. Messages are UTF-8 strings, newline-terminated, and | |
| prefixed with their length as an [unsigned varint][uvarint]. The difference is | |
| purely in the **sequencing** of messages. | |
| [multistream-select][mss]. | |
| Both [go-libp2p] and [rust-libp2p] use optimistic negotiation in production, | ||
| but it has not previously been documented in the libp2p specifications. This | ||
| document formalizes the optimization and documents the requirements | ||
| implementations must follow to use it correctly. | ||
|
|
There was a problem hiding this comment.
| Both [go-libp2p] and [rust-libp2p] use optimistic negotiation in production, | |
| but it has not previously been documented in the libp2p specifications. This | |
| document formalizes the optimization and documents the requirements | |
| implementations must follow to use it correctly. |
| Dialer Listener | ||
| | | | ||
| |--- /multistream/1.0.0 ---------------->| | ||
| |<-- /multistream/1.0.0 -----------------| |
There was a problem hiding this comment.
Dialer does not have have to wait to hear back /multistream/1.0.0
|
|
||
| ## Prerequisites | ||
|
|
||
| Optimistic protocol negotiation is inherently **best-effort**. The dialer sends |
There was a problem hiding this comment.
| Optimistic protocol negotiation is inherently **best-effort**. The dialer sends | |
| Optimistic protocol negotiation is inherently optimistic. The dialer sends |
| Implementations SHOULD NOT use optimistic negotiation on the **first** stream | ||
| to a peer when no prior protocol knowledge is available. |
There was a problem hiding this comment.
| Implementations SHOULD NOT use optimistic negotiation on the **first** stream | |
| to a peer when no prior protocol knowledge is available. | |
| Implementations MAY skip optimistic negotiation when no prior protocol knowledge is available. |
| is a pure write/fire-and-forget pattern), the implementation MAY skip reading | ||
| the handshake response. | ||
|
|
||
| 3. **Prior knowledge**: Implementations SHOULD NOT use optimistic negotiation |
There was a problem hiding this comment.
SHOULD NOT is too strong I think. This can be OPTIONAL or MAY
| applies within an already-authenticated peer relationship, where the remote peer | ||
| provides incorrect identify information. | ||
|
|
||
| ## Interaction with Inlined Muxer Negotiation |
There was a problem hiding this comment.
This section should simply say Inlined Muxer Negotiation is preferred.
| - Implementations SHOULD log or track negotiation failures to detect potential | ||
| protocol confusion. | ||
|
|
||
| ## Security Considerations |
There was a problem hiding this comment.
This section doesn't add value. Consider cutting it.
There was a problem hiding this comment.
I have also removed the security considerations section here. If you want me to keep - i will re-write it again. Thank you.
- Fix RTT count: standard negotiation is 1 RTT, not 2 (Comment 1, 4) - Fix both diagrams to show header+protocol sent together - Simplify wire format section (Comment 2) - Remove meta 'not previously documented' paragraph (Comment 3) - Change 'best-effort' to 'optimistic' (Comment 5) - Soften SHOULD NOT to MAY for prior knowledge (Comment 6, 7) - Remove obvious 'Data boundary' requirement (Comment 8) - Simplify inlined muxer section (Comment 9) - Remove Security Considerations section (Comment 10)
|
@MarcoPolo hello, I have addressed and made the updates you suggested in latest commits - i would like you to just see whether the changes are in accordance with what you suggested. Thank you. |
spec: Document optimistic multistream-select
Closes #643
Summary
This PR adds a new Working Draft specification documenting optimistic (lazy) multistream-select — the protocol negotiation optimization already implemented in go-libp2p and rust-libp2p but never formally specified.
What is optimistic multistream-select?
When a dialer knows (via identify) that a peer supports a given protocol, it can skip waiting for the multistream-select echo and send the header, protocol ID, and application data all at once — saving one round trip.
This is critical for latency-sensitive patterns like Kademlia DHT's "one stream per RPC" model.
Changes
New file
connections/optimistic-multistream.md— Full Working Draft specification covering:Modified file
connections/README.md— Added ToC entry, cross-reference subsection under Protocol Negotiation, and link definitionImplementation references
lazyConncloseStopSendingcaused by incomplete lazy handshake