Description
Creating this per discussion on ChainSafe/js-libp2p-gossipsub#87 (comment)
There are currently a few inconsistencies with the ConnectionManager events that need to be solved:
it seems that there are some problems with our current approach of updating IPs, and it seems the events currently emitted by the connection manager are not sufficient for tracking IPs to open connections for peers with scores.
issue 1: ConnectionManager doesn't emit on closed connections. ConnectionManager#_maybeDisconnectOne, doesn't emit when a connection is closed, more generally, ConnectionManager isn't tracking/emitting on manually closed connections, but rather only on calls to ConnectionManager#onDisconnect.
issue 2: ConnectionManager emits peer:connect event before storing the emitted connection.
The current approach is to use ConnectionManager#getAll on each peer:connect event for a list of current IPs, but since the event is triggered before the new connection is stored, the call to getAll will not include the new connection unless the event handler awaits the ConnectionManager#onConnect finishing in its entirety. But that potentially also runs into issues re issue 1.
cc @wemeetagain