# Three-tier architecture of P2P network in Ethereum

Posted by 刘学枫 on January 9, 2019

## Introduction

As a decentralized digital currency system, the network architecture of Ethereum is very important since the synchronization of data and the update of nodes’ status both depend on the connection mechanism between nodes. Peer to Peer(P2P) protocol is used as a communication link for Ethereum and has been developed in various aspects according to the transmission of data(e.g. blocks, transaction and hash value) and message in the network, which can be divided into three layers.

## Three-tier architecture

The P2P function in Ethereum was design as a package to support multiple protocols on it that allows programers to rapidly and easily add peer to peer networking to any type of application since it is regarded as a communication link for the transmisstion of the upper layer protocol shown in figure below:

• The uppermost layer is the specific implementation of each protocol in Ethereum, such as ETH protocol and LES protocol.

• The second layer is the p2p communication link layer in Ethereum. It is mainly responsible for starting monitoring, processing new inbound/outbound connections or maintaining built links, providing channels for upper layer protocols and calling methodes of the bottom layer to analyse messages.

• The bottom layer is the network IO layer provided by the Go language, which is the encapsulation of the network layer in TCP/IP.

Specifically, the p2p communication link layer mainly does three things:

• After the data of the upper layer protocol is delivered to the p2p layer, it is first encoded by RLP.

• The RLP encoded data will be encrypted by the shared key to ensure the security of the data during the communication process.

• Finally, the data stream is converted to an RLPXFrameRW frame for easy encrypted transmission and parsing of data.

• 最上层是由以太坊里具体的协议组成。
• 中间的P2P通讯链接层主要是用于启动节点监控，处理连入/连出或者维持现有链接，向上层协议提供访问通道以及调用下层函数来分析消息包。
• 最下层则是对Go语言中TCP/IP协议的底层封装。

• 对上层传递下来的消息进行RLP编码。
• 接着对RLP编码后的数据用共享加密的方式确保数据传输过程中的安全性。
• 最后，该数据流转换为RLPXFrameRW帧进行简单加密并传输。

## Conclusion

We take a glance look at this short blog, we can have a simple understanding of the three-tier architecture of Ethereum P2P network. However, it does not provide anything specific analysis about the Ethereum’ source code. If you are interest about it, you can read more further in [2].

## Reference

[1]Ethereum Network Architecture Analysis

[2]Peer to Peer