Why and How does my peer increases

So I noticed when I run ipfs desktop, it usually starts with peers less than 10…and then over a couple of minutes, this number steady increases…

Question I have are:

  • What is the process that controls this increment in the number of peers a node has?
  • How is this discovery of peers done?
  • Can I control this is some way? For example limit the number of peers? Or say I do not want to connect to some peers?

@finlaybweber

The TLDR is any time you stumble onto a peer, you hold onto them. Once you hit some limit then you remove the “least useful” peers until you’re within the acceptable range of connections.

There are a number of ways this could be done, including:

  • DHT
    • Being a DHT client (the default with IPFS desktop) will cause you to connect to a number of DHT nodes in order to be able to look up data efficiently
    • Being a DHT server (the default with standard go-ipfs if your machine is reachable on the public internet) will cause you to lookup nodes in order to efficiently perform lookups and give peers good responses, and will also receive connections from peers looking for data in the DHT
  • MDNS (enabled by default) will connect to all IPFS (or libp2p) MDNS nodes on your local network
  • Content Providing
    • Looking for providers of content to download (i.e. via the DHT) will connect you to those providers
    • If you have content you are advertising, and are publicly reachable then people will find you (i.e. via the DHT) and connect to you

The reason you see less then 10 immediately, then an increase is that the first ~5-10 immediate connections are done to the bootstrapping nodes hardcoded in your config. Then the DHT peer discovery begins and the number of nodes growth organically.