mino

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 5 Imported by: 12

Documentation

Overview

Package mino defines a minimalist network overlay to communicate between a set of participants.

The overlay provides two primitives to send messages: Call that will directly contact the addresses and Stream that will build a network and distribute the load to forward the messages.

Documentation Last Review: 07.10.2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address interface {
	encoding.TextMarshaler

	// Equal returns true when both addresses are similar.
	Equal(other Address) bool

	// String returns a string representation of the address.
	String() string

	// ConnectionType returns the type of connection for this Address
	ConnectionType() AddressConnectionType
}

Address is a representation of a node's address.

type AddressConnectionType

type AddressConnectionType int32

AddressConnectionType indicates how to connect to the remote end.

const (
	// ACTgRPC is a plain text connection
	ACTgRPC AddressConnectionType = iota
	// ACTgRPCS is a self-signed TLS secured grpc connection
	ACTgRPCS
	// ACThttps is a publicly signed TLS secured grpc connection
	ACThttps
)

type AddressFactory

type AddressFactory interface {
	serde.Factory

	// FromText returns the address of the text.
	FromText(text []byte) Address
}

AddressFactory is the factory to deserialize addresses.

type AddressIterator

type AddressIterator interface {
	// Seek moves the iterator to a specific index.
	Seek(int)

	// HasNext returns true if a address is available, false if the iterator is
	// exhausted.
	HasNext() bool

	// GetNext returns the next address in case HasNext returns true, otherwise
	// no assumption can be done.
	GetNext() Address
}

AddressIterator is an iterator over the list of addresses of a membership.

func NewAddressIterator

func NewAddressIterator(addrs []Address) AddressIterator

NewAddressIterator returns a new address iterator.

type Filter

type Filter struct {
	// Indices indicates the indexes of the elements that must be included. This
	// list if updated based on the filter that we apply. For example, [0,3]
	// tells that this filter keeps 2 elements from the underlying data
	// structure we filter that are stored at indexes 0, 3. This list is always
	// sorted and can be shifted in a circular way.
	Indices []int
}

Filter is a set of parameters for the Players.Take function.

func ApplyFilters

func ApplyFilters(filters []FilterUpdater) *Filter

ApplyFilters applies the filters and return the result.

type FilterUpdater

type FilterUpdater func(*Filter)

FilterUpdater is a function to update the filters.

func IndexFilter

func IndexFilter(index int) FilterUpdater

IndexFilter is a filter to include a given index.

func ListFilter

func ListFilter(indices []int) FilterUpdater

ListFilter is a filter to set the list of indices. It will override any index previously set.

func RangeFilter

func RangeFilter(start, end int) FilterUpdater

RangeFilter is a filter to include a range of indices.

func RotateFilter

func RotateFilter(n int) FilterUpdater

RotateFilter is a filter to rotate the indices. When n is above zero, it will rotate by n steps on the left and when n is below, it will do the same on the right. The behaviour is unknown if not used as the last filter as next updaters could change the order.

type Handler

type Handler interface {
	// Process handles a single request by producing the response according to
	// the request message.
	Process(req Request) (resp serde.Message, err error)

	// Stream is a handler for a stream request. It will open a stream with the
	// participants.
	Stream(out Sender, in Receiver) error
}

Handler is the interface to implement to create a public endpoint.

type Mino

type Mino interface {
	GetAddressFactory() AddressFactory

	// GetAddress returns the address that other participants should use to contact
	// this instance.
	GetAddress() Address

	// WithSegment returns a new mino instance that will have its URI path
	// extended with the provided segment.
	WithSegment(segment string) Mino

	// CreateRPC creates an RPC that can send to and receive from a unique
	// URI which is computed with URI = (segment || segment || ... || name). If
	// the combination already exists, it will return an error.
	CreateRPC(name string, h Handler, f serde.Factory) (RPC, error)
}

Mino is an abstraction of a overlay network. It provides primitives to send messages to a set of participants.

It uses segments to separate the different RPCs of multiple services in a URI-like manner (i.e. /my/awesome/rpc has _my_ and _awesome_ segments).

type Players

type Players interface {
	// Take should a subset of the players according to the filters.
	Take(...FilterUpdater) Players

	// AddressIterator returns an iterator that prevents changes of the
	// underlying array and save memory by iterating over the same array.
	AddressIterator() AddressIterator

	// Len returns the length of the set of players.
	Len() int
}

Players is an interface to represent a set of nodes participating in a message passing protocol.

