router

package
v1.18.1-qos Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// HandleInbound handles inbound messages
	HandleInbound(ctx context.Context, msg HandlerMessage) error

	// HandleOutbound handles outbound messages
	HandleOutbound(ctx context.Context, msg HandlerMessage) error

	// Connected handles node connection events
	Connected(ctx context.Context, nodeID ids.NodeID) error

	// Disconnected handles node disconnection events
	Disconnected(ctx context.Context, nodeID ids.NodeID) error
}

Handler handles network messages for a specific chain

type HandlerMessage

type HandlerMessage struct {
	NodeID    ids.NodeID
	RequestID uint32
	Op        Op
	Message   []byte
}

HandlerMessage represents a message for chain handlers

type InboundHandler

type InboundHandler interface {
	HandleInbound(ctx context.Context, msg message.InboundMessage)
}

InboundHandler handles inbound messages

type InboundHandlerFunc

type InboundHandlerFunc func(ctx context.Context, msg message.InboundMessage)

InboundHandlerFunc is a function that implements InboundHandler

func (InboundHandlerFunc) HandleInbound

func (f InboundHandlerFunc) HandleInbound(ctx context.Context, msg message.InboundMessage)

HandleInbound implements InboundHandler

type Message

type Message struct {
	NodeIDs   []ids.NodeID
	RequestID uint32
	Op        Op
	Bytes     []byte
}

Message represents a network message

type Op

type Op byte

Op represents a network operation

const (
	// GetAcceptedFrontier requests accepted frontier
	GetAcceptedFrontier Op = iota
	// AcceptedFrontier is accepted frontier response
	AcceptedFrontier
	// GetAccepted requests accepted items
	GetAccepted
	// Accepted is accepted items response
	Accepted
	// Get requests an item
	Get
	// Put provides an item
	Put
	// PushQuery sends a push query
	PushQuery
	// PullQuery sends a pull query
	PullQuery
	// Chits is query response
	Chits
)

type Router

type Router interface {
	// HandleInbound handles an inbound message
	HandleInbound(ctx context.Context, msg message.InboundMessage)

	// RegisterHandler registers a handler for a specific chain
	RegisterHandler(chainID ids.ID, handler Handler)

	// UnregisterHandler removes a handler for a specific chain
	UnregisterHandler(chainID ids.ID)

	// Deprecated is required for backward compatibility
	Deprecated()
}

Router is the main interface for message routing This replaces the deprecated consensus/networking/router package

func NewRouter

func NewRouter(logger log.Logger) Router

NewRouter creates a new router instance

type Sender

type Sender interface {
	// Send sends a message to the specified nodes
	Send(ctx context.Context, msg Message) error

	// SendAppRequest sends an app request to the specified nodes
	SendAppRequest(ctx context.Context, nodeIDs []ids.NodeID, requestID uint32, payload []byte) error

	// SendAppResponse sends an app response to a specific node
	SendAppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, payload []byte) error

	// SendAppGossip sends app gossip to the specified nodes
	SendAppGossip(ctx context.Context, nodeIDs []ids.NodeID, payload []byte) error
}

Sender sends messages to network peers

func NewSender

func NewSender(logger log.Logger) Sender

NewSender creates a new sender instance

Jump to

Keyboard shortcuts

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