registry

package
v0.2202.6 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 40 Imported by: 1

Documentation

Overview

Package registry provides a registry of runtimes supported by the running oasis-node. It serves as a central point of runtime configuration.

Index

Constants

View Source
const (
	// CfgRuntimeProvisioner configures the runtime provisioner.
	//
	// The same provisioner is used for all runtimes.
	CfgRuntimeProvisioner = "runtime.provisioner"
	// CfgRuntimePaths confgures the paths for supported runtimes.
	//
	// The value should be a vector of slices to the runtime bundles.
	CfgRuntimePaths = "runtime.paths"
	// CfgSandboxBinary configures the runtime sandbox binary location.
	CfgSandboxBinary = "runtime.sandbox.binary"
	// CfgRuntimeEnvironment sets the runtime environment. Setting an environment that does not
	// agree with the runtime descriptor or system hardware will cause an error.
	CfgRuntimeEnvironment = "runtime.environment"
	// CfgRuntimeSGXLoader configures the runtime loader binary required for SGX runtimes.
	//
	// The same loader is used for all runtimes.
	CfgRuntimeSGXLoader = "runtime.sgx.loader"

	// CfgRuntimeConfig configures node-local runtime configuration.
	CfgRuntimeConfig = "runtime.config"

	// CfgHistoryPrunerStrategy configures the history pruner strategy.
	CfgHistoryPrunerStrategy = "runtime.history.pruner.strategy"
	// CfgHistoryPrunerInterval configures the history pruner interval.
	CfgHistoryPrunerInterval = "runtime.history.pruner.interval"
	// CfgHistoryPrunerKeepLastNum configures the number of last kept
	// rounds when using the "keep last" pruner strategy.
	CfgHistoryPrunerKeepLastNum = "runtime.history.pruner.num_kept"

	// CfgRuntimeMode configures how the runtime workers should behave on this node.
	CfgRuntimeMode = "runtime.mode"

	// CfgDebugMockIDs configures mock runtime IDs for the purpose
	// of testing.
	CfgDebugMockIDs = "runtime.debug.mock_ids"
)
View Source
const (
	// RuntimeProvisionerMock is the name of the mock runtime provisioner.
	//
	// Use of this provisioner is only allowed if DebugDontBlameOasis flag is set.
	RuntimeProvisionerMock = "mock"
	// RuntimeProvisionerUnconfined is the name of the unconfined runtime provisioner that executes
	// runtimes as regular processes without any sandboxing.
	//
	// Use of this provisioner is only allowed if DebugDontBlameOasis flag is set.
	RuntimeProvisionerUnconfined = "unconfined"
	// RuntimeProvisionerSandboxed is the name of the sandboxed runtime provisioner that executes
	// runtimes as regular processes in a Linux namespaces/cgroups/SECCOMP sandbox.
	RuntimeProvisionerSandboxed = "sandboxed"
)
View Source
const (
	// RuntimeEnvironmentSGX specifies to run the runtime in SGX.
	RuntimeEnvironmentSGX = "sgx"
	// RuntimeEnvironmentELF specifies to run the runtime in the OS address space.
	//
	// Use of this runtime environment is only allowed if DebugDontBlameOasis flag is set.
	RuntimeEnvironmentELF = "elf"
	// RuntimeEnvironmentAuto specifies to run the runtime in the most appropriate location.
	RuntimeEnvironmentAuto = "auto"
)
View Source
const (
	// MaxRuntimeCount is the maximum number of runtimes that can be supported
	// by a single node.
	MaxRuntimeCount = 64

	// LocalStorageFile is the filename of the worker's local storage database.
	LocalStorageFile = "worker-local-storage.badger.db"
)
View Source
const (
	// RuntimesDir is the name of the directory located inside the node's data
	// directory which contains the per-runtime state.
	RuntimesDir = "runtimes"
)

Variables

View Source
var ErrRuntimeHostNotConfigured = errors.New("runtime/registry: runtime host not configured")

ErrRuntimeHostNotConfigured is the error returned when the runtime host is not configured for a specified runtime and a request is made to get the runtime host provisioner.

Flags has the configuration flags.

Functions

func EnsureRuntimeStateDir

func EnsureRuntimeStateDir(dataDir string, runtimeID common.Namespace) (string, error)

EnsureRuntimeStateDir ensures a specific per-runtime directory exists and returns its full path.

func GetRuntimeStateDir added in v0.2100.0

func GetRuntimeStateDir(dataDir string, runtimeID common.Namespace) string

func NewRuntimeHostHandler added in v0.2103.0

func NewRuntimeHostHandler(
	env RuntimeHostHandlerEnvironment,
	runtime Runtime,
	consensus consensus.Backend,
) protocol.Handler

