Ethereum Source (05): Network Service analysis

Source: Internet
Author: User

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

Directory

1 network layering ..... ..... ..... ........................ ..... ..... ..... ..... .............. ........... 4

2 Session layer ..... ..... .... ..... ..... ...................... ..... ..... ..... ..... ..... .............. .......... 4

2.1 Peer Introduction ...... ..... ......................... ....... ..... .................. ......... 5

2.2 Peer management ...... ..... ........................ ....... ..... .................. ......... 5

2.2.1 Peer Dynamic Add delete process ..... ..... ... ..... .... ..... ..... ..... ..... ..... ..................... 5

2.2.2 Peer handshake mechanism ..... ..... .................... ............................. 6

3 Presentation layer: RLP encoding ...... ..... ..... ................ ........ ................... ....... 6

4 Application layer: Eth protocol ...... ..... ..... ................ ........ ................... ....... 6

1 Network tiering

Ethereum all network functions are shown in the following diagram: All network functions are built on the Ethernet transport layer, TCP and UDP are used.



2 Session Layer

The session layer mainly includes peer management, nodetable Management and RPC protocol, this article focuses on peer management, nodetable please refer to the peer-network and neighbor node discovery mechanism. Key code that involves the session layer:


2.1 Peer Introduction

Peer refers to a neighbor node that passes the communication handshake, and only the neighbor node becomes a peer, and only the nodes in the peer list can communicate properly.


2.2 Peer Management

Peers exists in the code as a map structure, created by the server Run method run, and added and removed in the Run method. Pees maximum default number is (Node/defaults.go defined)


2.2.1 Peer Dynamic Add Delete process

Peer addition is divided into two types: passive and active Add. 1) Passive add refers to the other node initiates the handshake, the process is as follows:

2) Whenever there is a change in the current peers, such as adding, deleting, or once the Dial task is completed, an active handshake process is performed, where the nodes to be Dial (dial-up, i.e. handshake communication) are composed of the following parts:


Static node, configuration file write at system startup


Random selection in nodetable (One-second of the current needdyndials, needdyndials value (s.maxpeer+1)/2=13)


Node in Loobbuf (Neighbor node in discovery Task)


When the number of nodes in the LOOKBUF is insufficient, a nodetable flush is forced, and the node written to Lookbuf is flushed.

3) Peer Deletion has three ways: RPC command deletion, one application layer of communication complete automatic deletion, communication process read-write error.


2.2.2 Peer handshake Mechanism

Refer to "Ethereum Bottom technology research: Peer handshake mechanism"



3 Presentation layer: RLP encoding

Ethereum is related to the data sent on the network x follow the RLP code, reference "RLP mechanism analysis"



4 Application layer: Eth protocol

After the Peer handshake succeeds, the application layer communication can be performed, and the Eth protocol packet is shown in the following table:

The ETH protocol application layer includes the following commands:


This article is organized by the core chain team.

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.