How do you use ConnectionManager Notifee?

Hi,

I’m trying to use the ConnectionManager Notifee to handle certain events when a new connection occurs. My current progress shows that the ConnectedF method of the notifee is called, but I am having a difficult time communicating on a stream with the peer within this method. The peer never receives the messages sent along the stream and therefore never responds.

More specifically, I’m trying to build out the following workflow for two libp2p clients:

When connecting to a new peer, exchange a message to that peer, and conditionally disconnect from that peer based on the contents of the message.

Example flow of events in my mind:

  • ClientA may have discovered ClientB in a DHT
  • ClientA dials ClientB
  • On connection, open a stream with ClientB on protocol “/v1/example”
  • ClientB has a stream handler for “/v1/example”
  • ClientA sends a message on the stream and ClientB responds

The problem I am having is on the final step. ClientB is not receiving this message in their stream handler.

If you’d like to see the code to understand it, I have a work in progress PR here: https://github.com/prysmaticlabs/prysm/pull/2306

Thanks

Hey @prestonvanloon! Welcome to the forum :wink:

Gonna move this discussion over to the Users forum as it’s more relevant there.

Thanks for linking to the PR. I’m looking at it now :eyes: and will get back to you shortly.

1 Like

I provided indications in the WIP PR, but to close the loop in the forum, here’s the link to the comment:

Hope that helps, and thanks a lot for raising this “experience report” about the go-libp2p API – I’ll feed this into upcoming refactors!

Thanks for the comments!

I suppose if there was any feedback, it would be to make the intention of the connection manager more clear. From the limited information and my intention, I thought “this looks like the perfect API to learn about new connections and act upon them”.

This is actually the second time I have been pointed to the Network() of the host. The first confusion I had was that the peerstore was not actually the list of my peers, but more of an address book of every peer that I had seen. Not sure if there is additional feedback there, but the Network seems to be the canonical way to access information yet the godoc description for Network is simply “Networks returns the Network interface of the Host”, which is not very helpful.

1 Like

Hey @prestonvanloon thanks for the feedback! It’s an especially good time to hear things like this, since we’re in the process of refactoring our core interfaces into a new package, and we’re taking the opportunity to work on docs and the overall developer experience.

I’m actually fairly new to go-libp2p myself, but I have enough experience with js-libp2p that I’ve lost a bit of my “beginners mind” and hearing this kind of feedback is invaluable. Please keep it coming!