libp2p / developer-meetings

2018 libp2p Developers Meeting in Berlin
7 stars 2 forks source link

[Presentation] libp2p connection flow #12

Open ghost opened 6 years ago

ghost commented 6 years ago

Presentation: What is the connection flow of a libp2p connection? What happens internally and why?

Your Name: Jacob Heun @jacobheun

Session Type (choose one): Presentation

Duration: 30 minutes

Title (a few words): The life of a libp2p connection

Abstract (1 sentence up to a couple paragraphs, as you prefer):

Libp2p connections have a lot going on. It can be difficult to understand what's going on under the hood, and why it's happening. In this talk we'll cover the lifecycle of a connection, along with the many pieces that work together to form that connection and why they exist.

Attendees should leave with a better holistic understanding of libp2p connections and their lifecycle.

JustMaier commented 5 years ago

Is the connection lifecycle documented somewhere? I've looked at the connection spec and it really doesn't talk about it much.

As far as I can tell it's something like this.

  1. Peer is discovered
  2. Peer is manually or automatically dialed (no protocol specified)
  3. Peer is connected, but for data exchange to happen, a protocol should be dialed via dialProtocol, once the protocol connection is open the peers have an active Connection that they can then use to stream data via pull-streams.
  4. (This is where things get fuzzy) I assume it's one of the following: a. The connection remains open until either peer calls hangUp on the other peer. (Does this terminate the non-protocol connection as well?) b. The connection closes at the end of the callback c. A protocol connection is just "logical" a new connection isn't actually opened, instead it just establishes that the data that comes next over the connection is supposed to be handled via that protocol handler.

Any feedback/guidance would be awesome.

JustMaier commented 5 years ago

Just stumbled on this, the talk @jacobheun gave in August `18 on this exact topic, doh. Now to watch it and see if I can answer my own question.


Edit: The video didn't really answer the question, but the more that I think about it and explore examples, it looks like it must be C, that the Connection must just be logical and that it's just passing it to the handler for easy access.

ghost commented 5 years ago

@JustMaier This is a great question to bring over to our discussion boards at https://discuss.libp2p.io/.

In short, yes, streams (protocols) are just logical connections that are multiplexed over a single TCP connection.

JustMaier commented 5 years ago

Thanks @mgoelzer, I'll be sure to keep questions like this over on the discussion boards. Sorry about that. I'll go ahead and post there just so there's a record.

jacobheun commented 5 years ago

I'll follow up on the forum but also closing the circle here, there is a WIP spec to better document the language agnostic lifecycle at https://github.com/libp2p/specs/pull/168. We will also be working on the JS specific implementation docs as we improve the api in the coming months.