NewRuntimeHostHandler returns a protocol handler that provides the required host methods for the runtime to interact with the outside world.

The passed identity may be nil.

func NewRuntimeHostNotifier added in v0.2103.0

func NewRuntimeHostNotifier(
	ctx context.Context,
	runtime Runtime,
	hostRt host.Runtime,
	consensus consensus.Backend,
) protocol.Notifier

NewRuntimeHostNotifier returns a protocol notifier that handles key manager policy updates.

func ParseRuntimeMap

func ParseRuntimeMap(rawItems []string) (map[common.Namespace]string, error)

ParseRuntimeMap parses strings in the format of <runtime-id>[:<value>] and returns them as a map of runtime IDs to value.

Types

type Registry

type Registry interface {
	// Mode returns the configured behavior of runtime workers on this node.
	Mode() RuntimeMode

	// GetRuntime returns the per-runtime interface if the runtime is supported.
	GetRuntime(runtimeID common.Namespace) (Runtime, error)

	// Runtimes returns a list of all supported runtimes.
	Runtimes() []Runtime

	// NewUnmanagedRuntime creates a new runtime that is not managed by this
	// registry.
	NewUnmanagedRuntime(ctx context.Context, runtimeID common.Namespace) (Runtime, error)

	// AddRoles adds available node roles to the runtime. Specify nil as the runtimeID
	// to set the role for all runtimes.
	AddRoles(roles node.RolesMask, runtimeID *common.Namespace) error

	// Cleanup performs post-termination cleanup.
	Cleanup()

	// FinishInitialization finalizes setup for all runtimes.
	FinishInitialization(ctx context.Context) error
}

Registry is the running node's runtime registry interface.

func New

func New(ctx context.Context, dataDir string, consensus consensus.Backend, ias ias.Endpoint) (Registry, error)

New creates a new runtime registry.

type Runtime

type Runtime interface {
	// ID is the runtime identifier.
	ID() common.Namespace

	// Mode returns the configured behavior of runtime workers on this node.
	Mode() RuntimeMode

	// DataDir returns the runtime-specific data directory.
	DataDir() string

	// RegistryDescriptor waits for the runtime to be registered and
	// then returns its registry descriptor.
	RegistryDescriptor(ctx context.Context) (*registry.Runtime, error)

	// WatchRegistryDescriptor subscribes to registry descriptor updates.
	WatchRegistryDescriptor() (<-chan *registry.Runtime, pubsub.ClosableSubscription, error)

	// ActiveDescriptor waits for runtime to be initialized and then returns
	// currently active runtime descriptor.
	ActiveDescriptor(ctx context.Context) (*registry.Runtime, error)

	// WatchActiveDescriptor subscribes to runtime active descriptor updates.
	WatchActiveDescriptor() (<-chan *registry.Runtime, pubsub.ClosableSubscription, error)

	// RegisterStorage sets the given local storage backend for the runtime.
	RegisterStorage(storage storageAPI.Backend)

	// AddRoles adds available node roles to the runtime.
	AddRoles(roles node.RolesMask)

	// HasRoles checks if the node has all of the roles specified for this runtime.
	HasRoles(roles node.RolesMask) bool

	// History returns the history for this runtime.
	History() history.History

	// Storage returns the per-runtime storage backend.
	Storage() storageAPI.Backend

	// LocalStorage returns the per-runtime local storage.
	LocalStorage() localstorage.LocalStorage

	// HasHost checks whether this runtime can be hosted by the current node.
	HasHost() bool

	// Host returns the runtime host configuration and provisioner if configured.
	Host(ctx context.Context) (map[version.Version]*runtimeHost.Config, runtimeHost.Provisioner, error)

	// HostVersions returns a list of supported runtime versions.
	HostVersions() []version.Version
}

Runtime is the running node's supported runtime interface.

type RuntimeConfig

type RuntimeConfig struct {
	// Mode is the runtime mode for this node.
	Mode RuntimeMode

	// Host contains configuration for the runtime host. It may be nil if no runtimes are to be
	// hosted by the current node.
	Host *RuntimeHostConfig

	// History configures the runtime history keeper.
	History history.Config
}

RuntimeConfig is the node runtime configuration.

func (*RuntimeConfig) Runtimes added in v0.2200.0

func (cfg *RuntimeConfig) Runtimes() (runtimes []common.Namespace)

Runtimes returns a list of configured runtimes.

type RuntimeHostConfig added in v0.2100.0

type RuntimeHostConfig struct {
	// Provisioners contains a set of supported runtime provisioners, based on TEE hardware.
	Provisioners map[node.TEEHardware]runtimeHost.Provisioner

	// Runtimes contains per-runtime provisioning configuration. Some fields may be omitted as they
	// are provided when the runtime is provisioned.
	Runtimes map[common.Namespace]map[version.Version]*runtimeHost.Config
}

