message

package
v0.0.0-...-bc03976 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HandshakeOps = []Op{
		PingOp,
		PongOp,
		HandshakeOp,
		GetPeerListOp,
		PeerListOp,
	}

	// List of all consensus request message types
	ConsensusRequestOps = []Op{
		GetStateSummaryFrontierOp,
		GetAcceptedStateSummaryOp,
		GetAcceptedFrontierOp,
		GetAcceptedOp,
		GetAncestorsOp,
		GetOp,
		PushQueryOp,
		PullQueryOp,
		AppRequestOp,
	}
	ConsensusResponseOps = []Op{
		StateSummaryFrontierOp,
		AcceptedStateSummaryOp,
		AcceptedFrontierOp,
		AcceptedOp,
		AncestorsOp,
		PutOp,
		ChitsOp,
		AppResponseOp,
		AppErrorOp,
	}
	// AppGossip is the only message that is sent unrequested without the
	// expectation of a response
	ConsensusExternalOps = append(
		ConsensusRequestOps,
		append(
			ConsensusResponseOps,
			AppGossipOp,
		)...,
	)
	ConsensusInternalOps = []Op{
		GetStateSummaryFrontierFailedOp,
		GetAcceptedStateSummaryFailedOp,
		GetAcceptedFrontierFailedOp,
		GetAcceptedFailedOp,
		GetAncestorsFailedOp,
		GetFailedOp,
		QueryFailedOp,
		ConnectedOp,
		ConnectedSubnetOp,
		DisconnectedOp,
		NotifyOp,
		GossipRequestOp,
		TimeoutOp,
	}
	ConsensusOps = append(ConsensusExternalOps, ConsensusInternalOps...)

	ExternalOps = append(ConsensusExternalOps, HandshakeOps...)

	SynchronousOps = []Op{

		GetStateSummaryFrontierOp,
		GetStateSummaryFrontierFailedOp,
		StateSummaryFrontierOp,
		GetAcceptedStateSummaryOp,
		GetAcceptedStateSummaryFailedOp,
		AcceptedStateSummaryOp,

		GetAcceptedFrontierOp,
		GetAcceptedFrontierFailedOp,
		AcceptedFrontierOp,
		GetAcceptedOp,
		GetAcceptedFailedOp,
		AcceptedOp,
		GetAncestorsOp,
		GetAncestorsFailedOp,
		AncestorsOp,

		GetOp,
		GetFailedOp,
		PutOp,
		PushQueryOp,
		PullQueryOp,
		QueryFailedOp,
		ChitsOp,

		ConnectedOp,
		ConnectedSubnetOp,
		DisconnectedOp,
	}

	AsynchronousOps = []Op{

		AppRequestOp,
		AppErrorOp,
		AppGossipOp,
		AppResponseOp,
	}

	FailedToResponseOps = map[Op]Op{
		GetStateSummaryFrontierFailedOp: StateSummaryFrontierOp,
		GetAcceptedStateSummaryFailedOp: AcceptedStateSummaryOp,
		GetAcceptedFrontierFailedOp:     AcceptedFrontierOp,
		GetAcceptedFailedOp:             AcceptedOp,
		GetAncestorsFailedOp:            AncestorsOp,
		GetFailedOp:                     PutOp,
		QueryFailedOp:                   ChitsOp,
		AppErrorOp:                      AppResponseOp,
	}
	UnrequestedOps = set.Of(
		GetAcceptedFrontierOp,
		GetAcceptedOp,
		GetAncestorsOp,
		GetOp,
		PushQueryOp,
		PullQueryOp,
		AppRequestOp,
		AppGossipOp,
		GetStateSummaryFrontierOp,
		GetAcceptedStateSummaryOp,
	)
)

Functions

func GetChainID

func GetChainID(m any) (ids.ID, error)

func GetDeadline

func GetDeadline(m any) (time.Duration, bool)

func GetEngineType

func GetEngineType(m any) (p2p.EngineType, bool)

func GetRequestID

