libp2p / specs

Technical specifications for the libp2p networking stack
https://libp2p.io
1.58k stars 275 forks source link

Idea: Friendly Streams #500

Open Stebalien opened 1 year ago

Stebalien commented 1 year ago

Libp2p has streams, but they're really annoying:

  1. They take up resources when not in use, so we usually treat them as ephemeral. But this gets really annoying when we want to send ordered messages on a stream that's usually idle (gossip, etc.).
  2. They don't migrate across connections (proposal in #406).
  3. They won't re-try and/or re-form on failure. We have quite a bit of code to try sending a message on a stream, only to open a new stream and re-try.

We should consider adding user-space stream layer that can:

  1. Suspend the underlying transport stream to free all buffers.
  2. Migrates and re-creates streams.
Stebalien commented 1 year ago

Hm. Well, this would require leaving goroutines open. Which isn't great.

Maybe we're really just looking for in-order messages of some form?

Wondertan commented 1 year ago

Hey @Stebalien. I've been working on a Go-specific side project https://github.com/celestiaorg/go-libp2p-messenger, which solves most of the annoying points you've mentioned:

Other points about Messenger:

Stebalien commented 1 year ago

That's exactly what I'm looking for. But I would consider suspending idle streams because we currently have to reserve fairly large receive buffers per-stream (I think?).

Stebalien commented 1 year ago

Ah, wait, that's what your issue is referring to.

Stebalien commented 1 year ago

Are there any ordering guarantees?

Wondertan commented 1 year ago

Yes, as I use native channels there atm

(If I understood your question correctly)

Wondertan commented 1 year ago

(if there are any messenger issues or feature requests, I am happy to collaborate/implement them)