message

package
v1.9.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: BSD-3-Clause Imports: 17 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HandshakeOps = []Op{
		Version,
		PeerList,
		Ping,
		Pong,
	}

	// List of all consensus request message types
	ConsensusRequestOps = []Op{
		GetAcceptedFrontier,
		GetAccepted,
		GetAncestors,
		Get,
		PushQuery,
		PullQuery,
		AppRequest,
		GetStateSummaryFrontier,
		GetAcceptedStateSummary,
	}
	ConsensusResponseOps = []Op{
		AcceptedFrontier,
		Accepted,
		Ancestors,
		Put,
		Chits,
		AppResponse,
		StateSummaryFrontier,
		AcceptedStateSummary,
	}
	// AppGossip is the only message that is sent unrequested without the
	// expectation of a response
	ConsensusExternalOps = append(
		ConsensusRequestOps,
		append(
			ConsensusResponseOps,
			AppGossip,
		)...,
	)
	ConsensusInternalOps = []Op{
		GetAcceptedFrontierFailed,
		GetAcceptedFailed,
		GetAncestorsFailed,
		GetFailed,
		QueryFailed,
		AppRequestFailed,
		Timeout,
		Connected,
		Disconnected,
		Notify,
		GossipRequest,
		GetStateSummaryFrontierFailed,
		GetAcceptedStateSummaryFailed,
		CrossChainAppRequest,
		CrossChainAppRequestFailed,
		CrossChainAppResponse,
	}
	ConsensusOps = append(ConsensusExternalOps, ConsensusInternalOps...)

	ExternalOps = append(ConsensusExternalOps, HandshakeOps...)

	SynchronousOps = []Op{
		GetAcceptedFrontier,
		AcceptedFrontier,
		GetAccepted,
		Accepted,
		GetAncestors,
		Ancestors,
		Get,
		Put,
		PushQuery,
		PullQuery,
		Chits,
		GetAcceptedFrontierFailed,
		GetAcceptedFailed,
		GetAncestorsFailed,
		GetFailed,
		QueryFailed,
		Connected,
		Disconnected,

		GetStateSummaryFrontier,
		StateSummaryFrontier,
		GetAcceptedStateSummary,
		AcceptedStateSummary,
		GetStateSummaryFrontierFailed,
		GetAcceptedStateSummaryFailed,
	}

	AsynchronousOps = []Op{
		AppRequest,
		AppGossip,
		AppRequestFailed,
		AppResponse,

		CrossChainAppRequest,
		CrossChainAppRequestFailed,
		CrossChainAppResponse,
	}

	ResponseToFailedOps = map[Op]Op{
		AcceptedFrontier:      GetAcceptedFrontierFailed,
		Accepted:              GetAcceptedFailed,
		Ancestors:             GetAncestorsFailed,
		Put:                   GetFailed,
		Chits:                 QueryFailed,
		AppResponse:           AppRequestFailed,
		CrossChainAppResponse: CrossChainAppRequestFailed,
		StateSummaryFrontier:  GetStateSummaryFrontierFailed,
		AcceptedStateSummary:  GetAcceptedStateSummaryFailed,
	}
	FailedToResponseOps = map[Op]Op{
		GetStateSummaryFrontierFailed: StateSummaryFrontier,
		GetAcceptedStateSummaryFailed: AcceptedStateSummary,
		GetAcceptedFrontierFailed:     AcceptedFrontier,
		GetAcceptedFailed:             Accepted,
		GetAncestorsFailed:            Ancestors,
		GetFailed:                     Put,
		QueryFailed:                   Chits,
		AppRequestFailed:              AppResponse,
		CrossChainAppRequestFailed:    CrossChainAppResponse,
	}
	UnrequestedOps = map[Op]struct{}{
		GetAcceptedFrontier:     {},
		GetAccepted:             {},
		GetAncestors:            {},
		Get:                     {},
		PushQuery:               {},
		PullQuery:               {},
		AppRequest:              {},
		AppGossip:               {},
		CrossChainAppRequest:    {},
		GetStateSummaryFrontier: {},
		GetAcceptedStateSummary: {},
	}
)

Functions

This section is empty.

Types

type Creator

func NewCreator

func NewCreator(metrics prometheus.Registerer, parentNamespace string, compressionEnabled bool, maxInboundMessageTimeout time.Duration) (Creator, error)

type Field

type Field uint32

Field that may be packed into a message

