router

package
v1.12.0-initial-poc.4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: BSD-3-Clause Imports: 25 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainRouter

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

ChainRouter routes incoming messages from the validator network to the consensus engines that the messages are intended for. Note that consensus engines are uniquely identified by the ID of the chain that they are working on. Invariant: P-chain must be registered before processing any messages

func (*ChainRouter) AddChain

func (cr *ChainRouter) AddChain(ctx context.Context, chain handler.Handler)

AddChain registers the specified chain so that incoming messages can be routed to it

func (*ChainRouter) Benched added in v1.4.3

func (cr *ChainRouter) Benched(chainID ids.ID, nodeID ids.NodeID)

Benched routes an incoming notification that a validator was benched

func (*ChainRouter) Connected added in v0.8.2

func (cr *ChainRouter) Connected(nodeID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID)

Connected routes an incoming notification that a validator was just connected

func (*ChainRouter) Disconnected added in v0.8.2

func (cr *ChainRouter) Disconnected(nodeID ids.NodeID)

Disconnected routes an incoming notification that a validator was connected

func (*ChainRouter) HandleInbound added in v1.6.4

func (cr *ChainRouter) HandleInbound(ctx context.Context, msg message.InboundMessage)

func (*ChainRouter) HealthCheck added in v1.2.1

func (cr *ChainRouter) HealthCheck(context.Context) (interface{}, error)

HealthCheck returns results of router health checks. Returns: 1) Information about health check results 2) An error if the health check reports unhealthy

func (*ChainRouter) Initialize

func (cr *ChainRouter) Initialize(
	nodeID ids.NodeID,
	log logging.Logger,
	timeoutManager timeout.Manager,
	closeTimeout time.Duration,
	criticalChains set.Set[ids.ID],
	sybilProtectionEnabled bool,
	trackedSubnets set.Set[ids.ID],
	onFatal func(exitCode int),
	healthConfig HealthConfig,
	reg prometheus.Registerer,
) error

Initialize the router.

When this router receives an incoming message, it cancels the timeout in [timeouts] associated with the request that caused the incoming message, if applicable.

func (*ChainRouter) RegisterRequest added in v1.2.1

func (cr *ChainRouter) RegisterRequest(
	ctx context.Context,
	nodeID ids.NodeID,
	chainID ids.ID,
	requestID uint32,
	op message.Op,
	timeoutMsg message.InboundMessage,
	engineType p2p.EngineType,
)

RegisterRequest marks that we should expect to receive a reply for a request from the given node's [chainID] and the reply should have the given requestID.

The type of message we expect is [op].

Every registered request must be cleared either by receiving a valid reply and passing it to the appropriate chain or by a timeout. This method registers a timeout that calls such methods if we don't get a reply in time.

func (*ChainRouter) Shutdown

func (cr *ChainRouter) Shutdown(ctx context.Context)

Shutdown shuts down this router

func (*ChainRouter) Unbenched added in v1.4.3

func (cr *ChainRouter) Unbenched(chainID ids.ID, nodeID ids.NodeID)

Unbenched routes an incoming notification that a validator was just unbenched

type ExternalHandler added in v1.7.7

type ExternalHandler interface {
	InboundHandler

	Connected(nodeID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID)
	Disconnected(nodeID ids.NodeID)
}

ExternalHandler handles messages from external parties

type HealthConfig added in v1.2.1

type HealthConfig struct {
	// Reports unhealthy if we drop more than [MaxDropRate] of messages
	MaxDropRate float64 `json:"maxDropRate"`

	// Halflife of averager used to calculate the message drop rate
	// Must be > 0.
	// Larger value --> Drop rate affected less by recent messages
	MaxDropRateHalflife time.Duration `json:"maxDropRateHalflife"`

	// Reports unhealthy if more than this number of requests are outstanding.
	// Must be > 0
	MaxOutstandingRequests int `json:"maxOutstandingRequests"`

	// Reports unhealthy if there is a request outstanding for longer than this
	MaxOutstandingDuration time.Duration `json:"maxOutstandingDuration"`

	// Reports unhealthy if there is at least 1 outstanding not processed
	// before this mark
	MaxRunTimeRequests time.Duration `json:"maxRunTimeRequests"`
}

HealthConfig describes parameters for router health checks.

type InboundHandler added in v1.7.7

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

InboundHandler handles inbound messages

type InboundHandlerFunc added in v1.7.7

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

The ExternalRouterFunc type is an adapter to allow the use of ordinary functions as ExternalRouters. If f is a function with the appropriate signature, ExternalRouterFunc(f) is an ExternalRouter that calls f.

func (InboundHandlerFunc) HandleInbound added in v1.7.7

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

type InternalHandler added in v1.7.7

type InternalHandler interface {
	benchlist.Benchable

	RegisterRequest(
		ctx context.Context,
		nodeID ids.NodeID,
		chainID ids.ID,
		requestID uint32,
		op message.Op,
		failedMsg message.InboundMessage,
		engineType p2p.EngineType,
	)
}

InternalHandler deals with messages internal to this node

type Router

type Router interface {
	ExternalHandler
	InternalHandler

	Initialize(
		nodeID ids.NodeID,
		log logging.Logger,
		timeouts timeout.Manager,
		shutdownTimeout time.Duration,
		criticalChains set.Set[ids.ID],
		sybilProtectionEnabled bool,
		trackedSubnets set.Set[ids.ID],
		onFatal func(exitCode int),
		healthConfig HealthConfig,
		reg prometheus.Registerer,
	) error
	Shutdown(context.Context)
	AddChain(ctx context.Context, chain handler.Handler)
	health.Checker
}

Router routes consensus messages to the Handler of the consensus engine that the messages are intended for

func Trace added in v1.9.1

func Trace(router Router, tracer trace.Tracer) Router

Directories

Path Synopsis
Package routermock is a generated GoMock package.
Package routermock is a generated GoMock package.

Jump to

Keyboard shortcuts

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