What is the proper way to limit connections?

I’m trying to limit the number of peers to n, so I have found the connection manager library which trims down peer connections to some threshold, but the peers just connect again after discovering the peer in the DHT.

How can I simply reject connections, once i have hit the limit, rather than waiting for them to be trimmed in the connection manager?


Still looking for help on this one. There are two parts to this issue:

  • Stop dialing peers once a certain number of peers have been met.
  • Refuse new connections from peers immediately if certain number of peers is met.

Hey @prestonvanloon!

This would require a change to the swarm. We have a limiter component, but it’s only used to throttle in-progress dials. In dialer v1, you’d need to modify the swarm to enforce this limit. With dialer v2, you can just pass a Processor when you construct the dial pipeline. Unfortunately the dialer v2 PR is finished but not merged yet.

Same. This would be a change in the swarm. You could stop the transport listeners when the peer limit is met, or you could close inbound connections immediately.