-1

I've tried to look for an answer to this online and haven't found any. My question is: how does bitcoin establish a peer to peer network. Establishing a centralized network with a server in the middle between all clients is trivial. However, establishing a fully peer to peer network isn't that easy. This is mostly due to NATs and Firewalls. How does bitcoin core get around NATs and Firewalls. Does it use holepunching, and, if so, is there a central server that dynamically updates public and private Ip/ports? I guess I would just like to know how the peer to peer network is established.

1 Answers1

2

The Bitcoin P2P protocol is an application-specific layer over TCP/IP.

If a node does not have an open port by themselves, they can only make outgoing connections. Node software uses things like UPnP to request NATs to open ports, but if that fails, a node's connections will be unidirectional.

Pieter Wuille
  • 105,497
  • 9
  • 194
  • 308
  • If a node's connection becomes unidirectional, then it can only make requests to other nodes with public IPs and Ports. Is that how unidirectionally connected nodes update their blockchain? – JUAN FELIPE SUÁREZ BURGOS Jul 11 '20 at 19:32
  • Could you briefly elaborate on what UPnP is please. – JUAN FELIPE SUÁREZ BURGOS Jul 11 '20 at 19:33
  • Yes, but the protocol is symmetric. So if a node can only make outbound connections, that is still a fully-featured connection between two nodes - it doesn't matter who established the connection. There isn't a "server" and "client" side to the connection. – Pieter Wuille Jul 11 '20 at 20:23
  • But it does, ultimately, resemble a client server architecture in the sense that nodes that are behind NATs, just like clients in a client server architecture, can only make outgoing transactions but cannot listen to incoming transactions. It's similar to a REST API. – JUAN FELIPE SUÁREZ BURGOS Jul 11 '20 at 21:40
  • 1
    Yes, in terms of connectivity you are right, but not in terms of functionality. If A connects B, then it will be both the case that A requests things from B, and B requests things from A. – Pieter Wuille Jul 11 '20 at 21:41
  • based on my knowledge, bitcoin core connections aren't technically symmetric and there are comments in code that prove this, like on GETADDR message that gets ignored if the sender is a peer different than inbound. So basically a peer that can only have outbound connection will never send other peers its known addresses (this is an example but I think there are other cases where there aren't asymmetric behaviors) – Not Important Jul 12 '20 at 17:47
  • Sure, and transaction relay also works slightly differently in both directions. Still, both parties will learn each other's transactions and blocks. – Pieter Wuille Jul 12 '20 at 17:47
  • 1
    let me go a bit OT @PieterWuille to show gratitude for the effort you put in cryptospace and your attitude you keep showing to help people since long time – Not Important Jul 12 '20 at 18:07