const (
	VersionStr          Field = iota // Used in handshake
	NetworkID                        // Used in handshake
	NodeID                           // TODO: remove NodeID. Used in handshake
	MyTime                           // Used in handshake
	IP                               // Used in handshake
	ChainID                          // Used for dispatching
	RequestID                        // Used for all messages
	Deadline                         // Used for request messages
	ContainerID                      // Used for querying
	ContainerBytes                   // Used for gossiping
	ContainerIDs                     // Used for querying
	MultiContainerBytes              // Used in Ancestors
	SigBytes                         // Used in handshake / peer gossiping
	VersionTime                      // Used in handshake / peer gossiping
	Peers                            // Used in peer gossiping
	TrackedSubnets                   // Used in handshake / peer gossiping
	AppBytes                         // Used at application level
	VMMessage                        // Used internally
	Uptime                           // Used for Pong
	SummaryBytes                     // Used for state sync
	SummaryHeights                   // Used for state sync
	SummaryIDs                       // Used for state sync
	VersionStruct                    // Used internally
	SourceChainID                    // Used for cross-chain messaging
)

Fields that may be packed. These values are not sent over the wire.

func (Field) String

func (f Field) String() string

type InboundMessage

type InboundMessage interface {
	fmt.Stringer

	BytesSavedCompression() int
	Op() Op
	Get(Field) (interface{}, error)
	NodeID() ids.NodeID
	ExpirationTime() time.Time
	OnFinishedHandling()
}

InboundMessage represents a set of fields for an inbound message that can be serialized into a byte stream

type InboundMsgBuilder

