node

package
v0.0.0-...-c98baff Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package node provides tooling for creating a I3v node. I3v 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 I3v nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllModulesTemplate is a template for a I3v node that has all modules
	// enabled.
	AllModulesTemplate = NodeParams{
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            true,
		CreateMiner:           true,
		CreateRenter:          true,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// GatewayTemplate is a template for a I3v node that has a functioning
	// Gateway. The node has a Gateway but no other modules.
	GatewayTemplate = NodeParams{
		CreateConsensusSet:    false,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           false,
		CreateRenter:          false,
		CreateTransactionPool: false,
		CreateWallet:          false,
	}
	// HostTemplate is a template for a I3v 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,
	}
	// MinerTemplate is a template for a I3v node that has a functioning miner.
	// The node has a miner and all dependencies, but no other modules.
	MinerTemplate = NodeParams{
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           true,
		CreateRenter:          false,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// RenterTemplate is a template for a I3v 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 I3v 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 mux of the node.
	Mux *i3vmux.I3vMux

	// 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
	// modules.
	Dir string
}

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

func New

func New(params NodeParams, loadStartTime time.Time) (*Node, <-chan error)

New will create a new 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 i3vtest package cannot import any of the modules directly (so that the modules may use the i3vtest 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

	// Dependencies for each module supporting dependency injection.
	ConsensusSetDeps modules.Dependencies
	ContractorDeps   modules.Dependencies
	ContractSetDeps  modules.Dependencies
	GatewayDeps      modules.Dependencies
	HostDeps         modules.Dependencies
	HostDBDeps       modules.Dependencies
	RenterDeps       modules.Dependencies
	TPoolDeps        modules.Dependencies
	WalletDeps       modules.Dependencies

	// Dependencies for storage monitor supporting dependency injection.
	StorageManagerDeps modules.Dependencies

	// Custom settings for i3vmux
	I3vMuxAddress string

	// Custom settings for modules
	Allowance   modules.Allowance
	Bootstrap   bool
	HostAddress string
	HostStorage uint64
	RPCAddress  string

	// Initialize node from existing seed.
	PrimarySeed string

	// The following fields are used to skip parts of the node set up
	SkipSetAllowance     bool
	SkipHostDiscovery    bool
	SkipHostAnnouncement bool
	SkipWalletInit       bool

	// The high level directory where all the persistence gets stored for the
	// modules.
	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 Gateway

func Gateway(dir string) NodeParams

Gateway returns a GatewayTemplate filled out with the provided dir.

func Host

func Host(dir string) NodeParams

Host returns a HostTemplate filled out with the provided dir.

func Miner

func Miner(dir string) NodeParams

Miner returns a MinerTemplate 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.

func (NodeParams) NumModules

func (np NodeParams) NumModules() (n int)

NumModules returns how many of the major modules the given NodeParams would create.

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