message

package
v1.7.2-rc.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: BSD-3-Clause Imports: 14 Imported by: 43

Documentation

Index

Constants

This section is empty.

Variables

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

	// List of all consensus request message types
	ConsensusRequestOps = []Op{
		GetAcceptedFrontier,
		GetAccepted,
		GetAncestors,
		Get,
		PushQuery,
		PullQuery,
		AppRequest,
	}
	ConsensusResponseOps = []Op{
		AcceptedFrontier,
		Accepted,
		MultiPut,
		Put,
		Chits,
		AppResponse,
	}
	// 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,
		GetFailed,
		QueryFailed,
		GetAncestorsFailed,
		AppRequestFailed,
		Timeout,
		Connected,
		Disconnected,
		Notify,
		GossipRequest,
	}
	ConsensusOps = append(ConsensusExternalOps, ConsensusInternalOps...)

	ExternalOps = append(ConsensusExternalOps, HandshakeOps...)

	RequestToResponseOps = map[Op]Op{
		GetAcceptedFrontier: AcceptedFrontier,
		GetAccepted:         Accepted,
		GetAncestors:        MultiPut,
		Get:                 Put,
		PushQuery:           Chits,
		PullQuery:           Chits,
		AppRequest:          AppResponse,
	}
	ResponseToFailedOps = map[Op]Op{
		AcceptedFrontier: GetAcceptedFrontierFailed,
		Accepted:         GetAcceptedFailed,
		MultiPut:         GetAncestorsFailed,
		Put:              GetFailed,
		Chits:            QueryFailed,
		AppResponse:      AppRequestFailed,
	}
	FailedToResponseOps = map[Op]Op{
		GetAcceptedFrontierFailed: AcceptedFrontier,
		GetAcceptedFailed:         Accepted,
		GetAncestorsFailed:        MultiPut,
		GetFailed:                 Put,
		QueryFailed:               Chits,
		AppRequestFailed:          AppResponse,
	}
	UnrequestedOps = map[Op]struct{}{
		GetAcceptedFrontier: {},
		GetAccepted:         {},
		GetAncestors:        {},
		Get:                 {},
		PushQuery:           {},
		PullQuery:           {},
		AppRequest:          {},
		AppGossip:           {},
	}
)

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Packer
	Parser
}

func NewCodecWithMemoryPool

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

type Creator

func NewCreator

func NewCreator(metrics prometheus.Registerer, compressionEnabled bool, parentNamespace string) (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                           // Used in handshake
	MyTime                           // Used in handshake
	IP                               // Used in handshake
	Peers                            // 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 MultiPut
	SigBytes                         // Used in handshake / peer gossiping
	VersionTime                      // Used in handshake / peer gossiping
	SignedPeers                      // Used in peer gossiping
	TrackedSubnets                   // Used in handshake / peer gossiping
	AppBytes                         // Used at application level
	VMMessage                        // Used internally
	Uptime                           // Used for Pong
)

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.ShortID
	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

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

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

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

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

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

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

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

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

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

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

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

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

func NewInboundBuilder

func NewInboundBuilder(c Codec) InboundMsgBuilder

type InternalMsgBuilder

type InternalMsgBuilder interface {
	InternalFailedRequest(
		op Op,
		nodeID ids.ShortID,
		chainID ids.ID,
		requestID uint32,
	) InboundMessage

	InternalTimeout(nodeID ids.ShortID) InboundMessage
	InternalConnected(nodeID ids.ShortID) InboundMessage
	InternalDisconnected(nodeID ids.ShortID) InboundMessage
	InternalVMMessage(nodeID ids.ShortID, notification uint32) InboundMessage
	InternalGossipRequest(nodeID ids.ShortID) InboundMessage
}

func NewInternalBuilder

func NewInternalBuilder() InternalMsgBuilder

type Op

type Op byte

Op is an opcode

const (
	// Handshake:
	GetVersion Op = iota

	GetPeerList
	// TODO: NetworkUpgrade/Rename this to Pong
	UptimePong
	Ping
	// TODO: NetworkUpgrade/delete this in favor of UptimePong
	Pong
	// Bootstrapping:
	GetAcceptedFrontier
	AcceptedFrontier
	GetAccepted
	Accepted
	GetAncestors
	MultiPut
	// Consensus:
	Get
	Put
	PushQuery
	PullQuery
	Chits

	PeerList
	Version
	// Application level:
	AppRequest
	AppResponse
	AppGossip

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

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 (Op) Compressable

func (op Op) Compressable() bool

func (Op) String

func (op Op) String() string

type OutboundMessage

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

	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 {
	GetVersion() (OutboundMessage, error)

	Version(
		networkID,
		nodeID uint32,
		myTime uint64,
		ip utils.IPDesc,
		myVersion string,
		myVersionTime uint64,
		sig []byte,
		trackedSubnets []ids.ID,
	) (OutboundMessage, error)

	GetPeerList() (OutboundMessage, error)

	PeerList(peers []utils.IPCertDesc) (OutboundMessage, error)

	Ping() (OutboundMessage, error)

	Pong() (OutboundMessage, error)

	UptimePong(uptimePercentage uint8) (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)

	MultiPut(
		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)

	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,
	) (OutboundMessage, error)
}

type Parser

type Parser interface {
	SetTime(t time.Time) // useful in UTs
	Parse(bytes []byte, nodeID ids.ShortID, onFinishedHandling func()) (InboundMessage, error)
}

Jump to

Keyboard shortcuts

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