protocol

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package protocol provides the common functionality for mini-protocols

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message interface {
	SetCbor([]byte)
	Cbor() []byte
	Type() uint8
}

Message provides a common interface for message utility functions

type MessageBase

type MessageBase struct {
	MessageType uint8
	// contains filtered or unexported fields
}

MessageBase is the minimum implementation for a mini-protocol message

func (*MessageBase) Cbor

func (m *MessageBase) Cbor() []byte

Cbor returns the original CBOR that was parsed

func (*MessageBase) SetCbor

func (m *MessageBase) SetCbor(data []byte)

SetCbor stores the original CBOR that was parsed

func (*MessageBase) Type

func (m *MessageBase) Type() uint8

Type returns the message type

type MessageFromCborFunc

type MessageFromCborFunc func(uint, []byte) (Message, error)

MessageFromCborFunc represents a function that parses a mini-protocol message

type MessageHandlerFunc

type MessageHandlerFunc func(Message, bool) error

MessageHandlerFunc represents a function that handles an incoming message

type Protocol

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

Protocol implements the base functionality of an Ouroboros mini-protocol

func New

func New(config ProtocolConfig) *Protocol

New returns a new Protocol object

func (*Protocol) DoneChan added in v0.26.0

func (p *Protocol) DoneChan() chan bool

DoneChan returns the channel used to signal protocol shutdown

func (*Protocol) Mode added in v0.9.0

func (p *Protocol) Mode() ProtocolMode

Mode returns the protocol mode

func (*Protocol) Role added in v0.9.0

func (p *Protocol) Role() ProtocolRole

Role understands the protocol role

func (*Protocol) SendError added in v0.7.0

func (p *Protocol) SendError(err error)

SendError sends an error to the handler in the Ouroboros object

func (*Protocol) SendMessage

func (p *Protocol) SendMessage(msg Message) error

SendMessage appends a message to the send queue

func (*Protocol) Start added in v0.14.0

func (p *Protocol) Start()

Start initializes the mini-protocol

type ProtocolConfig added in v0.8.0

type ProtocolConfig struct {
	Name                string
	ProtocolId          uint16
	ErrorChan           chan error
	Muxer               *muxer.Muxer
	Mode                ProtocolMode
	Role                ProtocolRole
	MessageHandlerFunc  MessageHandlerFunc
	MessageFromCborFunc MessageFromCborFunc
	StateMap            StateMap
	InitialState        State
}

ProtocolConfig provides the configuration for Protocol

type ProtocolMode added in v0.9.0

type ProtocolMode uint

ProtocolMode is an enum of the protocol modes

const (
	ProtocolModeNone         ProtocolMode = 0 // Default (invalid) protocol mode
	ProtocolModeNodeToClient ProtocolMode = 1 // Node-to-client protocol mode
	ProtocolModeNodeToNode   ProtocolMode = 2 // Node-to-node protocol mode
)

type ProtocolOptions added in v0.9.0

type ProtocolOptions struct {
	Muxer     *muxer.Muxer
	ErrorChan chan error
	Mode      ProtocolMode
	// TODO: remove me
	Role    ProtocolRole
	Version uint16
}

ProtocolOptions provides common arguments for all mini-protocols

type ProtocolRole added in v0.9.0

type ProtocolRole uint

ProtocolRole is an enum of the protocol roles

const (
	ProtocolRoleNone   ProtocolRole = 0 // Default (invalid) protocol role
	ProtocolRoleClient ProtocolRole = 1 // Client protocol role
	ProtocolRoleServer ProtocolRole = 2 // Server protocol role
)

type ProtocolStateAgency added in v0.27.0

type ProtocolStateAgency uint

ProtocolStateAgency is an enum representing the possible protocol state agency values

const (
	AgencyNone   ProtocolStateAgency = 0 // Default (invalid) value
	AgencyClient ProtocolStateAgency = 1 // Client agency
	AgencyServer ProtocolStateAgency = 2 // Server agency
)

type State added in v0.5.1

type State struct {
	Id   uint
	Name string
}

State represents protocol state with both a numeric ID and a string identifer

func NewState added in v0.5.1

func NewState(id uint, name string) State

NewState returns a new State object with the provided numeric ID and string identifier

func (State) String added in v0.5.1

func (s State) String() string

String returns the state string identifier

type StateMap added in v0.8.0

type StateMap map[State]StateMapEntry

StateMap represents the state machine definition for a mini-protocol

func (StateMap) Copy added in v0.25.0

func (s StateMap) Copy() StateMap

Copy returns a copy of the state map. This is mostly for convenience, since we need to copy the state map in various places

type StateMapEntry added in v0.8.0

type StateMapEntry struct {
	Agency      ProtocolStateAgency
	Transitions []StateTransition
	Timeout     time.Duration
}

StateMapEntry represents a protocol state, it's possible state transitions, and an optional timeout

type StateTransition added in v0.8.0

type StateTransition struct {
	MsgType   uint8
	NewState  State
	MatchFunc StateTransitionMatchFunc
}

StateTransition represents a protocol state transition

type StateTransitionMatchFunc added in v0.12.0

type StateTransitionMatchFunc func(Message) bool

StateTransitionMatchFunc represents a function that will take a Message and return a bool that indicates whether the message is a match for the state transition rule

Directories

Path Synopsis
Package chainsync implements the Ouroboros chain-sync protocol
Package chainsync implements the Ouroboros chain-sync protocol
The common package contains types used by multiple mini-protocols
The common package contains types used by multiple mini-protocols
Package handshake implements the Ouroboros handshake protocol
Package handshake implements the Ouroboros handshake protocol
Package localstatequery implements the Ouroboros local-state-query protocol
Package localstatequery implements the Ouroboros local-state-query protocol
Package localtxmonitor implements the Ouroboros local-tx-monitor protocol
Package localtxmonitor implements the Ouroboros local-tx-monitor protocol
Package localtxsubmission implements the Ouroboros local-tx-submission protocol
Package localtxsubmission implements the Ouroboros local-tx-submission protocol

Jump to

Keyboard shortcuts

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