RuntimeHostConfig is configuration for a node that hosts runtimes.

type RuntimeHostHandlerEnvironment added in v0.2103.0

type RuntimeHostHandlerEnvironment interface {
	// GetKeyManagerClient returns the key manager client for this runtime.
	GetKeyManagerClient(ctx context.Context) (runtimeKeymanager.Client, error)

	// GetTxPool returns the transaction pool for this runtime.
	GetTxPool(ctx context.Context) (txpool.TransactionPool, error)

	// GetNodeIdentity returns the identity of a node running this runtime.
	GetNodeIdentity(ctx context.Context) (*identity.Identity, error)
}

RuntimeHostHandlerEnvironment is the host environment interface.

type RuntimeHostHandlerFactory added in v0.2100.0

type RuntimeHostHandlerFactory interface {
	// GetRuntime returns the registered runtime for which a runtime host handler is to be created.
	GetRuntime() Runtime

	// NewRuntimeHostHandler creates a new runtime host handler.
	NewRuntimeHostHandler() protocol.Handler

	// NewRuntimeHostNotifier creates a new runtime host notifier.
	NewRuntimeHostNotifier(ctx context.Context, host host.Runtime) protocol.Notifier
}

RuntimeHostHandlerFactory is an interface that can be used to create new runtime handlers and notifiers when provisioning hosted runtimes.

type RuntimeHostNode added in v0.2100.0

type RuntimeHostNode struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RuntimeHostNode provides methods for nodes that need to host runtimes.

func NewRuntimeHostNode added in v0.2100.0

func NewRuntimeHostNode(factory RuntimeHostHandlerFactory) (*RuntimeHostNode, error)

NewRuntimeHostNode creates a new runtime host node.

func (*RuntimeHostNode) GetHostedRuntime added in v0.2100.0

func (n *RuntimeHostNode) GetHostedRuntime() host.RichRuntime

GetHostedRuntime returns the provisioned hosted runtime (if any).

func (*RuntimeHostNode) ProvisionHostedRuntime added in v0.2100.0

func (n *RuntimeHostNode) ProvisionHostedRuntime(ctx context.Context) (host.RichRuntime, protocol.Notifier, error)

ProvisionHostedRuntime provisions the configured runtime.

This method may return before the runtime is fully provisioned. The returned runtime will not be started automatically, you must call Start explicitly.

func (*RuntimeHostNode) SetHostedRuntimeVersion added in v0.2200.0

func (n *RuntimeHostNode) SetHostedRuntimeVersion(ctx context.Context, version version.Version) error

SetHostedRuntimeVersion sets the currently active version for the hosted runtime.

func (*RuntimeHostNode) WaitHostedRuntime added in v0.2103.0

func (n *RuntimeHostNode) WaitHostedRuntime(ctx context.Context) (host.RichRuntime, error)

WaitHostedRuntime waits for the hosted runtime to be provisioned and returns it.

type RuntimeMode added in v0.2200.0

type RuntimeMode string

RuntimeMode defines the behavior of runtime workers on this node.

const (
	// RuntimeModeNone is the runtime mode where runtime support is disabled and only consensus
	// layer services are enabled.
	RuntimeModeNone RuntimeMode = "none"
	// RuntimeModeCompute is the runtime mode where the node participates as a compute and storage
	// node for all the configured runtimes.
	RuntimeModeCompute RuntimeMode = "compute"
	// RuntimeModeKeymanager is the runtime mode where the node participates as a keymanager node.
	RuntimeModeKeymanager RuntimeMode = "keymanager"
	// RuntimeModeClient is the runtime mode where the node does not register and is only a stateful
	// client for all the configured runtimes. Stateful means that it keeps all runtime state.
	RuntimeModeClient RuntimeMode = "client"
	// RuntimeModeClientStateless is the runtime mode where the node does not register and is only a
	// stateless client for all the configured runtimes. No state is kept locally and the node must
	// connect to remote nodes to perform any runtime queries.
	RuntimeModeClientStateless RuntimeMode = "client-stateless"
)

func (RuntimeMode) HasLocalStorage added in v0.2202.0

func (m RuntimeMode) HasLocalStorage() bool

HasLocalStorage returns true iff the mode is one that has local storage.

func (RuntimeMode) IsClientOnly added in v0.2200.0

func (m RuntimeMode) IsClientOnly() bool

IsClientOnly returns true iff the mode is one that has the node running as a client for all configured runtimes.

func (*RuntimeMode) UnmarshalText added in v0.2200.0

func (m *RuntimeMode) UnmarshalText(text []byte) error

UnmarshalText decodes a text marshaled runtime mode.

Jump to

Keyboard shortcuts

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