node

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package node provides tooling for creating a Sia node. Sia nodes consist of a collection of modules. The node package gives you tools to easily assemble various combinations of modules with varying dependencies and settings, including templates for assembling sane no-hassle Sia nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllModulesTemplate is a template for a Sia node that has all modules
	// enabled.
	AllModulesTemplate = NodeParams{
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            true,
		CreateMiner:           true,
		CreateRenter:          true,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// HostTemplate is a template for a Sia node that has a functioning host.
	// The node has a host and all dependencies, but no other modules.
	HostTemplate = NodeParams{
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            true,
		CreateMiner:           false,
		CreateRenter:          false,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// RenterTemplate is a template for a Sia node that has a functioning
	// renter. The node has a renter and all dependencies, but no other
	// modules.
	RenterTemplate = NodeParams{
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           false,
		CreateRenter:          true,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// WalletTemplate is a template for a Sia node that has a functioning
	// wallet. The node has a wallet and all dependencies, but no other
	// modules.
	WalletTemplate = NodeParams{
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           false,
		CreateRenter:          false,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
)

Functions

This section is empty.

Types

type Node

type Node struct {
	// The modules of the node. Modules that are not initialized will be nil.
	ConsensusSet    modules.ConsensusSet
	Explorer        modules.Explorer
	Gateway         modules.Gateway
	Host            modules.Host
	Miner           modules.TestMiner
	Renter          modules.Renter
	TransactionPool modules.TransactionPool
	Wallet          modules.Wallet

	// The high level directory where all the persistence gets stored for the
	// moudles.
	Dir string
}

Node is a collection of Sia modules operating together as a Sia node.

func New

func New(params NodeParams) (*Node, error)

New will create a new test node. The inputs to the function are the respective 'New' calls for each module. We need to use this awkward method of initialization because the siatest package cannot import any of the modules directly (so that the modules may use the siatest package to test themselves).

func (*Node) Close

func (n *Node) Close() (err error)

Close will call close on every module within the node, combining and returning the errors.

type NodeParams

type NodeParams struct {
	// Flags to indicate which modules should be created automatically by the
	// server. If you are providing a pre-existing module, do not set the flag
	// for that module.
	//
	// NOTE / TODO: The code does not currently enforce this, but you should not
	// provide a custom module unless all of its dependencies are also custom.
	// Example: if the ConsensusSet is custom, the Gateway should also be
	// custom. The TransactionPool however does not need to be custom in this
	// example.
	CreateConsensusSet    bool
	CreateExplorer        bool
	CreateGateway         bool
	CreateHost            bool
	CreateMiner           bool
	CreateRenter          bool
	CreateTransactionPool bool
	CreateWallet          bool

	// Custom modules - if the modules is provided directly, the provided
	// module will be used instead of creating a new one. If a custom module is
	// provided, the 'omit' flag for that module must be set to false (which is
	// the default setting).
	ConsensusSet    modules.ConsensusSet
	Explorer        modules.Explorer
	Gateway         modules.Gateway
	Host            modules.Host
	Miner           modules.TestMiner
	Renter          modules.Renter
	TransactionPool modules.TransactionPool
	Wallet          modules.Wallet

	// The high level directory where all the persistence gets stored for the
	// moudles.
	Dir string
}

NodeParams contains a bunch of parameters for creating a new test node. As there are many options, templates are provided that you can modify which cover the most common use cases.

Each module is created separately. There are several ways to create a module, though not all methods are currently available for each module. You should only use one method for creating a module, using multiple methods will cause an error.

  • Indicate with the 'CreateModule' bool that a module should be created automatically. To create the module with custom dependencies, pass the custom dependencies in using the 'ModuleDependencies' field.
  • Pass an existing module in directly.
  • Set 'CreateModule' to false and do not pass in an existing module. This will result in a 'nil' module, meaning the node will not have that module.

func AllModules

func AllModules(dir string) NodeParams

AllModules returns an AllModulesTemplate filled out with the provided dir.

func Host

func Host(dir string) NodeParams

Host returns a HostTemplate filled out with the provided dir.

func Renter

func Renter(dir string) NodeParams

Renter returns a RenterTemplate filled out with the provided dir.

func Wallet

func Wallet(dir string) NodeParams

Wallet returns a WalletTemplate filled out with the provided dir.

Directories

Path Synopsis
api
server
Package server provides a server that can wrap a node and serve an http api for interacting with the node.
Package server provides a server that can wrap a node and serve an http api for interacting with the node.

Jump to

Keyboard shortcuts

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