wire

package
v0.0.0-...-508c5de Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: LGPL-2.1-or-later Imports: 7 Imported by: 0

README

ethwire

The ethwire package contains the ethereum wire protocol. The ethwire package is required to write and read from the ethereum network.

Installation

go get github.com/ethereum/ethwire-go

Messaging overview

The Ethereum Wire protocol defines the communication between the nodes running Ethereum. Further reader reading can be done on the Wiki.

Reading Messages

// Read and validate the next eth message from the provided connection.
// returns a error message with the details.
msg, err := ethwire.ReadMessage(conn)
if err != nil {
  // Handle error
}

Writing Messages

// Constructs a message which can be interpreted by the eth network.
// Write the inventory to network
err := ethwire.WriteMessage(conn, &Msg{
  Type: ethwire.MsgInvTy,
  Data : []interface{}{...},
})

Documentation

Overview

Package wire provides low level access to the Ethereum network and allows you to broadcast data over the network.

Index

Constants

View Source
const (
	// Values are given explicitly instead of by iota because these values are
	// defined by the wire protocol spec; it is easier for humans to ensure
	// correctness when values are explicit.
	MsgHandshakeTy = 0x00
	MsgDiscTy      = 0x01
	MsgPingTy      = 0x02
	MsgPongTy      = 0x03
	MsgGetPeersTy  = 0x04
	MsgPeersTy     = 0x05

	MsgStatusTy         = 0x10
	MsgTxTy             = 0x12
	MsgGetBlockHashesTy = 0x13
	MsgBlockHashesTy    = 0x14
	MsgGetBlocksTy      = 0x15
	MsgBlockTy          = 0x16
	MsgNewBlockTy       = 0x17
)

Variables

View Source
var MagicToken = []byte{34, 64, 8, 145}

The magic token which should be the first 4 bytes of every message and can be used as separator between messages.

Functions

func WriteMessage

func WriteMessage(conn net.Conn, msg *Msg) error

The basic message writer takes care of writing data over the given connection and does some basic error checking

Types

type ClientIdentity

type ClientIdentity interface {
	String() string
}

should be used in Peer handleHandshake, incorporate Caps, ProtocolVersion, Pubkey etc.

type Conn

type Conn interface {
	Write(typ MsgType, v ...interface{}) error
	Read() *Msg
}

Connection interface describing the methods required to implement the wire protocol.

type Connection

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

The connection object allows you to set up a connection to the Ethereum network. The Connection object takes care of all encoding and sending objects properly over the network.

func New

func New(conn net.Conn) *Connection

Create a new connection to the Ethereum network

func (*Connection) Read

func (self *Connection) Read() *Msg

Read, reads from the network. It will block until the next message is received.

func (*Connection) Write

func (self *Connection) Write(typ MsgType, v ...interface{}) error

Write to the Ethereum network specifying the type of the message and the data. Data can be of type RlpEncodable or []interface{}. Returns nil or if something went wrong an error.

type Messages

type Messages []*Msg

type Msg

type Msg struct {
	Type MsgType // Specifies how the encoded data should be interpreted
	//Data []byte
	Data *ethutil.Value
}

func NewMessage

func NewMessage(msgType MsgType, data interface{}) *Msg

func ReadMessage

func ReadMessage(data []byte) (msg *Msg, remaining []byte, done bool, err error)

func ReadMessages

func ReadMessages(conn net.Conn) (msgs []*Msg, err error)

The basic message reader waits for data on the given connection, decoding and doing a few sanity checks such as if there's a data type and unmarhals the given data

type MsgType

type MsgType byte

func (MsgType) String

func (mt MsgType) String() string

type SimpleClientIdentity

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

func NewSimpleClientIdentity

func NewSimpleClientIdentity(clientIdentifier string, version string, customIdentifier string) *SimpleClientIdentity

func (*SimpleClientIdentity) GetCustomIdentifier

func (c *SimpleClientIdentity) GetCustomIdentifier() string

func (*SimpleClientIdentity) SetCustomIdentifier

func (c *SimpleClientIdentity) SetCustomIdentifier(customIdentifier string)

func (*SimpleClientIdentity) String

func (c *SimpleClientIdentity) String() string

Jump to

Keyboard shortcuts

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