isolated

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package isolated provides a pastry transport implementation that does not actually communicate with other nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMessageRoundTrip

func CheckMessageRoundTrip[M any, P MessagePointer[M]](t *rapid.T, logger *slog.Logger, nodeCount int, generator func(*Universe) *rapid.Generator[M])

CheckMessageRoundTrip performs a basic round-trip test of a message type. You must provide a rapid.Generator for your message type. Your message type must implement pastry.Message, and must be a pointer type. (We use the pointer method pattern to create instances of the message type.) You must also provide the number of local nodes that you need to store in your message type.

func RandomUniverse

func RandomUniverse(logger *slog.Logger) *rapid.Generator[*Universe]

RandomUniverse returns a property test generator that produces a local universe containing isolated nodes.

func RandomUniverseN

func RandomUniverseN(logger *slog.Logger, minSize, maxSize int) *rapid.Generator[*Universe]

RandomUniverseN returns a property test generator that produces a local universe containing isolated nodes. minSize and maxSize are the number of required _remote_ nodes in the universe, not including the local node.

Types

type MessagePointer

type MessagePointer[M any] interface {
	pastry.Message
	*M
}

type Universe

type Universe struct {
	MessageLibrary *pastry.MessageLibrary
	Transceiver    *pastry.Transceiver
	Router         *pastry.Router
	Local          *node
	Remote         []*node
	AllIdentifiers []pastry.Identifier
	SentMessages   *pastrytest.SentMessages
	// contains filtered or unexported fields
}

Universe represents an “isolated” Pastry network, which contains one “local” node and zero or more “remote” nodes. The remote nodes don't actually exist in the current program, and therefore cannot do anything. That, in turn, means that the local node cannot actually send messages to any remote nodes. Instead, the local node's transport records which outbound messages are sent. This is useful for basic testing of Pastry applications by verifying the outgoing messages that the local node enqueues in response to a (simulated) incoming message.

func NewUniverse

func NewUniverse(logger *slog.Logger, localID pastry.Identifier) *Universe

NewUniverse creates a new isolated universe. You will usually not have to call this function directly, and will instead use RandomUniverse or RandomUniverseN to create a random universe in a Rapid property test.

The local node's router starts out empty. You should use SaturateRouter to force the local node to know about every other node in the universe, or use the join protocol to have it learn about other nodes organically.

func (*Universe) AddRemoteNode

func (u *Universe) AddRemoteNode(nodeID pastry.Identifier, proximity pastry.Proximity) *node

AddRemoteNode adds a new remote node to an isolated universe. This is useful in test cases where, for instance, you need to ensure that the identifiers of the nodes relate to each other in a particular way. Panics if there is already a node with the same identifier.

func (*Universe) Format

func (u *Universe) Format(state fmt.State, verb rune)

func (*Universe) GetNode

func (u *Universe) GetNode(id pastry.Identifier) *node

GetNode returns the node (local or remote) with the given identifier.

func (*Universe) GetOwner

func (u *Universe) GetOwner(dest pastry.Identifier) pastry.Node

GetOwner returns which node in the universe owns a particular destination identifier.

func (*Universe) GetOwningIdentifier

func (u *Universe) GetOwningIdentifier(dest pastry.Identifier) pastry.Identifier

GetOwningIdentifier returns the identifier of the node in the universe that owns a particular destination identifier.

func (*Universe) GetRemoteOwner

func (u *Universe) GetRemoteOwner(dest pastry.Identifier) pastry.Node

GetRemoteOwner returns which remote node in the universe would own a particular destination identifier, assuming that the local node is not on the network yet.

func (*Universe) LocalNode

func (u *Universe) LocalNode() pastry.Node

func (*Universe) Logger

func (u *Universe) Logger() *slog.Logger

func (*Universe) RandomRemoteNode

func (u *Universe) RandomRemoteNode() *rapid.Generator[pastry.Node]

RandomNode returns a property test generator that produces a random remote node in the universe.

func (*Universe) ReadNode

func (u *Universe) ReadNode(p *pastry.MessagePayload) (pastry.Node, error)

func (*Universe) RouteLocal

func (u *Universe) RouteLocal(ctx context.Context, source pastry.Identifier, target pastry.Identifier, msg pastry.Message) error

RouteLocal serializes and routes a message via the local node's router.

func (*Universe) SaturateRouter

func (u *Universe) SaturateRouter()

SaturateRouter fills the local node's Router with every node in the universe.

func (*Universe) SendLocal

func (u *Universe) SendLocal(ctx context.Context, msg pastry.Message) error

SendLocal serializes and sends a message to the local node's transceiver.

Jump to

Keyboard shortcuts

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