Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the bitcoin client determine the first IP address to connect?

Tags:

p2p

bitcoin

In my knowledge, bitcoin is a p2p protocol and a p2p protocol must have a dedicated central server. But it is said that bitcoin is decentralized.

like image 479
Divlaker Avatar asked Jan 16 '17 09:01

Divlaker


People also ask

How does a bitcoin client connect to the network?

How can I join the network? That's the spirit. All you need to do is download (and run) a bitcoin client. When you run the client it will connect to other nodes and start downloading a full copy of the blockchain (the file that contains all the verified transactions).

How do bitcoin clients find each other?

Peers discovery in BTC network The primary way to discover peers in the bitcoin network is to connect to a list of BTC nodes that are previously connected. However, for the initial connection, the node has to use a publicly known DNS feed to retrieve a list of IP addresses of long-running stable nodes.

How do bitcoin nodes connect to each other?

To connect to a known peer, nodes establish a TCP connection, usually to port 8333 (the port generally known as the one used by bitcoin), or an alternative port if one is provided.

How does the bitcoin P2P network work?

The bitcoin network is a peer-to-peer payment network that operates on a cryptographic protocol. Users send and receive bitcoins, the units of currency, by broadcasting digitally signed messages to the network using bitcoin cryptocurrency wallet software.


1 Answers

Back in 2009 we relied on IRC to bootstrap the network, so every node would connect to Freenode (later LFnet) and would join a channel. Their nicknames were their encoded public IP address.

Nowadays the Bitcoin Core client, and many other implementations, rely on DNS seeds. DNS seeds are special DNS servers that are configured to return a number of randomly selected nodes from the network. The operators of the DNS seeds also run crawlers to enumerate the publicly reachable nodes that are to be returned by the seeds.

The seeds that are currently included in the Bitcoin Core client are:

  • bitcoin.sipa.be
  • dnsseed.bluematt.me
  • dnsseed.bitcoin.dashjr.org
  • seed.bitcoinstats.com
  • bitseed.xf2.org
  • bitcoin.jonasschnelli.ch

If you send a request to any of these servers they will return a number of random IPs that are known to run Bitcoin on port 8333:

dig seed.bitcoinstats.com +short
71.19.155.244
173.254.232.51
45.79.97.30
198.252.112.64
35.128.8.141
108.17.18.165
98.208.76.134
8.29.28.12
52.62.2.124
96.234.214.85
47.89.24.56
212.164.215.159
52.62.42.229
68.52.96.191
115.66.205.171
24.250.16.39
201.43.160.155
5.3.253.18
100.40.179.172
50.135.169.181
186.149.249.18
101.201.44.207
96.35.97.46
124.188.118.196
82.8.4.79

Besides the DNS seeds, the Core client also has a static list of IPs to try first and it will cache any previously contacted peers in a local database in order to reconnect without having to query the DNS seeds.

(Disclaimer: I am the operator of one of the DNS seeds)

like image 180
cdecker Avatar answered Oct 20 '22 00:10

cdecker