node

package
v0.0.0-...-e5f450f Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const LifecycleTimeout = time.Second * 15

Variables

View Source
var (
	// ErrOpened is thrown on attempt to open already open/in-use Store.
	ErrOpened = errors.New("node: store is in use")
	// ErrNotInited is thrown on attempt to open Store without initialization.
	ErrNotInited = errors.New("node: store is not initialized")
)

Functions

func Init

func Init(path string, tp Type) error

Init initializes the Node FileSystem Store for the given Node Type 'tp' in the directory under 'path' with default Config. Options are applied over default Config and persisted on disk.

func IsInit

func IsInit(path string) bool

IsInit checks whether FileSystem Store was setup under given 'path'. If any required file/subdirectory does not exist, then false is reported.

func SaveConfig

func SaveConfig(path string, cfg *Config) error

SaveConfig saves Config 'cfg' under the given 'path'.

Types

type Config

type Config struct {
	P2P p2p.Config
}

Config is main configuration structure for a Node. It combines configuration units for all Node subsystems.

func DefaultConfig

func DefaultConfig(tp Type) *Config

DefaultConfig provides a default Config for a given Node Type 'tp'. NOTE: Currently, configs are identical, but this will change.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads Config from the given 'path'.

func (*Config) Decode

func (cfg *Config) Decode(r io.Reader) error

Decode pulls a Config from a given reader r.

func (*Config) Encode

func (cfg *Config) Encode(w io.Writer) error

Encode flushes a given Config into w.

type ConfigLoader

type ConfigLoader func() (*Config, error)

ConfigLoader defines a function that loads a config from any source.

type Node

type Node struct {
	Type Type

	Host         core.Host
	PubSub       *pubsub.PubSub
	Datastore    datastore.Batching
	ConnGater    connmgr.ConnectionGater
	Routing      routing.PeerRouting
	DataExchange exchange.Interface
	DAG          format.DAGService

	Wordle *wordle.Service
	// contains filtered or unexported fields
}

func New

func New(tp Type, store Store) (*Node, error)

New assembles a new Node with the given type 'tp' over Store 'store'.

func (*Node) Run

func (n *Node) Run(ctx context.Context) error

Run is a Start which blocks on the given context 'ctx' until it is canceled. If canceled, the Node is still in the running state and should be gracefully stopped via Stop.

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start launches the Node and all its components and services.

func (*Node) Stop

func (n *Node) Stop(ctx context.Context) error

Stop shuts down the Node, all its running Components/Services and returns. Canceling the given context earlier 'ctx' unblocks the Stop and aborts graceful shutdown forcing remaining Components/Services to close immediately.

type Store

type Store interface {
	// Path reports the FileSystem path of Store.
	Path() string

	// Keystore provides a Keystore to access keys.
	Keystore() (keystore.Keystore, error)

	// Datastore provides a Datastore - a KV store for arbitrary data to be stored on disk.
	Datastore() (datastore.Batching, error)

	// Config loads the stored Node config.
	Config() (*Config, error)

	// PutConfig alters the stored Node config.
	PutConfig(*Config) error

	// Close closes the Store freeing up acquired resources and locks.
	Close() error
}

Store encapsulates storage for the Node. Basically, it is the Store of all Stores. It provides access for the Node data stored in root directory e.g. '~/.wordle'.

func OpenStore

func OpenStore(path string) (Store, error)

OpenStore creates new FS Store under the given 'path'. To be opened the Store must be initialized first, otherwise ErrNotInited is thrown. OpenStore takes a file Lock on directory, hence only one Store can be opened at a time under the given 'path', otherwise ErrOpened is thrown.

type Type

type Type uint8

Type defines the Node type for identity purposes. The zero value for Type is invalid.

const (
	// Light is a stripped-down Wordle Node which aims to be lightweight while preserving the highest possible
	// security guarantees.
	Light Type = iota + 1
	// Full is a Wordle Node that stores blocks in their entirety.
	Full
)

func ParseType

func ParseType(str string) Type

ParseType converts string in a type if possible.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid reports whether the Type is valid.

func (Type) String

func (t Type) String() string

String converts Type to its string representation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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