From the Java perspective block chain Practice Series 3 - P2P Networks: The Evolution of the block chain P2P network topology

In this section I will start a network connection to introduce several mainstream chain block p2p network structure, so that we understand the block chain network more deep-seated.

Internet connection

Fi is an application-level interconnection network. Everywhere in our lives, such as: Mobile Wifi wireless network that people use, a little switch network. Network connection type defines the number of network connection devices and methods, and to determine the communication mechanism of network. Only network connection type and a multi-point connection connecting the two physically.

Point connection

Point to point connection, this involves only two network devices, e.g., interconnected data transmission between two laptops.

Multipoint connection

As the name suggests, refers to a network connection is provided between three or more devices. Computer networks are generally multi-point connections.

Except for data transmission between machines connected by a network transport layer protocol, except for a small number of the current program block chain using the UDP protocol, most of them use TCP / IP protocol.

P2P network topology

P2P stands for "peer-to-peer", by definition, the nodes connected to the network between nodes on the network. Nodes in the network, both the service provider resources, but also the recipients, which means that each node in the network to provide common services between nodes are equal, there is no "special" nodes.

P2P network technology to solve two problems, one resource locator, the second is resource acquisition. P2P network topology is roughly divided into four centralized, fully distributed unstructured, fully distributed architecture, semi-distributed.

Centralized topology

That there is a central node holds all the other nodes of the index information, the index information generally includes the node IP address, port, node resources. QQ is similar to such a network topology.

Centralized topology

Shortcoming

1, prone to performance bottlenecks node of the expansion;

2, there is a single point of failure, paralysis of the central index server easily lead to collapse of the entire network and thus lower the reliability and safety.

More suitable for a small network, the finite amplify large networks.

Fully distributed unstructured topology

I.e., between a node and a new node is added random P2P network to establish a connection path, so as to form a random topology.

Transmission between the node and the node closer to " flooding algorithm " , namely: the transaction is generated from a node, then broadcast to neighboring nodes, nodes close to a pass 10 10 Fax 100 until it spread to the entire network.

Different from the centralized topology, he has no central server, each machine is a true peer relationships in the network.

Fully distributed unstructured P2P network topology

Shortcoming

1, since the network is unstructured, and therefore a fully random graph, the link between nodes do not follow predefined topology, it generally does not provide any performance guarantee total;

2, there is a partition, chain cleavage;

advantage

Fault-tolerance, and adding a few nodes frequently exit effect on small systems

Fully distributed architecture of the topology

Fully Distributed structured P2P network topology is to use a distributed hash table (Distributed Hash Table, abbreviated as DHT) techniques to organize nodes in the network can be achieved by a structured network of such techniques, for example, a representative algorithm Tapestry, Pastry, Chord and CAN.

Pastry  is a scalable, distributed object location and routing protocol proposed by Microsoft Research, can be used to build large-scale P2P systems. In Pastry, each node 128 is assigned a node identifier number (nodeID), all node identifiers nodeID an annular space is formed, ranging from 0 to 2128 - 1 node is added by the dispersion system column node randomly assigned IP address space 128 nodeID.

Pastry

Semi-distributed topology

Centralized and distributed hybrid configuration , as shown, the network comprises a plurality of super nodes composed of a distributed network, and each of the plurality of supernode ordinary nodes and it is composed of a local centralized network.

A new common node is added, the first select a super-node communication, the supernode push again other super node list to a newly added node, adding the node to decide which particular super node selected as a parent node according to the super node status list .

Semi-distributed topology

This structure of the flooding broadcast occurs only between super nodes , to avoid large-scale flooding problems. In practice, the hybrid structure is relatively flexible and more effective network architecture, implementation difficulty is relatively small, so there are more systems are being developed to achieve a hybrid-type structure. In fact, the Bitcoin network is now such a structure.

Ok, we have more detailed explanation of the P2P network topology, then entered, we Bitcoin P2P network as an example, then we appeal it and what difference does it say?

First, we know that, P2P is a peer to peer network, since it is the point, then there is the discovery node (positioning) and interaction, then we will explain the two parts.

Network node discovery

Node discovery is the first step of any block access node chain block chain P2P networks. Node Discovery can be divided into an initial node discovery and node discovery after startup .

Initialization node discovery

Generally divided into two types, DNS-send and hard-code.

1, DNS way : Find a domain name will be the center of initialization, the Bitcoin community defenders will maintain some domain names.

2, hard coded : hard-coded in the code number of addresses, which we call the child nodes, the connection initialization attempts. When all seeds of all the nodes fails, all nodes will attempt to connect these seeds nodes.

After starting node discovery

In the Bitcoin network, a node can maintain their own list of peers (peer list) is sent to neighbor nodes, the nodes after the initial discovery, the first thing you need to do is to the other node to the list .

Place in an Ethernet network, also maintains a similar list of nodes (NodeTable), but this list of nodes with different Bitcoin simple maintenance, which uses a P2P network protocols a sophisticated algorithm, called Kademlia network, referred KAD network.

It uses DHT to locate resources, stands for Distributed Hash Table, the Chinese called distributed hash table. KAD network maintains a routing table used to quickly locate the target node. Since KAD network based on the UDP protocol, the node of an Ethernet node discovery is based on the square, if the node finds later, will switch to the data exchange protocol UDP, TCP.

Resource Locator - LAN penetration

P2P network architecture block chain is a fully distributed topology . But now our network environment is composed by a local area network and the Internet. So how do you find public Internet node node deployed in the LAN it?

If the LAN is that you can control, that's fine to say, only need to configure routing VPC network, map the public IP and port to your IP and port to the LAN ( intranet penetration ) .

If it is not controlled and how to do it? Way is NAT UPnP technology and protocols .

Briefly NAT technology, is to replace T the CP packet source address and mapped to the internal network.

U P nP is Universal Plug and Play (Universal Plug and Play) It is mainly used abbreviation for intelligent interconnection devices, all devices on the network can immediately know when a new device is added.

Bitcoin Square and Ethernet are used as LAN UPnP protocol penetrating tool, as long as the LAN routing device supports NAT gateway function supports UPnP protocol, you can automatically map your block chain node to the public network.

Resources - interaction protocol between nodes

Once the node connection is established, the interaction between nodes is to follow some specific commands , these commands are written in the message header, message body is written in the message content.

Command is divided into two, one is a request command (the Ping) An interactive command data (Pong) .

The first thing after the node is connected to a handshake . This process on Bitcoin and Ethernet Square is about the same, that is to say hello to each other, to provide some brief information. For example, to swap the version number to see if it's compatible. Ethernet provides only Square symmetric encryption handshake process, no bit credits.

In this way (shaking hands), peer node obtains a list of nodes that can be connected, and it will also publish their own messages to other network nodes to look for. Node node information locally will save the last sync peer connection, so it can be quickly and previous peer node to re-establish the connection when a node restart.

Ping mechanism can maintain connections between nodes, if a node persistent connection for up to 90 minutes without any communication, it will be deemed to have been disconnected from the network, the network will start looking for a new peer node. Thus, the bit will be credits network node and the network change with the organic dynamic adjustment, without the need for centralized control, which is made to the center .

to sum up

In this section we explain our main P2P evolution of history, we understand Bitcoin P2P communications network basis, in the next section we will discuss their different ways according to the different communication nodes.

 

references:

"Mastering Bitcoin Second Edition"

P2P network topology

Block 100 asks chain

 

Published 18 original articles · won praise 11 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_38652136/article/details/105145816