rlpx

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2022 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package rlpx implements the RLPx transport protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is an RLPx network connection. It wraps a low-level network connection. The underlying connection should not be used for other activity when it is wrapped by Conn.

Before sending messages, a handshake must be performed by calling the Handshake method. This type is not generally safe for concurrent use, but reading and writing of messages may happen concurrently after the handshake. Conn代表了基于RLPx协议的网络连接 内部封装了net.Conn对象实现真正的传输层通信

func NewConn

func NewConn(conn net.Conn, dialDest *ecdsa.PublicKey) *Conn

NewConn wraps the given network connection. If dialDest is non-nil, the connection behaves as the initiator during the handshake. dialDest不为nil说明本地是握手的发起方 dialDest是nil说明本地是握手的接收方

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying network connection.

func (*Conn) Handshake

func (c *Conn) Handshake(prv *ecdsa.PrivateKey) (*ecdsa.PublicKey, error)

Handshake performs the handshake. This must be called before any data is written or read from the connection. 利用本地私钥开始执行握手过程,返回远程节点的临时公钥 握手过程应该在传输任何数据之前,也就是NewConn后立刻执行Handshake

func (*Conn) InitWithSecrets

func (c *Conn) InitWithSecrets(sec Secrets)

InitWithSecrets injects connection secrets as if a handshake had been performed. This cannot be called after the handshake. 用于模拟握手完成,不执行真正的握手过程,直接需要握手过程共享的秘密保存到Conn中 就是用Secrets对象生成handshakeState对象

func (*Conn) Read

func (c *Conn) Read() (code uint64, data []byte, wireSize int, err error)

Read reads a message from the connection. The returned data buffer is valid until the next call to Read. 通过网络读取一个消息,获取code和消息内的数据 从链路中读取一个帧,返回code和真实的数据,以及通过链路传输的数据的长度

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(time time.Time) error

SetDeadline sets the deadline for all future read and write operations. 超过指定时间后不能再Read和Write

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(time time.Time) error

SetReadDeadline sets the deadline for all future read operations. 超过指定时间后不能再Read

func (*Conn) SetSnappy

func (c *Conn) SetSnappy(snappy bool)

SetSnappy enables or disables snappy compression of messages. This is usually called after the devp2p Hello message exchange when the negotiated version indicates that compression is available on both ends of the connection. 用于设置此连接上是否启用数据压缩

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(time time.Time) error

SetWriteDeadline sets the deadline for all future write operations. 超过指定时间后不能再Write

func (*Conn) Write

func (c *Conn) Write(code uint64, data []byte) (uint32, error)

Write writes a message to the connection.

Write returns the written size of the message data. This may be less than or equal to len(data) depending on whether snappy compression is enabled. 通过网络发送一个消息,指定code和数据 返回进行网络传输的数据长度,不使用压缩时就等于data的长度,压缩的话可能小于data的长度

type Secrets

type Secrets struct {
	// AES和MAC长度都是32字节,作为AES-256算法的密钥
	AES, MAC              []byte
	EgressMAC, IngressMAC hash.Hash
	// contains filtered or unexported fields
}

Secrets represents the connection secrets which are negotiated during the handshake. Secrets是握手的成果,用于后续消息发送的对称加密

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL