Closed t-botclive closed 6 months ago
When new connection is established p2p spawns 2 events in order:
IncomingConnection
providing connection id ConnectionEstablished
providing peer id
When we receive an incoming connection event and limit is reached - disconnecting from peer by using close_connection function does not work, it always returns false
. So we cannot close it at this step.
But when getting ConnectionEstablished
event and having a peer id we can easily verify amount of peers we are already connected to and close it if it exceeds the configured number.
Other than that I haven't found any other way to handle this, there's no function to set this limit during swarm setup step.I could see one potential problem; when a new node tries to join the network, if all existing nodes are already connected to other nodes equal to or more than the limit, the new node won't be able to join.
It's important but not urgent issue so we can mark this as TODO and revisit this later.