message

package
v1.11.11-rc.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: BSD-3-Clause Imports: 15 Imported by: 6

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 added in v1.9.2

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

func GetDeadline added in v1.9.2

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

func GetEngineType added in v1.9.6

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

func GetRequestID added in v1.9.2

func GetRequestID(m any) (uint32, bool)

func Unwrap added in v1.9.2

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

Types

type Connected

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

func (*Connected) String added in v1.10.3

func (m *Connected) String() string

type ConnectedSubnet added in v1.9.4

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 added in v1.10.3

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 added in v1.10.3

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 added in v1.9.2

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

func (*GetAcceptedFailed) GetRequestId added in v1.9.2

func (m *GetAcceptedFailed) GetRequestId() uint32

func (*GetAcceptedFailed) String added in v1.10.3

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 added in v1.9.2

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

func (*GetAcceptedFrontierFailed) GetRequestId added in v1.9.2

func (m *GetAcceptedFrontierFailed) GetRequestId() uint32

func (*GetAcceptedFrontierFailed) String added in v1.10.3

func (m *GetAcceptedFrontierFailed) String() string

type GetAcceptedStateSummaryFailed added in v1.8.4

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

func (*GetAcceptedStateSummaryFailed) GetChainId added in v1.9.2

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

func (*GetAcceptedStateSummaryFailed) GetRequestId added in v1.9.2

func (m *GetAcceptedStateSummaryFailed) GetRequestId() uint32

func (*GetAcceptedStateSummaryFailed) String added in v1.10.3

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 added in v1.9.2

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

func (*GetAncestorsFailed) GetEngineType added in v1.9.6

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

func (*GetAncestorsFailed) GetRequestId added in v1.9.2

func (m *GetAncestorsFailed) GetRequestId() uint32

func (*GetAncestorsFailed) String added in v1.10.3

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 added in v1.9.2

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

func (*GetFailed) GetRequestId added in v1.9.2

func (m *GetFailed) GetRequestId() uint32

func (*GetFailed) String added in v1.10.3

func (m *GetFailed) String() string

type GetStateSummaryFrontierFailed added in v1.8.4

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

func (*GetStateSummaryFrontierFailed) GetChainId added in v1.9.2

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

func (*GetStateSummaryFrontierFailed) GetRequestId added in v1.9.2

func (m *GetStateSummaryFrontierFailed) GetRequestId() uint32

func (*GetStateSummaryFrontierFailed) String added in v1.10.3

type GossipRequest

type GossipRequest struct{}

func (GossipRequest) String added in v1.10.3

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 added in v1.9.3

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

func InboundAcceptedFrontier added in v1.9.3

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

func InboundAcceptedStateSummary added in v1.9.3

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

func InboundAppError added in v1.10.18

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

func InboundAppRequest added in v1.9.3

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

func InboundAppResponse added in v1.9.3

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

func InboundChits added in v1.9.3

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

func InboundGetAccepted added in v1.9.3

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

func InboundGetAcceptedFrontier added in v1.9.3

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

func InboundGetAcceptedStateSummary added in v1.9.3

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

func InboundGetStateSummaryFrontier added in v1.9.3

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

func InboundPullQuery added in v1.9.3

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

func InboundPushQuery added in v1.9.3

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

func InboundStateSummaryFrontier added in v1.9.3

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

func InternalConnected added in v1.9.2

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

func InternalConnectedSubnet added in v1.9.4

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 added in v1.9.2

func InternalDisconnected(nodeID ids.NodeID) InboundMessage

func InternalGetAcceptedFailed added in v1.9.2

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

func InternalGetAcceptedFrontierFailed added in v1.9.2

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

func InternalGetAcceptedStateSummaryFailed added in v1.9.2

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

func InternalGetAncestorsFailed added in v1.9.2

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

func InternalGetFailed added in v1.9.2

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

func InternalGetStateSummaryFrontierFailed added in v1.9.2

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

func InternalGossipRequest added in v1.9.2

func InternalGossipRequest(
	nodeID ids.NodeID,
) InboundMessage

func InternalQueryFailed added in v1.9.2

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

func InternalTimeout added in v1.9.2

func InternalTimeout(nodeID ids.NodeID) InboundMessage

func InternalVMMessage added in v1.9.2

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 added in v1.9.2

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 added in v1.9.2

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

func (*QueryFailed) GetRequestId added in v1.9.2

func (m *QueryFailed) GetRequestId() uint32

func (*QueryFailed) String added in v1.10.3

func (m *QueryFailed) String() string

type Timeout

type Timeout struct{}

func (Timeout) String added in v1.10.3

func (Timeout) String() string

type VMMessage

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

func (*VMMessage) String added in v1.10.3

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