go-libp2p icon indicating copy to clipboard operation
go-libp2p copied to clipboard

[DRAFT] feat: conntracker

Open MarcoPolo opened this issue 1 year ago • 2 comments

This PR attempts to refactor how NewStream works. Instead of having the swarm be responsible for picking the best connection, and then waiting on identify to run on that connection. We have a separate service that subscribes to connection events and identify events, and the NewStream asks for the best connection that has been identified.

This has a couple of advantages:

  1. We can wait for a Identify to complete on any connection. Not just the one we happen to pick.
  2. It moves connection tracking code out of the swarm into a smaller service that can be tested independently. a. I'd even like to run a fuzz test on the conntracker service itself.
  3. It attaches a peer's supported protocols to the connection itself rather than the peer. a. This allows a peer to say they support protocol X and Y over a connection, and only support Z over another one. This solves a similar problem to labelling connections as "limited", but lets the remote have a say in how we use the connection rather than the local side assuming something. But note that we aren't actually using this just yet. See also https://github.com/libp2p/go-libp2p/issues/2693

This is a draft for now as there are a couple of TODOs in the code, some more tests I want to add, and some thought in how to roll this out (maybe default on, but can disable with an ENV flag for debugging purposes.)

This is also how I think we should build on and improve go-libp2p moving forward. Simple services that share information over an eventbus or channels (depending on the use case).

MarcoPolo avatar Nov 07 '24 23:11 MarcoPolo