message

package
v1.7.17-rc.19 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: BSD-3-Clause Imports: 15 Imported by: 44

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,
		ChitsV2,
		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,
	}
	ConsensusOps = append(ConsensusExternalOps, ConsensusInternalOps...)

	ExternalOps = append(ConsensusExternalOps, HandshakeOps...)

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

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

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

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

		QueryFailed: Chits,

		AppRequestFailed:              AppResponse,
		GetStateSummaryFrontierFailed: StateSummaryFrontier,
		GetAcceptedStateSummaryFailed: AcceptedStateSummary,
	}
	UnrequestedOps = map[Op]struct{}{
		GetAcceptedFrontier:     {},
		GetAccepted:             {},
		GetAncestors:            {},
		Get:                     {},
		PushQuery:               {},
		PullQuery:               {},
		AppRequest:              {},
		AppGossip:               {},
		GetStateSummaryFrontier: {},
		GetAcceptedStateSummary: {},
	}
)

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Packer
	Parser
}

func NewCodecWithMemoryPool

func NewCodecWithMemoryPool(namespace string, metrics prometheus.Registerer, maxMessageSize int64, maxMessageTimeout time.Duration) (Codec, error)

type Creator

func NewCreator

func NewCreator(metrics prometheus.Registerer, compressionEnabled bool, parentNamespace string, 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
)

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

func (Field) Packer

func (f Field) Packer() func(*wrappers.Packer, interface{})

Packer returns the packer function that can be used to pack this field.

func (Field) String

func (f Field) String() string

func (Field) Unpacker

func (f Field) Unpacker() func(*wrappers.Packer) interface{}

Unpacker returns the unpacker function that can be used to unpack this field.

type InboundMessage

type InboundMessage interface {
	fmt.Stringer

	BytesSavedCompression() int
	Op() Op
	Get(Field) interface{}
	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 {
	Parser

	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,
		containerID ids.ID,
		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

	InboundChitsV2(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
		containerID 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,
		containerID ids.ID,
		container []byte,
		nodeID ids.NodeID,
	) InboundMessage // used in UTs only
}

func NewInboundBuilder

func NewInboundBuilder(c Codec) InboundMsgBuilder

type InternalMsgBuilder

type InternalMsgBuilder interface {
	InternalFailedRequest(
		op Op,
		nodeID ids.NodeID,
		chainID ids.ID,
		requestID uint32,
	) 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
	// linearize dag
	ChitsV2

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

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

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

	AddRef()
	DecRef()
}

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,
		containerID ids.ID,
		container []byte,
	) (OutboundMessage, error)

	PushQuery(
		chainID ids.ID,
		requestID uint32,
		deadline time.Duration,
		containerID ids.ID,
		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)

	ChitsV2(
		chainID ids.ID,
		requestID uint32,
		containerIDs []ids.ID,
		containerID 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.

func NewOutboundBuilder

func NewOutboundBuilder(c Codec, enableCompression bool) OutboundMsgBuilder

type Packer

type Packer interface {
	Pack(
		op Op,
		fieldValues map[Field]interface{},
		compress bool,
		bypassThrottling bool,
	) (OutboundMessage, error)
}

type Parser

type Parser 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)
}

type TestMsg added in v1.7.6

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

func NewTestMsg added in v1.7.6

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

func (*TestMsg) AddRef added in v1.7.6

func (*TestMsg) AddRef()

func (*TestMsg) BypassThrottling added in v1.7.6

func (m *TestMsg) BypassThrottling() bool

func (*TestMsg) Bytes added in v1.7.6

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

func (*TestMsg) BytesSavedCompression added in v1.7.6

func (*TestMsg) BytesSavedCompression() int

func (*TestMsg) DecRef added in v1.7.6

func (*TestMsg) DecRef()

func (*TestMsg) Get added in v1.7.6

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

func (*TestMsg) Op added in v1.7.6

func (m *TestMsg) Op() Op

Jump to

Keyboard shortcuts

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