diff

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiffCapMsg       = 0x00
	GetDiffLayerMsg  = 0x01
	DiffLayerMsg     = 0x02
	FullDiffLayerMsg = 0x03
)
View Source
const (
	Diff1 = 1
)

Constants to match up protocol versions and messages

View Source
const ProtocolName = "diff"

ProtocolName is the official short name of the `diff` protocol used during devp2p capability negotiation.

Variables

View Source
var ProtocolVersions = []uint{Diff1}

ProtocolVersions are the supported versions of the `diff` protocol (first is primary).

Functions

func Handle

func Handle(backend Backend, peer *Peer) error

Handle is the callback invoked to manage the life cycle of a `diff` peer. When this function terminates, the peer is disconnected.

func MakeProtocols

func MakeProtocols(backend Backend, dnsdisc enode.Iterator) []p2p.Protocol

MakeProtocols constructs the P2P protocol definitions for `diff`.

Types

type Backend

type Backend interface {
	// Chain retrieves the blockchain object to serve data.
	Chain() *core.BlockChain

	// RunPeer is invoked when a peer joins on the `eth` protocol. The handler
	// should do any peer maintenance work, handshakes and validations. If all
	// is passed, control should be given back to the `handler` to process the
	// inbound messages going forward.
	RunPeer(peer *Peer, handler Handler) error

	PeerInfo(id enode.ID) interface{}

	Handle(peer *Peer, packet Packet) error
}

type DiffCapPacket

type DiffCapPacket struct {
	DiffSync bool
	Extra    rlp.RawValue // for extension
}

func (*DiffCapPacket) Kind

func (*DiffCapPacket) Kind() byte

func (*DiffCapPacket) Name

func (*DiffCapPacket) Name() string

type DiffLayersPacket

type DiffLayersPacket []rlp.RawValue

func (*DiffLayersPacket) Kind

func (*DiffLayersPacket) Kind() byte

func (*DiffLayersPacket) Name

func (*DiffLayersPacket) Name() string

func (*DiffLayersPacket) Unpack

func (p *DiffLayersPacket) Unpack() ([]*types.DiffLayer, error)

type FullDiffLayersPacket

type FullDiffLayersPacket struct {
	RequestId uint64
	DiffLayersPacket
}

func (*FullDiffLayersPacket) Kind

func (*FullDiffLayersPacket) Kind() byte

func (*FullDiffLayersPacket) Name

func (*FullDiffLayersPacket) Name() string

type GetDiffLayersPacket

type GetDiffLayersPacket struct {
	RequestId   uint64
	BlockHashes []common.Hash
}

func (*GetDiffLayersPacket) Kind

func (*GetDiffLayersPacket) Kind() byte

func (*GetDiffLayersPacket) Name

func (*GetDiffLayersPacket) Name() string

type Handler

type Handler func(peer *Peer) error

Handler is a callback to invoke from an outside runner after the boilerplate exchanges have passed.

type NodeInfo

type NodeInfo struct{}

NodeInfo represents a short summary of the `diff` sub-protocol metadata known about the host peer.

type Packet

type Packet interface {
	Name() string // Name returns a string corresponding to the message type.
	Kind() byte   // Kind returns the message type.
}

Packet represents a p2p message in the `diff` protocol.

type Peer

type Peer struct {
	*p2p.Peer // The embedded P2P package peer
	// contains filtered or unexported fields
}

Peer is a collection of relevant information we have about a `diff` peer.

func NewPeer

func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter) *Peer

NewPeer create a wrapper for a network connection and negotiated protocol version.

func (*Peer) AsyncSendDiffLayer

func (p *Peer) AsyncSendDiffLayer(diffLayers []rlp.RawValue)

func (*Peer) Close

func (p *Peer) Close()

Close signals the broadcast goroutine to terminate. Only ever call this if you created the peer yourself via NewPeer. Otherwise let whoever created it clean it up!

func (*Peer) DiffSync

func (p *Peer) DiffSync() bool

func (*Peer) Handshake

func (p *Peer) Handshake(diffSync bool) error

Handshake executes the diff protocol handshake,

func (*Peer) ID

func (p *Peer) ID() string

ID retrieves the peer's unique identifier.

func (*Peer) Log

func (p *Peer) Log() log.Logger

Log overrides the P2P logget with the higher level one containing only the id.

func (*Peer) RequestDiffLayers

func (p *Peer) RequestDiffLayers(hashes []common.Hash) error

RequestDiffLayers fetches a batch of diff layers corresponding to the hashes specified.

func (*Peer) SendDiffLayers

func (p *Peer) SendDiffLayers(diffs []rlp.RawValue) error

func (*Peer) Version

func (p *Peer) Version() uint

Version retrieves the peer's negoatiated `diff` protocol version.

type Tracker

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

func NewTracker

func NewTracker(timeout time.Duration) *Tracker

func (*Tracker) Fulfil

func (t *Tracker) Fulfil(peer string, version uint, code uint64, id uint64) bool

Fulfil fills a pending request, if any is available.

func (*Tracker) Track

func (t *Tracker) Track(peer string, version uint, reqCode uint64, resCode uint64, id uint64)

Track adds a network request to the tracker to wait for a response to arrive or until the request it cancelled or times out.

Jump to

Keyboard shortcuts

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