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

Add multigram draft 1 #123

Closed
wants to merge 3 commits into from
Closed

Add multigram draft 1 #123

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 6, 2016

Braindump related to packet switching (ipfs/notes#143).

@ghost ghost added libp2p labels Jul 6, 2016
@ghost ghost assigned jbenet and daviddias Jul 6, 2016
@jbenet jbenet added the status/in-progress In progress label Jul 6, 2016
@ghost ghost mentioned this pull request Jul 6, 2016
@ghost
Copy link
Author

ghost commented Jul 6, 2016

I'd be grateful for pointers to prior art, and most of all people who review this, point out open questions, etc. :)

@@ -0,0 +1,96 @@
# Multigram -- protocol negotiation and multiplexing over datagrams

For multiplexing different protocols on the same datagram connection, multigram prepends a 1-byte header to every packet. This header represents an index in a table of protocols shared between both endpoints. This protocol table is negotiated by exchanging the intersection of the endpoint's supported protocols. The protocol table's size of 256 tuples can be increased by nesting multiple multigram headers.
Copy link
Member

Choose a reason for hiding this comment

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

Why not use a varint instead of a single byte?

Copy link
Author

Choose a reason for hiding this comment

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

Parsing is not so much a problem, but the per-packet overhead should be constant -- for some cases, we'll want to inform the upper protocols about the overhead, so they can avoid fragmentation, or batch multiple small messages into one packet.

We could fit a larger table into to 2 bytes, but I expect that a connection with more than 255 protocols on the same layer will be extremely rare. These two bytes multiply the deeper you nest protocols, in IPFS we currently have 3 layers of multistream I think?

Does this make any sense?

Copy link
Author

Choose a reason for hiding this comment

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

The maximum packet size would be bubbled up from the transports through all the protocol wrappers, e.g. 512 (UDP) - 1 (multigram) - 20 (cryptoauth) - 1 (multigram) - 12 (switch) - 1 (multigram) = 477

Copy link
Member

Choose a reason for hiding this comment

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

hrm... okay. I see the importance of the single byte, but you do mention that you can 'expand' the table by nesting. Nesting seems more complicated than using a varint and informing other layers how much space they have left to consume

Copy link
Author

Choose a reason for hiding this comment

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

Yes, with a good night's sleep, you're absolutely right.

Copy link
Author

Choose a reason for hiding this comment

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

To explain what my concern was: I was thinking the varint width would vary on a packet-per-packet basis, while it'll really only change if you add protocols to the protocol table (i.e. change the multigram connection's state).

Copy link
Member

@Kubuxu Kubuxu Jul 8, 2016

Choose a reason for hiding this comment

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

I think varint will make packet handling more complex then it should be, you introduce offset handling and unframing that depends on the state of connection.
If the state goes desync for what ever reason getting it back to sync will be extremely hard.
Having constant header file is very nice feature.

Also 255 overlay protocols (that are negotiated on need basis should be more than enough, if more is needed, layering is still an option).

Copy link
Author

Choose a reason for hiding this comment

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

Mh yep we're trading off between a complication of header parsing, and a complication of protocol semantics. We should decide whether we favor performance (int8 field and nested multigrams) over a simpler protocol (varint and no nesting).

We should figure out exactly how complicated nesting is (make experiments), and also how heavy parsing a varint is vs. an int8 (benchmarks). My gut feeling is that we should probably go with an int8, because we'll have to do this for every packet, and multiple times per packet in many use cases.

Not-so-appealing idea: a varint degrades to an int8 nicely, so there might a way to leave it up to implementations.

@ghost
Copy link
Author

ghost commented Jul 8, 2016

todo

  • decide int8 vs. varint
    • nesting experiment
    • int8 vs. varint benchmarks
  • decide on /multigram-setup formats
  • research prior art on table replication
  • elaborate on the table operations
    • the exact operations
    • the reason for table operations (packets are small, so in bigger use cases, the table has to be fragmented)
  • success responses
  • error responses
  • ability to reset the table?

@RichardLitt
Copy link
Member

This should be added to the now stubbed out https://github.com/multiformats/multigram, and work should continue there.

@ghost ghost unassigned jbenet and daviddias Aug 24, 2016
@ghost
Copy link
Author

ghost commented Aug 24, 2016

Will open another PR at https://github.com/multiformats/multigram -- plenty of great changes resulted from the discussions had in Lisbon.

@ghost ghost closed this Aug 24, 2016
@ghost ghost removed status/in-progress In progress labels Aug 24, 2016
@ben221199
Copy link

Is multigram still a thing or should it be deprecated? In that case, the https://github.com/multiformats/multigram should be archived and the README of https://github.com/multiformats/multiformats and the website should be updated. The last activity was around 2016/2017.

@rvagg
Copy link
Member

rvagg commented Aug 8, 2022

@marten-seemann @mxinden thoughts? If we're not using it I agree with @ben221199 that we should make it clear they're not an ongoing concern.

@mxinden
Copy link

mxinden commented Aug 9, 2022

Thanks for the ping @rvagg. I have not been aware of the multigram project.

With QUIC and libp2p/specs#349 I don't see us pushing for a datagram based protocol negotiation protocol any time soon. Thus I am fine with marking this effort deprecated.

@rvagg
Copy link
Member

rvagg commented Aug 11, 2022

archived it, thanks for raising it @ben221199

@ben221199
Copy link

Maybe I can also make a pull request for https://github.com/multiformats/website.

@marten-seemann
Copy link
Member

Sorry for the late reply. I agree with closing / archiving.

Datagram transports are probably better implemented on top of QUIC, which provides native datagrams (encrypted, congestion controlled, forward-secure) at the transport level.

This pull request was closed.
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.

9 participants