topology-foundation / rs-topology

(currently not usable) The official Rust implementation of Topology Protocol
MIT License
23 stars 5 forks source link

p2p peer limit #38

Closed t-botclive closed 6 months ago

t-botclive commented 6 months ago
t-botclive commented 6 months ago

When new connection is established p2p spawns 2 events in order:

  1. IncomingConnection providing connection id
  2. 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.
jihoonsong commented 6 months ago

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.