There are a lot of crap flying around about the Bitcoin. Is it going to crush down? Is it worthless? Why did prices go down? Hell I know! Maybe people just found out “cryptocurrency” doesn’t mean “privacy” and all history of transactions are public and it’s matter of time to find out who did which transaction? Who knows… Don’t even ask me these questions, Bitcoin is a nice introduction to the thriving market of numbers aka fintech. But, what I care the most is the technology behind.
I am fine with BTC “distributed” database (blockchain, probably only cats haven’t heard about “blockchain”). Each node currently stores about 20G of transactions. It’s the same gigantic ledger for every one. Well it’s not the redundancy I would normally approve but whatever - it’s about money. “Storing money has to be expensive” - said banker.
Regardless to the market problems, do you know how your Bitcoin node connects to other nodes? I did not.
For me, JVM-based software engineer, this code looks quite unfamiliar at the first glance. I don’t think idiots wrote it though. Anyway, the code is straightforward:
read peers (other nodes) from parameters passed to the application
load a list from peers.dat file if exists
resolve DNS in order to get the public nodes
load fixed addresses
Sounds ridiculous, no? It looks like there are actually nodes that are not distributed but there are few points where node can connect. Nice! It completely destroys my view of magic distributed system.
Loading parameters from args and file are dull so I will leave them without a comment. More important thing is what happening if we don’t know locations of other nodes at all.
Loading from DNS
Here is the code. Few DNS are pre-defined and the actual lookup request is happening. What might be the problem? Well, if you are not VPN your DNS requests (which are UDPs) you can get caught or at least identified by your ISP. Not that safe, huh?
I am not a network expert, but can you spoof this addresses as being in control over your home network? Let me know in a comments, really appreciate!
Well, many of them. Guess what? They are automatically generated with a python script. There is a file contrib/seeds/nodes_main.txt that actually contains all addresses and it’s just getting translated into but arrays. How clever is that?
There is no secret broadcasting or magic in making connection between two nodes through the Internet. All the things are related to DNS or fixed IP stuff.
I have to admit, all P2P network-ish things were magic to me. I spent two-three evenings to understand this thing. It doesn’t look like a major magic or rocket science anymore. I recommend you to check out the code “really important” (well, they are still brainiacs I admit) people wrote. For fun, for learning and for being better. That’s a good sign that also just “regular” people like me can do a contribution to the World. I should keep trying :).