func GetRequestID(m any) (uint32, bool)

func Unwrap

func Unwrap(m *p2p.Message) (fmt.Stringer, error)

Types

type Connected

type Connected struct {
	NodeVersion *version.Application `json:"node_version,omitempty"`
}

func (*Connected) String

func (m *Connected) String() string

type ConnectedSubnet

type ConnectedSubnet struct {
	SubnetID ids.ID `json:"subnet_id,omitempty"`
}

ConnectedSubnet contains the subnet ID of the subnet that the node is connected to.

func (*ConnectedSubnet) String

func (m *ConnectedSubnet) String() string

type Creator

type Creator interface {
	OutboundMsgBuilder
	InboundMsgBuilder
}

func NewCreator

func NewCreator(
	log logging.Logger,
	metrics prometheus.Registerer,
	compressionType compression.Type,
	maxMessageTimeout time.Duration,
) (Creator, error)

type Disconnected

type Disconnected struct{}

func (Disconnected) String

func (Disconnected) String() string

type GetAcceptedFailed

type GetAcceptedFailed struct {
	ChainID   ids.ID `json:"chain_id,omitempty"`
	RequestID uint32 `json:"request_id,omitempty"`
}

func (*GetAcceptedFailed) GetChainId

func (m *GetAcceptedFailed) GetChainId() []byte

func (*GetAcceptedFailed) GetRequestId

func (m *GetAcceptedFailed) GetRequestId() uint32

func (*GetAcceptedFailed) String

func (m *GetAcceptedFailed) String() string

type GetAcceptedFrontierFailed

type GetAcceptedFrontierFailed struct {
	ChainID   ids.ID `json:"chain_id,omitempty"`
	RequestID uint32 `json:"request_id,omitempty"`
}

func (*GetAcceptedFrontierFailed) GetChainId

func (m *GetAcceptedFrontierFailed) GetChainId() []byte

func (*GetAcceptedFrontierFailed) GetRequestId

func (m *GetAcceptedFrontierFailed) GetRequestId() uint32

func (*GetAcceptedFrontierFailed) String

func (m *GetAcceptedFrontierFailed) String() string

type GetAcceptedStateSummaryFailed

type GetAcceptedStateSummaryFailed struct {
	ChainID   ids.ID `json:"chain_id,omitempty"`
	RequestID uint32 `json:"request_id,omitempty"`
}

func (*GetAcceptedStateSummaryFailed) GetChainId

func (m *GetAcceptedStateSummaryFailed) GetChainId() []byte

func (*GetAcceptedStateSummaryFailed) GetRequestId

func (m *GetAcceptedStateSummaryFailed) GetRequestId() uint32

func (*GetAcceptedStateSummaryFailed) String

type GetAncestorsFailed

type GetAncestorsFailed struct {
	ChainID    ids.ID         `json:"chain_id,omitempty"`
	RequestID  uint32         `json:"request_id,omitempty"`
	EngineType p2p.EngineType `json:"engine_type,omitempty"`
}

func (*GetAncestorsFailed) GetChainId

func (m *GetAncestorsFailed) GetChainId() []byte

func (*GetAncestorsFailed) GetEngineType

func (m *GetAncestorsFailed) GetEngineType() p2p.EngineType

func (*GetAncestorsFailed) GetRequestId

func (m *GetAncestorsFailed) GetRequestId() uint32

func (*GetAncestorsFailed) String

func (m *GetAncestorsFailed) String() string

type GetFailed

type GetFailed struct {
	ChainID   ids.ID `json:"chain_id,omitempty"`
	RequestID uint32 `json:"request_id,omitempty"`
}

func (*GetFailed) GetChainId

func (m *GetFailed) GetChainId() []byte

func (*GetFailed) GetRequestId

func (m *GetFailed) GetRequestId() uint32

func (*GetFailed) String

func (m *GetFailed) String() string

type GetStateSummaryFrontierFailed

