node

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = time.Second * 15

Variables

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

Functions

func Init

func Init(path string, tp Type, options ...Option) error

Init initializes the Node FileSystem Repository 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 InitWith

func InitWith(path string, tp Type, cfg *Config) error

InitWith initializes the Node FileSystem Repository for the given Node Type 'tp' in the directory under 'path' with the given Config 'cfg'.

func IsInit

func IsInit(path string, tp Type) bool

IsInit checks whether FileSystem Repository 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 {
	Core     core.Config
	P2P      p2p.Config
	RPC      rpc.Config
	Services services.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

ReadFrom pulls a Config from a given reader r.

func (*Config) Encode

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

TODO(@Wondertan): We should have a description for each field written into w,

so users can instantly understand purpose of each field. Ideally, we should have a utility program to parse comments
from actual sources(*.go files) and generate docs from comments. Hint: use 'ast' package.

WriteTo 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
	Config *Config

	// CoreClient provides access to a Core node process.
	CoreClient core.Client `optional:"true"`

	// RPCServer provides access to Node's exposed APIs.
	RPCServer *rpc.Server `optional:"true"`

	// p2p components
	Host         host.Host
	ConnGater    connmgr.ConnectionGater
	Routing      routing.PeerRouting
	DataExchange exchange.Interface
	DAG          format.DAGService
	// p2p protocols
	PubSub *pubsub.PubSub
	// BlockService provides access to the node's Block Service
	// TODO @renaynay: I don't like the concept of storing individual services on the node,
	// TODO maybe create a struct in full.go that contains `FullServices` (all expected services to be running on a
	// TODO full node) and in light, same thing `LightServices` (all expected services to be running in a light node.
	// TODO `FullServices` can include `LightServices` + other services.
	BlockServ  *block.Service  `optional:"true"`
	ShareServ  share.Service   // not optional
	HeaderServ *header.Service // not optional

	DASer *das.DASer `optional:"true"`
	// contains filtered or unexported fields
}

Node represents the core structure of a Celestia node. It keeps references to all Celestia-specific components and services in one place and provides flexibility to run a Celestia node in different modes. Currently supported modes: * Full * Light

func New

func New(tp Type, repo Repository, options ...Option) (*Node, error)

New assembles a new Node with the given type 'tp' over Repository 'repo'.

func (*Node) RegisterAPI

func (n *Node) RegisterAPI(endpoint string, api http.Handler) error

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 Option

type Option func(*Config)

Option for Node's Config.

func WithConfig

func WithConfig(custom *Config) Option

WithConfig sets the entire custom config.

func WithRemoteCore

func WithRemoteCore(protocol string, address string) Option

WithRemoteCore configures Node to start with remote Core.

func WithTrustedHash

func WithTrustedHash(hash string) Option

WithTrustedHash sets TrustedHash to the Config.

func WithTrustedPeer

func WithTrustedPeer(addr string) Option

WithTrustedPeer sets TrustedPeer to the Config.

type Repository

type Repository interface {
	// Path reports the FileSystem path of Repository.
	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)

	// Core provides an access to Core's Repository.
	Core() (core.Repository, error)

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

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

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

Repository encapsulates storage for the Node. It provides access for the Node data stored in root directory e.g. '~/.celestia'.

func MockRepository

func MockRepository(t *testing.T, cfg *Config) Repository

MockRepository provides mock in memory Repository for testing purposes.

func NewMemRepository

func NewMemRepository() Repository

NewMemRepository creates an in-memory Repository for Node. Useful for testing.

func Open

func Open(path string, tp Type) (Repository, error)

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

type Type

type Type uint8

Type defines the Node type (e.g. `light`, `full`) for identity purposes. The zero value for Type is invalid.

const (
	// Full is a full-featured Celestia Node.
	Full Type = iota + 1
	// Light is a stripped-down Celestia Node which aims to be lightweight while preserving highest possible
	// security guarantees.
	Light
)

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