How a New Bitcoin Node Find Peers in the Bitcoin Network

The Bitcoin network is a decentralized network of linked nodes.

A new node must locate peers and establish a connection with them in order to join the network.

I'll explain to you in this post how a new node in the bitcoin network connects to an already-existing peer node.

Network Discovery

To participate, a newly booted node has to locate other bitcoin nodes in the network. A new node must find and connect to at least one active node on the network in order to initiate this procedure.

Nodes create a TCP connection to a known peer, typically to port 8333 (which is commonly recognized as the port utilized by Bitcoin).

As soon as a connection is made, the node will transmit a version message, which comprises basic identifying information, to initiate a "handshake".

Any peer's initial message to another peer is always the version message. Upon receiving a version message, the local peer will check the reported version of the remote peer to determine compatibility. The local peer will send a message to establish a connection and acknowledge the version message if the remote peer is compliant.

Connecting to Node via DNS Seed

DNS, or domain name server, contains a list of IP addresses belonging to bitcoin nodes that are known to exist.

Node IP addresses are what DNS seeds resolve to. Because a node might leave and rejoin the network at any time, the collection of IP addresses you receive back is always changing.

In order to obtain a list of the accessible IP addresses of known node peers in the bitcoin network, the New Node queries the DNS server.

A connection attempt is made between the new node and any of the return node lists for DNS queries once it has access to the list of IP addresses of known nodes in the network.

Connecting to Node Via -seednode Alternatively if you don’t want to use DNS Seed, you can connect your new node with an existing node in the network by providing the IP address of the node at boot up

-seednode argument allow new node connect to the bitcoin network via know node which in turn introduce the new node to introduce the new node to other node in the network.

Communication with Node

The new node will send its neighbors an addr message with its own IP address once it has made one or more connections. In turn, the neighbors will tell their neighbors about the newly linked node, making it more widely known and more strongly connected.

The newly connected node can also ask its neighbors to produce a list of IP addresses of other peers by sending them the command getaddr.

To provide distinct routes into the Bitcoin network, a node needs to establish connections with a few different peers. The node must continue to find new nodes as it loses old connections and help other nodes bootstrap because paths are unreliable due to nodes coming and going.

Because the initial node can introduce itself to its peer nodes and those peers can introduce you to others, bootstrapping only requires one connection.

Furthermore, establishing connections with more than a few nodes is pointless and wasteful of network resources. A node that has successfully bootstrapped will retain its most recent successful peer connections, enabling it to rapidly reconnect to its previous peer network in the event of a reboot

If there is no traffic on a connection, nodes will periodically send a message to maintain the connection. If a node has not communicated on a connection for too long, it is assumed to be disconnected and a new peer will be sought.

The network dynamically adjusts to transient nodes and network problems and can organically grow and shrink as needed without any central control.

Conclusion

This process explain what every node does when trying to join the bitcoin network.