router

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRoute

func CheckRoute(builder Builder, epoch uint64, t reputation.Trust, route []common.ServerInfo) error

CheckRoute checks if the route is a route correctly constructed by the builder for value a.

Returns nil if route is correct, otherwise an error clarifying the inconsistency.

func NewRouteContext

func NewRouteContext(ctx common.Context, passed []common.ServerInfo) common.Context

NewRouteContext wraps the main context of value passing with its traversal route and epoch.

Types

type Builder

type Builder interface {
	// NextStage must return next group of route points
	// for passed epoch and trust values.
	// Implementation must take into account already passed route points.
	//
	// Empty passed list means being at the starting point of the route.
	//
	// Must return empty list and no error if the endpoint of the route is reached.
	NextStage(epoch uint64, t reputation.Trust, passed []common.ServerInfo) ([]common.ServerInfo, error)
}

Builder groups methods to route values in the network.

type Option

type Option func(*options)

Option sets an optional parameter of Router.

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger returns Option to specify logging component.

type Prm

type Prm struct {
	// Characteristics of the local node's server.
	//
	// Must not be nil.
	LocalServerInfo common.ServerInfo

	// Component for sending values to a fixed route point.
	//
	// Must not be nil.
	RemoteWriterProvider RemoteWriterProvider

	// Route planner.
	//
	// Must not be nil.
	Builder Builder
}

Prm groups the required parameters of the Router's constructor.

All values must comply with the requirements imposed on them. Passing incorrect parameter values will result in constructor failure (error or panic depending on the implementation).

type RemoteWriterProvider

type RemoteWriterProvider interface {
	// InitRemote must return WriterProvider to the route point
	// corresponding to info.
	//
	// Nil info matches the end of the route.
	InitRemote(info common.ServerInfo) (common.WriterProvider, error)
}

RemoteWriterProvider describes the component for sending values to a fixed route point.

type Router

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

Router represents component responsible for routing local trust values over the network.

For each fixed pair (node peer, epoch) there is a single value route on the network. Router provides the interface for writing values to the next point of the route.

For correct operation, Router must be created using the constructor (New) based on the required parameters and optional components. After successful creation, the Router is immediately ready to work through API.

func New

func New(prm Prm, opts ...Option) *Router

func (*Router) InitWriter

func (r *Router) InitWriter(ctx common.Context) (common.Writer, error)

InitWriter initializes and returns Writer that sends each value to its next route point.

If ctx was created by NewRouteContext, then the traversed route is taken into account, and the value will be sent to its continuation. Otherwise, the route will be laid from scratch and the value will be sent to its primary point.

After building a list of remote points of the next leg of the route, the value is sent sequentially to all of them. If any transmissions (even all) fail, an error will not be returned.

Close of the composed Writer calls Close method on each internal Writer generated in runtime and never returns an error.

Always returns nil error.

Jump to

Keyboard shortcuts

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