Ethereum Source: Peer network and node discovery mechanism

Source: Internet
Author: User

Http://mp.weixin.qq.com/s/_hNFvgOdBp1Z8ecWc6X8rg

Directory

1 Introduction to Distributed networks

1.1 Kad net Introduction

1.2 Kad network node distance

1.3 k Barrels

1.4 Kad Communication protocol

2 Neighbor Nodes

Main members of the 2.1 nodetable class

2.2 Neighbor Node Discovery method

2.3 Neighbor node network topology and refresh mechanism.

1 Introduction to Distributed networks

Ethereum is the bottom-level distributed network, which uses the classic Kademlia network, referred to as Kad.


1.1 Kad Net Introduction

Presented by Petarp.manmounkov and Davidmazieres of the University of New York in 2002, Kademlia is a distributed hash list (DHT) technology that is based on a distance metric of XOR or operation and has been BitTorrent, BitComet, Application in emule and other software.


1.2 Kad network node distance

Ethernet network Node distance calculation method:

NODE1: Node 1 NodeId

Node2: Node 2 NodeId


1.3 k Barrels

The routing table of Kad is constructed by the data called K-bucket, and the K-bucket records information such as node Nodeid,distance,endpoint,ip. Ethereum k barrels are sorted by distance from the target node, with a total of 256 k barrels, each containing 16 nodes.

Figure 1.1 1.4 Kad communication protocol

The communication between nodes in Ethereum Kad network is based on UDP, which is mainly composed of the following commands, if the ping-pong handshake between two nodes is passed, the corresponding node is considered to be online.

Kad communication protocol, UDP-based

Serial number

Classification

Function description

Constitute

1

PING

Probe a node to determine if it is online

struct Pingnode

p> {

         h256  version = 0x3;

         Endpoint  from;

         Endpoint  to;

         uint32_t  timestamp;

};

2

PONG

Ping command response

 struct PONG 
 {
      
                         Endpoint to; 
                         h256 Echo; 
                         uint32_t timestamp; 
}; 

3

FINDNODE

Querying a node for a node that is close to the target node ID

struct findneighbours
{
NodeId Target; uint32_t timestamp;
};

4

Neighbors

Find_node command response, sending nodes in K-buckets close to the target node ID

struct neighbours
{
List Nodes:struct neighbour
{
inline Endpoint Endpoint;
NODEID node;
};
uint32_t timestamp;
};

2 Neighbor Nodes main members of the 2.1 nodetable class

In the C + + version of Ethereum source, Nodetable is the key class for the Ethereum peer network, and all data and methods related to the neighbor nodes are implemented by the Nodetable class.

Serial number

Member name

Description

Note

1

M_node

This node, including Nodeid, endpoint, IP, etc.


2

M_state

K Bucket, Nodeid, distance, endpoint, IP with neighbor nodes


3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.