func NewAddresses

func NewAddresses(addrs ...Address) Players

NewAddresses is a helper to instantiate a Players interface with only a few addresses.

type RPC

type RPC interface {
	// Call is a basic request to one or multiple distant peers. It directly
	// contacts all the players and thus expects a reasonable number of peers.
	//
	// The response channel must be closed once the request ends in a result,
	// either a reply or an error.
	Call(ctx context.Context, req serde.Message, players Players) (<-chan Response, error)

	// Stream is a persistent request that will be closed only when the
	// orchestrator is done or an error has occured, or the context is done.
	Stream(ctx context.Context, players Players) (Sender, Receiver, error)
}

RPC is an abstraction of a distributed Remote Procedure Call.

func MustCreateRPC

func MustCreateRPC(m Mino, name string, h Handler, f serde.Factory) RPC

MustCreateRPC creates the RPC with the given name, handler and factory to the Mino instance and expects the operation to be successful, otherwise it will panic.

type Receiver

type Receiver interface {
	// Recv waits for a message to send received from the stream. It returns the
	// address of the original sender and the message, or a message if the
	// stream is closed or the context is done.
	Recv(context.Context) (Address, serde.Message, error)
}

Receiver is an abstraction to receive messages from a stream in the context of a distributed RPC.

type Request

type Request struct {
	// Address is the address of the sender of the request.
	Address Address

	// Message is the message of the request.
	Message serde.Message
}

Request is a wrapper around the context of a message received from a player and that needs to be processed by the node. It provides some useful information about the network layer.

type Response

type Response interface {
	// GetFrom returns the address of the source of the reply.
	GetFrom() Address

	// GetMessageOrError returns the message, or an error if something wrong
	// happened.
	GetMessageOrError() (serde.Message, error)
}

Response represents the response of a distributed RPC. It provides the address of the original sender and the reply, or an error if something went wrong upfront.

func NewResponse

func NewResponse(from Address, msg serde.Message) Response

NewResponse creates a response that will return the message.

func NewResponseWithError

func NewResponseWithError(from Address, err error) Response

NewResponseWithError creates a response that will return an error instead of a message.

type Sender

type Sender interface {
	// Send sends the message to all the addresses. It returns a channel that
	// will be populated with errors coming from the network layer if the
	// message cannot be sent. The channel must be closed after the message has
	// been sent or failed to be sent.
	Send(msg serde.Message, addrs ...Address) <-chan error
}

Sender is an abstraction to send messages to a stream in the context of a distributed RPC.

type UnsupportedHandler

type UnsupportedHandler struct{}

UnsupportedHandler implements the Handler interface with default behaviour so that an implementation can focus on its needs.

func (UnsupportedHandler) Process

func (h UnsupportedHandler) Process(req Request) (serde.Message, error)

Process is the default implementation for a handler. It will return an error.

func (UnsupportedHandler) Stream

func (h UnsupportedHandler) Stream(in Sender, out Receiver) error

Stream is the default implementation for a handler. It will return an error.

Directories

Path Synopsis
Package gossip defines an abstraction to gossip messages to a defined set of participants.
Package gossip defines an abstraction to gossip messages to a defined set of participants.
Package minoch is an implementation of Mino that is using channels and a local manager to exchange messages.
Package minoch is an implementation of Mino that is using channels and a local manager to exchange messages.
certs
Package certs defines a certificate store that will provide primitives to store and get certificates for a given address.
Package certs defines a certificate store that will provide primitives to store and get certificates for a given address.
controller
Package controller implements a controller for minogrpc.
Package controller implements a controller for minogrpc.
ptypes
Package ptypes contains the protobuf definitions for the implementation of minogrpc.
Package ptypes contains the protobuf definitions for the implementation of minogrpc.
session
Package session defines an abstraction of a session during a distributed RPC.
Package session defines an abstraction of a session during a distributed RPC.
tokens
Package tokens defines a token holder to generate and validate access tokens.
Package tokens defines a token holder to generate and validate access tokens.
Package router defines the primitives to route a packet among a set of participants.
Package router defines the primitives to route a packet among a set of participants.
tree
Package tree is an implementation of a tree-based routing algorithm.
Package tree is an implementation of a tree-based routing algorithm.
tree/types
Package types implements the packet and handshake messages for the tree routing algorithm.
Package types implements the packet and handshake messages for the tree routing algorithm.

Jump to

Keyboard shortcuts

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