您的位置:首页 > 其它

MGC TOKEN technical explanation —— P2P network (distributed peer-to-peer network)

2019-02-15 14:43 162 查看

P2P network and communication mechanism
MGC Token Advantage
MGC Token is positioned on an application platform where smart contracts can be released and data can be interacted with and processed by other external IT systems for a variety of industry applications.
The network layer mainly realizes the connection and communication of network nodes, also known as peer-to-peer technology. It is an Internet system that does not have a central se 4000 rver and exchanges information by user groups.
KAD Introduction
Kademlia was proposed by PetarP.Manmounkov and David Mazieres of New York University in 2002 as a distributed hash table (DHT) technology. It uses XOR as the basis of distance measurement and has been applied in BitTorrent, BitComet, Emule and other software.
K barrel
Kad’s routing table is constructed by data called K bucket, which records information such as NodeId, distance, endpoint, and ip. The Ethereum K bucket is sorted according to the distance from the target node, a total of 256 K buckets, and each K bucket contains 16 nodes.

Technical construction
MGC Token application technology is a technology for constructing Bitcoin blockchain network and transaction information encryption transmission. It is based on cryptography and not based on credit, so that any agreed parties can make direct payments without any participation of third party agents.
The blockchain is a distributed ledger and the MGC Token is decentralized. The way to trust collectively maintains a technical solution for a reliable database. From a data point of view, the blockchain is a distributed database that is almost impossible to change, so the MGC Token is not only embodied as distributed storage of data, but also The distributed records embodied in data will be jointly maintained by system participants. MGC Token is not a single technology, but a combination of multiple technologies. These technologies are combined with new structures to form a new type. The way data is recorded, stored, and expressed.
Open, consensus
Anyone can participate in the MGC Token block network. Each user device can act as a node. Each node is allowed to obtain a complete database copy. The nodes are jointly maintained by competitive computing based on a set of consensus mechanisms. Integrate the blockchain carrier, any one node fails, and the remaining nodes can still operate normally.
Decentralization
MGC Token does not have centralized devices and management organizations. Data exchange between nodes is verified by digital signature technology. There is no need to trust each other. As long as the rules are established according to the system, nodes cannot deceive other nodes.
MGC Token network layer
The basic network layer consists of a data layer and a network layer. The data layer includes the underlying data block and related data encryption and time stamping technologies. The network layer also includes a distributed networking mechanism, a data propagation mechanism, and a data verification mechanism.

MGC Token core technology: block + chain
Technically speaking, a block is a data structure that records transactions, reflecting the flow of funds in a transaction. The blocks of the transaction that have been reached in the system are joined together to form a main chain, and all the nodes involved in the calculation record a part of the main chain or the main chain.
Each block consists of a block header and a block body. The block body is only responsible for recording all transaction information for a period of time, including the transaction quantity and transaction details; the block header encapsulates the current version number and the previous block. Address, timestamp (recording the time the block was generated, accurate to the second), random number (recording the value of the answer to the block to solve the math problem), the target hash of the current block, the root value of the Merkle number, etc. information. From a structural point of view, most of the functions of the blockchain are implemented by the block header.

MGC Token core technology: hash function
The hash function converts data of any length into a set of fixed-length code via the Hash algorithm. The principle is based on a cryptographic one-way hash function that is easily verified but hard to crack. Usually the industry uses y =hash(x) to implement a calculation of x to calculate a hash value y.
Commonly used hash algorithms include MD5, SHA-1, SHA-256, SHA-384, and SHA-512. Taking the SHA256 algorithm as an example, entering any string of data into SHA256 will result in a 256-bit hash value (hash value). Its characteristics: the same data input will get the same result. As long as the input data changes slightly (for example, a 1 becomes 0), a completely different result will be obtained, and the result cannot be predicted in advance. Positive calculations (calculating their corresponding hash values from the data) are very easy. Reverse calculation (cracking) is extremely difficult and is considered impossible under current technological conditions.
MGC Token core technology: Merkle tree
The Merkle tree is a hash binary tree that can be used to quickly verify the integrity of large-scale data. In the blockchain network, the Merkle tree is used to summarize all the transaction information in a block, and finally generate a uniform hash value of all the transaction information of the block. Any change in the transaction information in the block will make Merkle Tree Change
MGC Token core technology: P2P network
P2P networks (peer-to-peer networks), also known as peer-to-peer technologies, are Internet systems that do not have a central server and rely on user groups to exchange information. Unlike a central network system with a central server, each client of a peer-to-peer network is both a node and a server.
Kad communication protocol
The inter-node communication in the Ethereum Kad network is based on UDP, and is mainly composed of the following commands. If the PING-PONG handshake between two nodes passes, the corresponding node is considered to be online.

P2P networks are characterized by decentralization and robustness.
Decentralization: Resources and services in the network are scattered across all nodes. The transmission of information and the implementation of services are carried out directly between nodes, without the intervention of intermediate links and servers.
Robustness: The P2P architecture is inherently resistant to attack and high fault tolerance. Since the service is distributed between nodes, the destruction of some nodes or networks has little effect on other parts.
In the C++ version of the Ethereum source code, the NodeTable is a key class of the E2P2 P2P network. All the data and methods related to the neighbor nodes are implemented by the NodeTable class.

Neighbor node discovery method
Neighbor nodes are nodes that are added to the K bucket and handshake through the PING-PONG.