type GetStateSummaryFrontierFailed struct {
	ChainID   ids.ID `json:"chain_id,omitempty"`
	RequestID uint32 `json:"request_id,omitempty"`
}

func (*GetStateSummaryFrontierFailed) GetChainId

func (m *GetStateSummaryFrontierFailed) GetChainId() []byte

func (*GetStateSummaryFrontierFailed) GetRequestId

func (m *GetStateSummaryFrontierFailed) GetRequestId() uint32

func (*GetStateSummaryFrontierFailed) String

type GossipRequest

type GossipRequest struct{}

func (GossipRequest) String

func (GossipRequest) String() string

type InboundMessage

type InboundMessage interface {
	fmt.Stringer
	// NodeID returns the ID of the node that sent this message
	NodeID() ids.NodeID
	// Op returns the op that describes this message type
	Op() Op
	// Message returns the message that was sent
	Message() fmt.Stringer
	// Expiration returns the time that the sender will have already timed out
	// this request
	Expiration() time.Time
	// OnFinishedHandling must be called one time when this message has been
	// handled by the message handler
	OnFinishedHandling()
	// BytesSavedCompression returns the number of bytes that this message saved
	// due to being compressed
	BytesSavedCompression() int
}

InboundMessage represents a set of fields for an inbound message

func InboundAccepted

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

func InboundAcceptedFrontier

func InboundAcceptedFrontier(
	chainID ids.ID,
	requestID uint32,
	containerID ids.ID,
	nodeID ids.NodeID,
) InboundMessage

func InboundAcceptedStateSummary

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

func InboundAppError

func InboundAppError(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
	errorCode int32,
	errorMessage string,
) InboundMessage

func InboundAppRequest

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

func InboundAppResponse

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

func InboundChits

func InboundChits(
	chainID ids.ID,
	requestID uint32,
	preferredID ids.ID,
	preferredIDAtHeight ids.ID,
	acceptedID ids.ID,
	nodeID ids.NodeID,
) InboundMessage

func InboundGetAccepted

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

func InboundGetAcceptedFrontier

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

func InboundGetAcceptedStateSummary

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

func InboundGetStateSummaryFrontier

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

func InboundPullQuery

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

func InboundPushQuery

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

func InboundStateSummaryFrontier

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

func InternalConnected

func InternalConnected(nodeID ids.NodeID, nodeVersion *version.Application) InboundMessage

func InternalConnectedSubnet

func InternalConnectedSubnet(nodeID ids.NodeID, subnetID ids.ID) InboundMessage

InternalConnectedSubnet returns a message that indicates the node with [nodeID] is connected to the subnet with the given [subnetID].

func InternalDisconnected

func InternalDisconnected(nodeID ids.NodeID) InboundMessage

func InternalGetAcceptedFailed

func InternalGetAcceptedFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
) InboundMessage

func InternalGetAcceptedFrontierFailed

func InternalGetAcceptedFrontierFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
) InboundMessage

func InternalGetAcceptedStateSummaryFailed

func InternalGetAcceptedStateSummaryFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
) InboundMessage

func InternalGetAncestorsFailed

func InternalGetAncestorsFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
	engineType p2p.EngineType,
) InboundMessage

func InternalGetFailed

func InternalGetFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
) InboundMessage

func InternalGetStateSummaryFrontierFailed

func InternalGetStateSummaryFrontierFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
) InboundMessage

func InternalGossipRequest

func InternalGossipRequest(
	nodeID ids.NodeID,
) InboundMessage

func InternalQueryFailed

func InternalQueryFailed(
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
) InboundMessage

func InternalTimeout

func InternalTimeout(nodeID ids.NodeID) InboundMessage

func InternalVMMessage

func InternalVMMessage(
	nodeID ids.NodeID,
	notification uint32,
) InboundMessage

type InboundMsgBuilder

type InboundMsgBuilder interface {
	// Parse reads given bytes as InboundMessage
	Parse(
		bytes []byte,
		nodeID ids.NodeID,
		onFinishedHandling func(),
	) (InboundMessage, error)
}