type InboundMsgBuilder interface {
	SetTime(t time.Time) // useful in UTs

	// Parse reads given bytes as InboundMessage
	// Overrides client specified deadline in a message to maxDeadlineDuration
	Parse(bytes []byte, nodeID ids.NodeID, onFinishedHandling func()) (InboundMessage, error)

	InboundGetStateSummaryFrontier(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		nodeID ids.NodeID,
	) InboundMessage

	InboundStateSummaryFrontier(
		chainID ids.ID,
		requestID uint32,
		summary []byte,
		nodeID ids.NodeID,
	) InboundMessage

	InboundGetAcceptedStateSummary(
		chainID ids.ID,
		requestID uint32,
		heights []uint64,
		deadline time.Duration,
		nodeID ids.NodeID,
	) InboundMessage

	InboundAcceptedStateSummary(
		chainID ids.ID,
		requestID uint32,
		summaryIDs []ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundGetAcceptedFrontier(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		nodeID ids.NodeID,
	) InboundMessage

	InboundAcceptedFrontier(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundGetAccepted(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerIDs []ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundAccepted(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundAncestors(
		chainID ids.ID,
		requestID uint32,
		containers [][]byte,
		nodeID ids.NodeID,
	) InboundMessage // used in UTs only

	InboundPushQuery(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		container []byte,
		nodeID ids.NodeID,
	) InboundMessage

	InboundPullQuery(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerID ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundChits(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundAppRequest(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		msg []byte,
		nodeID ids.NodeID,
	) InboundMessage

	InboundAppResponse(
		chainID ids.ID,
		requestID uint32,
		msg []byte,
		nodeID ids.NodeID,
	) InboundMessage

	InboundGet(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerID ids.ID,
		nodeID ids.NodeID,
	) InboundMessage

	InboundPut(
		chainID ids.ID,
		requestID uint32,
		container []byte,
		nodeID ids.NodeID,
	) InboundMessage // used in UTs only
}

type InternalMsgBuilder

type InternalMsgBuilder interface {
	InternalFailedRequest(
		op Op,
		nodeID ids.NodeID,
		sourceChainID ids.ID,
		destinationChainID ids.ID,
		requestID uint32,
	) InboundMessage
	InternalCrossChainAppRequest(
		nodeID ids.NodeID,
		sourceChainID ids.ID,
		destinationChainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		msg []byte,
	) InboundMessage
	InternalCrossChainAppResponse(
		nodeID ids.NodeID,
		sourceChainID ids.ID,
		destinationChainID ids.ID,
		requestID uint32,
		msg []byte,
	) InboundMessage
	InternalTimeout(nodeID ids.NodeID) InboundMessage
	InternalConnected(nodeID ids.NodeID, nodeVersion *version.Application) InboundMessage
	InternalDisconnected(nodeID ids.NodeID) InboundMessage
	InternalVMMessage(nodeID ids.NodeID, notification uint32) InboundMessage
	InternalGossipRequest(nodeID ids.NodeID) InboundMessage
}

func NewInternalBuilder

func NewInternalBuilder() InternalMsgBuilder

type Op

type Op byte

Op is an opcode

const (
	Pong Op
	Ping

	// Bootstrapping:
	GetAcceptedFrontier
	AcceptedFrontier
	GetAccepted
	Accepted
	GetAncestors
	Ancestors
	// Consensus:
	Get
	Put
	PushQuery
	PullQuery
	Chits

	PeerList
	Version
	// Application level:
	AppRequest
	AppResponse
	AppGossip
	// State sync
	GetStateSummaryFrontier
	StateSummaryFrontier
	GetAcceptedStateSummary
	AcceptedStateSummary

	// Internal messages (External messages should be added above these):
	GetAcceptedFrontierFailed
	GetAcceptedFailed
	GetAncestorsFailed
	GetFailed
	QueryFailed
	AppRequestFailed
	Timeout
	Connected
	Disconnected
	Notify
	GossipRequest
	GetStateSummaryFrontierFailed
	GetAcceptedStateSummaryFailed
	CrossChainAppRequest
	CrossChainAppResponse
	CrossChainAppRequestFailed
)

Types of messages that may be sent between nodes Note: If you add a new parseable Op below, you must also add it to ops (declared below)

"_" are used in places where old message types were defined that are no longer supported. When new messages are introduced these values are typically safe to reuse.

func (Op) Compressible

func (op Op) Compressible() bool

func (Op) String

func (op Op) String() string

type OutboundMessage

type OutboundMessage interface {
	BytesSavedCompression() int
	Bytes() []byte
	Op() Op
	BypassThrottling() bool
}

OutboundMessage represents a set of fields for an outbound message that can be serialized into a byte stream

type OutboundMsgBuilder

type OutboundMsgBuilder interface {
	Version(
		networkID uint32,
		myTime uint64,
		ip ips.IPPort,
		myVersion string,
		myVersionTime uint64,
		sig []byte,
		trackedSubnets []ids.ID,
	) (OutboundMessage, error)

	PeerList(
		peers []ips.ClaimedIPPort,
		bypassThrottling bool,
	) (OutboundMessage, error)

	Ping() (OutboundMessage, error)

	Pong(uptimePercentage uint8) (OutboundMessage, error)

	GetStateSummaryFrontier(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
	) (OutboundMessage, error)

	StateSummaryFrontier(
		chainID ids.ID,
		requestID uint32,
		summary []byte,
	) (OutboundMessage, error)

	GetAcceptedStateSummary(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		heights []uint64,
	) (OutboundMessage, error)

	AcceptedStateSummary(
		chainID ids.ID,
		requestID uint32,
		summaryIDs []ids.ID,
	) (OutboundMessage, error)

	GetAcceptedFrontier(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
	) (OutboundMessage, error)

	AcceptedFrontier(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
	) (OutboundMessage, error)

	GetAccepted(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerIDs []ids.ID,
	) (OutboundMessage, error)

	Accepted(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
	) (OutboundMessage, error)

	GetAncestors(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerID ids.ID,
	) (OutboundMessage, error)

	Ancestors(
		chainID ids.ID,
		requestID uint32,
		containers [][]byte,
	) (OutboundMessage, error)

	Get(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerID ids.ID,
	) (OutboundMessage, error)

	Put(
		chainID ids.ID,
		requestID uint32,
		container []byte,
	) (OutboundMessage, error)

	PushQuery(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		container []byte,
	) (OutboundMessage, error)

	PullQuery(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerID ids.ID,
	) (OutboundMessage, error)

	Chits(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
	) (OutboundMessage, error)

	AppRequest(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		msg []byte,
	) (OutboundMessage, error)

	AppResponse(
		chainID ids.ID,
		requestID uint32,
		msg []byte,
	) (OutboundMessage, error)

	AppGossip(
		chainID ids.ID,
		msg []byte,
	) (OutboundMessage, error)
}

OutboundMsgBuilder builds outbound messages. Outbound messages are returned with a reference count of 1. Once the reference count hits 0, the message bytes should no longer be accessed.

type TestMsg

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

func NewTestMsg

func NewTestMsg(op Op, bytes []byte, bypassThrottling bool) *TestMsg

func (*TestMsg) AddRef

func (*TestMsg) AddRef()

func (*TestMsg) BypassThrottling

func (m *TestMsg) BypassThrottling() bool

func (*TestMsg) Bytes

func (m *TestMsg) Bytes() []byte

func (*TestMsg) BytesSavedCompression

func (*TestMsg) BytesSavedCompression() int

func (*TestMsg) DecRef

func (*TestMsg) DecRef()

func (*TestMsg) Get

func (*TestMsg) Get(Field) interface{}

func (*TestMsg) IsProto added in v1.8.6

func (*TestMsg) IsProto() bool

func (*TestMsg) Op

func (m *TestMsg) Op() Op

Jump to

Keyboard shortcuts

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