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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChainAlreadyRegistered is returned when trying to register a chain that's already registered
	ErrChainAlreadyRegistered = errors.New("chain already registered")

	// ErrChainNotRegistered is returned when trying to unregister a chain that's not registered
	ErrChainNotRegistered = errors.New("chain not registered")

	// ErrNoChainID is returned when a message doesn't contain a chain ID
	ErrNoChainID = errors.New("message does not contain chain ID")

	// ErrNilHandler is returned when trying to register a nil handler
	ErrNilHandler = errors.New("handler cannot be nil")

	// ErrRouterNotInitialized is returned when router is used before initialization
	ErrRouterNotInitialized = errors.New("router not initialized")
)

Functions

This section is empty.

Types

type ChainHandler

type ChainHandler interface {
	HandleInbound(ctx context.Context, msg message.InboundMessage)
	HealthCheck(ctx context.Context) (interface{}, error)
}

ChainHandler handles messages for a specific chain

type HealthConfig

type HealthConfig struct {
	MaxTimeSinceMsgReceived time.Duration
	MaxTimeSinceMsgSent     time.Duration
	MaxPortionSendQueueFull float64
	MaxSendFailRate         float64
	SendFailRateHalflife    time.Duration
}

HealthConfig contains health check configuration

type Router

type Router interface {
	// Initialize the router
	Initialize(
		nodeID ids.NodeID,
		logger log.Logger,
		timeoutManager timer.AdaptiveTimeoutManager,
		closeTimeout time.Duration,
		criticalChains set.Set[ids.ID],
		sybilProtectionEnabled bool,
		onFatal func(int),
		healthConfig HealthConfig,
		reg metric.Registerer,
		namespace string,
	) error

	// RegisterChain registers a handler for a specific chain
	RegisterChain(chainID ids.ID, handler ChainHandler) error

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

	// HandleInbound routes an inbound message to the appropriate chain
	HandleInbound(ctx context.Context, msg message.InboundMessage)

	// Connected is called when a peer connects
	Connected(nodeID ids.NodeID, nodeVersion *version.Application, netID ids.ID)

	// Disconnected is called when a peer disconnects
	Disconnected(nodeID ids.NodeID)

	// RegisterRequest registers an outbound request
	RegisterRequest(
		ctx context.Context,
		nodeID ids.NodeID,
		chainID ids.ID,
		requestID uint32,
		op message.Op,
		timeoutMsg message.InboundMessage,
		engineType p2p.EngineType,
	)

	// RegisterRequests registers outbound requests to multiple nodes
	RegisterRequests(
		ctx context.Context,
		nodeIDs set.Set[ids.NodeID],
		chainID ids.ID,
		requestID uint32,
		op message.Op,
		timeoutMsg message.InboundMessage,
		engineType p2p.EngineType,
	)

	// HealthCheck returns the router's health status
	HealthCheck(ctx context.Context) (interface{}, error)

	// Shutdown gracefully shuts down the router
	Shutdown(ctx context.Context)
}

Router routes messages between chains and manages network connections

func NewRouter

func NewRouter() Router

NewRouter creates a new router

Jump to

Keyboard shortcuts

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