loadroute

package
v0.0.0-...-79ba347 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRoute

func CheckRoute(builder Builder, a container.SizeEstimation, route []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 context.Context, passed []ServerInfo) context.Context

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

Passing the result to Router.InitWriter method will allow you to continue this route.

Types

type Builder

type Builder interface {
	// NextStage must return next group of route points for the value a
	// based on the passed route.
	//
	// 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.
	// If there are more than one point to go and the last passed point is included
	// in that list (means that point is the last point in one of the route groups),
	// returned route must contain nil point that should be interpreted as signal to,
	// among sending to other route points, save the announcement in that point.
	NextStage(a container.SizeEstimation, passed []ServerInfo) ([]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 *logger.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 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 ServerInfo) (loadcontroller.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 used container space values over the network.

For each fixed pair (container ID, 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

New creates a new instance of the Router.

Panics if at least one value of the parameters is invalid.

The created Router does not require additional initialization and is completely ready for work.

func (*Router) InitWriter

func (r *Router) InitWriter(ctx context.Context) (loadcontroller.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.

type ServerInfo

type ServerInfo interface {
	// PublicKey returns public key of the node
	// from the route in a binary representation.
	PublicKey() []byte

	// Iterates over network addresses of the node
	// in the route. Breaks iterating on true return
	// of the handler.
	IterateAddresses(func(string) bool)

	// Returns number of server's network addresses.
	NumberOfAddresses() int

	// ExternalAddresses returns external node's addresses.
	ExternalAddresses() []string
}

ServerInfo describes a set of characteristics of a point in a route.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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