Neighbor node discovery process description:
The system first starts to randomly generate the local node NodeId, which is recorded as LocalId, and will be fixed after generation.
2. The local node is recorded as local-eth.
3. The system reads the public node information, and after the ping-pong handshake is completed, it is written to the K bucket.
4. The system refreshes the K bucket every 7200ms.
The process of refreshing the K bucket is as follows:
A randomly generates the target node Id, recorded as TargetId, and records the number of discovery and refresh time from 1.
B Calculate the distance between TargetId and LocalId, denoted as Dlt
The NodeId of the node in the C K bucket is recorded as KadId, and the distance between KadId and TargetId is calculated, which is recorded as Dkt.
D Find the node in the K bucket whose Dlt is greater than Dkt, denoted as the k bucket node, and send the FindNOD to the k bucket node.
Command, the FindNODE command contains the TargetId,
After the E K bucket node receives the FindNODE command, it also performs the b-d process, and the node found from the K bucket is sent back to the local node using the Neighbours command.
F After the local node receives the Neighbours, it writes the received node to the K bucket.
G If the number of searches does not exceed 8 times and the refresh time does not exceed 600ms, return to step b to execute the loop.

Neighbor node network topology and refresh mechanism

P2p (peer-to-peer) is the node-to-node connection on the network. This is a type of network topology. The node here is an application running on a computer or mobile device that implements a consistent p2p communication protocol. As shown in the figure above, when your computer or mobile device (such as peer 7) there are generally two ways to join the p2p network:

  1. A peer node that is already in the active state and is in the active state is known. After connecting with the peer node, the peer will share the connection information of the entire p2p network.
    2 There is a tracker server. Before entering the p2p network, first access the tracker server to obtain information about all nodes of the p2p network, and then connect the peers according to the peer information obtained from the tracker, and then join the p2p network.
    For example, DHT (Distributed Hash Table) adopts the first access method (the Kademlia-like algorithm adopted by Ethereum is an implementation algorithm of DHT), and most p2p protocol applications have the existence of class tracker server, tracker itself. It is a known network center. The tracker is not available, or the known peer node has been offline inactive, and there is no way to enter the p2p network.
    Therefore, I personally think that only when the peer joins the p2p network (I understand this p2p network without considering the access method, which is a narrow p2p network) is the real decentralization. But the access of p2p network is also one of the important links of p2p communication protocol, so …
    Decentralization of the narrow p2p network protocol
    Compared with the traditional C/S network architecture, the most important feature of the p2p architecture is that the peers in the network are equal in status and function. Although each peer may handle different requests, the actual resources provided will vary after specific quantification, but they both consume resources and provide resources. If all resources (including but not limited to computing power, storage space, network bandwidth, etc.) in the entire p2p network are regarded as a total amount, the resource distribution in the p2p network is dispersed in each peer. From this point of rough, the p2p network architecture is naturally decentralized and distributed.
    In p2p networks, peer connections can be divided into unstructured and structured. Here is a brief introduction, the advantage of the unstructured p2p network is that it is easy to set up and has no structural requirements on the network. Even if a large number of peers join the network at the same time or leave the line, the whole network will be stable. The advantage of structuring is that data query efficiency is high.
    Ethereum’s p2p protocol
    Ethereum’s p2p network features:
    There may be some cases in the network where individuals join and leave the network at any time, but the probability of a large number of new and old individuals joining or leaving at the same time is very low.
    Ideally, the data stored in each block should be the same. However, the actual situation will be caused by the delay of the broadcast synchronization, resulting in inconsistent data in the block. Designing the communication mechanism is of course a desire to be as consistent as possible. Therefore, in the Ethereum p2p network, when searching for data, it is not necessary to improve efficiency for certain specific areas, and it is not necessary to send a request to the entire network.
    Protocol management module ProtocolManager for p2p communication

    In Ethereum, the top-level structure for managing p2p communication is called eth.ProtocolManager, which is also one of the core member variables of eth.Ethereum. The UML relationship is as follows:

    The peertSet indicates that the neighbor peer list is cached, and the peer in the peerSet map represents a remote node in the network.

    The ProtocolManager receives and sends data updates including transactions and blocks through various channels (newPeerCh, txsyncCh, quitSync, noMorePeers) and event subscriptions (eventMux, txSub, minedBlockSub).
    Fetcher stores Announce messages about all new data sent by other peers, and processes the corresponding fetch requests after its own comparison.

    Downloader is responsible for all the synchronization processes initiated to neighboring peers.
    In Ethereum’s p2p network, all the two peers that communicate must be first registered with each other and added to the respective peer list of peers, that is, the peerSet object. Such two peers can be called It is “adjacent”. Therefore, as long as two peers are in a communicable state, they must be “adjacent”.

    Start(maxPeers int): Enable p2p network
    The Start(maxPeers int) function is the startup function of the ProtocolManager, which is actively called in eth.Ethereum.Start(maxPeers). ProtocolManager.Start(maxPeers) will enable 4 goroutines to execute 4 functions separately.

    pm.txBroadcastLoop()

    pm.minedBroadcastLoop()

    pm.syncer()


pm.txsyncLoop()

The above four goroutines are processes in which the ProtocolManager actively initiates information to neighboring peers. It can be seen that the communication initiated by other peers can be divided into two categories according to the data type: transaction tx and block block; and according to the communication method, it can also be divided into broadcasting a new single data and synchronizing a group of the same type. Data, such a simple pairwise pairing, can form the above four-stage process.

Handle(p *peer): callback function of the adjacent peer
For peer-to-peer communication, in addition to actively initiating communication to the peer peer (such as the four goroutines started in Start()), a data transmission initiated by the peer peer is required. This transmission is not only by the other party. The peer sends it to the other party. More usage is that the peer sends a function to let the other party send some specific data to them. This type of communication is suitable for implementation in code implementation with callbacks.
ProtocolManager.handle() is a function that embeds each p2p.Protocol object as a callback function when the ProtocolManager object is created (implementing the Protocol.Run() method). Then, whenever there is a new peer to establish communication with the other party, if the other party can support the protocol, then both parties can successfully establish and start communication.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