type Op

type Op byte

Op is an opcode

const (
	// Handshake:
	PingOp Op = iota
	PongOp
	HandshakeOp
	GetPeerListOp
	PeerListOp
	// State sync:
	GetStateSummaryFrontierOp
	GetStateSummaryFrontierFailedOp
	StateSummaryFrontierOp
	GetAcceptedStateSummaryOp
	GetAcceptedStateSummaryFailedOp
	AcceptedStateSummaryOp
	// Bootstrapping:
	GetAcceptedFrontierOp
	GetAcceptedFrontierFailedOp
	AcceptedFrontierOp
	GetAcceptedOp
	GetAcceptedFailedOp
	AcceptedOp
	GetAncestorsOp
	GetAncestorsFailedOp
	AncestorsOp
	// Consensus:
	GetOp
	GetFailedOp
	PutOp
	PushQueryOp
	PullQueryOp
	QueryFailedOp
	ChitsOp
	// Application:
	AppRequestOp
	AppErrorOp
	AppResponseOp
	AppGossipOp
	// Internal:
	ConnectedOp
	ConnectedSubnetOp
	DisconnectedOp
	NotifyOp
	GossipRequestOp
	TimeoutOp
)

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)

func ToOp

func ToOp(m *p2p.Message) (Op, error)

func (Op) String

func (op Op) String() string

type OutboundMessage

type OutboundMessage interface {
	// BypassThrottling returns true if we should send this message, regardless
	// of any outbound message throttling
	BypassThrottling() bool
	// Op returns the op that describes this message type
	Op() Op
	// Bytes returns the bytes that will be sent
	Bytes() []byte
	// BytesSavedCompression returns the number of bytes that this message saved
	// due to being compressed
	BytesSavedCompression() int
}

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

type OutboundMsgBuilder

type OutboundMsgBuilder interface {
	Handshake(
		networkID uint32,
		myTime uint64,
		ip netip.AddrPort,
		client string,
		major uint32,
		minor uint32,
		patch uint32,
		ipSigningTime uint64,
		ipNodeIDSig []byte,
		ipBLSSig []byte,
		trackedSubnets []ids.ID,
		supportedACPs []uint32,
		objectedACPs []uint32,
		knownPeersFilter []byte,
		knownPeersSalt []byte,
		requestAllSubnetIPs bool,
	) (OutboundMessage, error)

	GetPeerList(
		knownPeersFilter []byte,
		knownPeersSalt []byte,
		requestAllSubnetIPs bool,
	) (OutboundMessage, error)

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

	Ping(
		primaryUptime uint32,
		subnetUptimes []*p2p.SubnetUptime,
	) (OutboundMessage, error)

	Pong() (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,
		containerID 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,
		engineType p2p.EngineType,
	) (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,
		requestedHeight uint64,
	) (OutboundMessage, error)

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

	Chits(
		chainID ids.ID,
		requestID uint32,
		preferredID ids.ID,
		preferredIDAtHeight ids.ID,
		acceptedID 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)

	AppError(
		chainID ids.ID,
		requestID uint32,
		errorCode int32,
		errorMessage string,
	) (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 QueryFailed

type QueryFailed struct {
	ChainID   ids.ID `json:"chain_id,omitempty"`
	RequestID uint32 `json:"request_id,omitempty"`
}

func (*QueryFailed) GetChainId

func (m *QueryFailed) GetChainId() []byte

func (*QueryFailed) GetRequestId

func (m *QueryFailed) GetRequestId() uint32

func (*QueryFailed) String

func (m *QueryFailed) String() string

type Timeout

type Timeout struct{}

func (Timeout) String

func (Timeout) String() string

type VMMessage

type VMMessage struct {
	Notification uint32 `json:"notification,omitempty"`
}

func (*VMMessage) String

func (m *VMMessage) String() string

Directories

Path Synopsis
Package messagemock is a generated GoMock package.
Package messagemock is a generated GoMock package.

Jump to

Keyboard shortcuts

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