There are several implementations of Ethereum clients. How do these clients find each other? What are the algorithms and peer-to-peer protocols involved in this peer discovery process?
A standalone implementation can be found here.
A simplified model of how the p2p algorithm works is the following:
- you have nodes that are assumed to be always available/online (in Ethereum they are called bootstrap nodes)
- bootstrap nodes maintain a list of all nodes that connected to them in a period of time (predefined temporal value, for example last 24 hours)
- when peers (Ethereum client applications such as eth, geth, pyethapp, etc.) connect to the Ethreum network, they first connect to the bootstrap nodes which share the lists of peers that have connected to them in the last predefined time period
- the connecting peers then synchronize with the peers and may prune the connections to the bootstrap nodes since they are no longer essential in peer discovery (the peers can perform discovery on their own)
The accepted answer is not correct. The bootnodes are unreliable. A node can get blacklisted from the bootnodes and the bootnodes are sometimes unavailable without any apparent reason.
The Ethereum network carries forward on its own inertia because peers maintain a history of seed candidates based on past experience. Completely new nodes must join the network by looking for node data, such as on etherscan.
For example my current instance of geth cannot connect to any main net bootnode, but joins the network easily because it has a database of previous nodes.