nodes

package
v0.2300.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package nodes provides lookup and watcher utilities for groups of nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TagsForRoleMask

func TagsForRoleMask(nodeRoles node.RolesMask) (tags []string)

TagsForRoleMask returns node lookup tags for node roles.

Types

type NodeDescriptorLookup

type NodeDescriptorLookup interface {
	// Lookup looks up a node descriptor given its identifier.
	Lookup(id signature.PublicKey) *node.Node

	// LookupByPeerID looks up a node descriptor given its P2P peer ID.
	LookupByPeerID(id signature.PublicKey) *node.Node

	// LookupTags looks up tags for a given node.
	LookupTags(id signature.PublicKey) []string

	// GetNodes returns current list of nodes.
	GetNodes() []*node.Node

	// WatchNodeUpdates subscribes to notifications about node descriptor updates.
	//
	// For non-Versioned descriptor lookups there should be NO Versioned events.
	// On subscription the current nodes will be sent immediately.
	WatchNodeUpdates() (<-chan *NodeUpdate, pubsub.ClosableSubscription, error)

	// Versioned returns true if this descriptor lookup is versioned.
	//
	// Versioned descriptor lookups are suitable to track versioned groups of nodes
	// (e.g. committees versioned by the group number), while non-versioned lookups
	// are suitable for watching non-versioned groups of nodes (e.g. all nodes,
	// or all nodes registered for a specific runtime).
	Versioned() bool
}

NodeDescriptorLookup is the node descriptor lookup interface.

func NewFilteredNodeLookup

func NewFilteredNodeLookup(nl NodeDescriptorLookup, f NodeFilterFunc) NodeDescriptorLookup

NewFilteredNodeLookup creates a NodeDescriptorLookup with a node filter function applied.

func NewRuntimeNodeLookup

func NewRuntimeNodeLookup(
	ctx context.Context,
	consensus consensus.Backend,
	runtimeID common.Namespace,
) (NodeDescriptorLookup, error)

NewRuntimeNodeLookup creates a new runtime node lookup.

Runtime node lookup watches all registered nodes for the provided runtime. Aditionally, watched nodes are tagged by node roles.

type NodeFilterFunc

type NodeFilterFunc func(*node.Node, []string) bool

NodeFilterFunc is a function that performs node filtering.

func IgnoreNodeFilter

func IgnoreNodeFilter(id signature.PublicKey) NodeFilterFunc

IgnoreNodeFilter returns a node filter function that filters out the node with the provided id.

func TagFilter

func TagFilter(tag string) NodeFilterFunc

TagFilter returns a node filter function that only includes nodes with the given tag.

func WithAllFilters

func WithAllFilters(filters ...NodeFilterFunc) NodeFilterFunc

WithAllFilters combines multiple filters into a single NodeFilterFunc that only includes nodes passing all of the provided filters.

type NodeUpdate

type NodeUpdate struct {
	Update *node.Node
	Delete *signature.PublicKey
	Reset  bool

	Freeze      *VersionEvent
	BumpVersion *VersionEvent
}

NodeUpdate is a node update.

type VersionEvent

type VersionEvent struct {
	Version int64
}

VersionEvent is a committee version event.

type VersionedNodeDescriptorWatcher

type VersionedNodeDescriptorWatcher interface {
	NodeDescriptorLookup

	// Reset clears the watcher so it doesn't watch any nodes.
	Reset()

	// Freeze freezes the node descriptor watcher so no new nodes can be watched.
	//
	// In order to watch new nodes, the caller must first call Reset. Calling this method on an
	// already frozen watcher may result in a panic.
	//
	// The version argument may be used to signal which committee version this is.
	Freeze(version int64)

	// BumpVersion updates the committee version without performing a reset.
	//
	// This method may be used when the new committee version is exactly the same as the old one
	// without introducing a needless reset.
	//
	// The watcher must have previously been frozen. Calling this method on an unfrozen watcher may
	// result in a panic.
	BumpVersion(version int64)

	// WatchNode starts watching a given node.
	//
	// It returns the latest version of the node descriptor.
	WatchNode(ctx context.Context, id signature.PublicKey) (*node.Node, error)

	// WatchNodeWithTag starts watching a given node, tagging it with a specific tag.
	//
	// It returns the latest version of the node descriptor.
	WatchNodeWithTag(ctx context.Context, id signature.PublicKey, tag string) (*node.Node, error)
}

VersionedNodeDescriptorWatcher is the versioned node descriptor watcher interface.

func NewVersionedNodeDescriptorWatcher

func NewVersionedNodeDescriptorWatcher(ctx context.Context, consensus consensus.Backend) (VersionedNodeDescriptorWatcher, error)

NewVersionedNodeDescriptorWatcher creates a new base versioned node descriptor watcher.

This watcher will only track nodes that will be explicitly marked to watch via WatchNode/WatchNodeWithTags methods.

Jump to

Keyboard shortcuts

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