blockfetch

package
v0.106.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ProtocolName        = "block-fetch"
	ProtocolId   uint16 = 3
)
View Source
const (
	MessageTypeRequestRange = 0
	MessageTypeClientDone   = 1
	MessageTypeStartBatch   = 2
	MessageTypeNoBlocks     = 3
	MessageTypeBlock        = 4
	MessageTypeBatchDone    = 5
)

Variables

View Source
var (
	StateIdle      = protocol.NewState(1, "Idle")
	StateBusy      = protocol.NewState(2, "Busy")
	StateStreaming = protocol.NewState(3, "Streaming")
	StateDone      = protocol.NewState(4, "Done")
)
View Source
var StateMap = protocol.StateMap{
	StateIdle: protocol.StateMapEntry{
		Agency: protocol.AgencyClient,
		Transitions: []protocol.StateTransition{
			{
				MsgType:  MessageTypeRequestRange,
				NewState: StateBusy,
			},
			{
				MsgType:  MessageTypeClientDone,
				NewState: StateDone,
			},
		},
	},
	StateBusy: protocol.StateMapEntry{
		Agency: protocol.AgencyServer,
		Transitions: []protocol.StateTransition{
			{
				MsgType:  MessageTypeStartBatch,
				NewState: StateStreaming,
			},
			{
				MsgType:  MessageTypeNoBlocks,
				NewState: StateIdle,
			},
		},
	},
	StateStreaming: protocol.StateMapEntry{
		Agency: protocol.AgencyServer,
		Transitions: []protocol.StateTransition{
			{
				MsgType:  MessageTypeBlock,
				NewState: StateStreaming,
			},
			{
				MsgType:  MessageTypeBatchDone,
				NewState: StateIdle,
			},
		},
	},
	StateDone: protocol.StateMapEntry{
		Agency: protocol.AgencyNone,
	},
}

Functions

func NewMsgFromCbor

func NewMsgFromCbor(msgType uint, data []byte) (protocol.Message, error)

Types

type BatchDoneFunc added in v0.104.0

type BatchDoneFunc func(CallbackContext) error

type BlockFetch

type BlockFetch struct {
	Client *Client
	Server *Server
}

func New

func New(protoOptions protocol.ProtocolOptions, cfg *Config) *BlockFetch

type BlockFetchOptionFunc

type BlockFetchOptionFunc func(*Config)

func WithBatchDoneFunc added in v0.104.0

func WithBatchDoneFunc(batchDoneFunc BatchDoneFunc) BlockFetchOptionFunc

func WithBatchStartTimeout

func WithBatchStartTimeout(timeout time.Duration) BlockFetchOptionFunc

func WithBlockFunc

func WithBlockFunc(blockFunc BlockFunc) BlockFetchOptionFunc

func WithBlockTimeout

func WithBlockTimeout(timeout time.Duration) BlockFetchOptionFunc

func WithRequestRangeFunc added in v0.66.0

func WithRequestRangeFunc(
	requestRangeFunc RequestRangeFunc,
) BlockFetchOptionFunc

type BlockFunc

type BlockFunc func(CallbackContext, uint, ledger.Block) error

Callback function types

type CallbackContext added in v0.78.0

type CallbackContext struct {
	ConnectionId connection.ConnectionId
	Client       *Client
	Server       *Server
}

Callback context

type Client

type Client struct {
	*protocol.Protocol
	// contains filtered or unexported fields
}

func NewClient

func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client

func (*Client) GetBlock

func (c *Client) GetBlock(point common.Point) (ledger.Block, error)

GetBlock requests and returns a single block specified by the provided point

func (*Client) GetBlockRange

func (c *Client) GetBlockRange(start common.Point, end common.Point) error

GetBlockRange starts an async process to fetch all blocks in the specified range (inclusive)

func (*Client) Start added in v0.73.3

func (c *Client) Start()

func (*Client) Stop

func (c *Client) Stop() error

type Config

type Config struct {
	BlockFunc         BlockFunc
	BatchDoneFunc     BatchDoneFunc
	RequestRangeFunc  RequestRangeFunc
	BatchStartTimeout time.Duration
	BlockTimeout      time.Duration
}

func NewConfig

func NewConfig(options ...BlockFetchOptionFunc) Config

type MsgBatchDone

type MsgBatchDone struct {
	protocol.MessageBase
}

func NewMsgBatchDone

func NewMsgBatchDone() *MsgBatchDone

type MsgBlock

type MsgBlock struct {
	protocol.MessageBase
	WrappedBlock []byte
}

func NewMsgBlock

func NewMsgBlock(wrappedBlock []byte) *MsgBlock

func (MsgBlock) MarshalCBOR added in v0.66.0

func (m MsgBlock) MarshalCBOR() ([]byte, error)

type MsgClientDone

type MsgClientDone struct {
	protocol.MessageBase
}

func NewMsgClientDone

func NewMsgClientDone() *MsgClientDone

type MsgNoBlocks

type MsgNoBlocks struct {
	protocol.MessageBase
}

func NewMsgNoBlocks

func NewMsgNoBlocks() *MsgNoBlocks

type MsgRequestRange

type MsgRequestRange struct {
	protocol.MessageBase
	Start common.Point
	End   common.Point
}

func NewMsgRequestRange

func NewMsgRequestRange(start common.Point, end common.Point) *MsgRequestRange

type MsgStartBatch

type MsgStartBatch struct {
	protocol.MessageBase
}

func NewMsgStartBatch

func NewMsgStartBatch() *MsgStartBatch

type RequestRangeFunc added in v0.66.0

type RequestRangeFunc func(CallbackContext, common.Point, common.Point) error

type Server

type Server struct {
	*protocol.Protocol
	// contains filtered or unexported fields
}

func NewServer

func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server

func (*Server) BatchDone added in v0.66.0

func (s *Server) BatchDone() error

func (*Server) Block added in v0.66.0

func (s *Server) Block(blockType uint, blockData []byte) error

func (*Server) NoBlocks added in v0.66.0

func (s *Server) NoBlocks() error

func (*Server) StartBatch added in v0.66.0

func (s *Server) StartBatch() error

type WrappedBlock

type WrappedBlock struct {
	cbor.StructAsArray
	Type     uint
	RawBlock cbor.RawMessage
}

Jump to

Keyboard shortcuts

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