Search code examples
bitcoinmesh-network

How do two Bitcoin clients discover each other?


I'm interested in how two peer-to-peer clients can join each other in a mesh network like Bitcoin clients can.

So when I fire up Bitcoin, how is my client joining all the others? How does it find the very first peer (who probably knows where others are)?

Thanks!


Solution

  • Bitcoin clients use several methods to locate other clients. The primary method is a list of nodes from a previous connection to the network. The works very well for everything but your first connection or a connection after a very long period of disconnection.

    For the case where you have no previous known IPs or they aren't usable, the primary fallback method is by DNS seeds. Several host names (such as dnsseed.bluematt.me) are maintained that resolve to a list of IP addresses known to be running nodes. Should that fail, the client has a list of IP addresses believed to point to stable nodes hard-coded into it.

    One method that used to be used, but that has since been abandoned, was having the clients locate each other using an IRC server. That worked similar to a BitTorrent tracker.

    Once you are connected to the network, you will begin to receive lists of IP addresses and ports of known clients.

    Source: https://bitcoin.stackexchange.com/questions/3536/how-bitcoin-clients-find-each-other