node

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Copyright 2020 YOUCHAIN FOUNDATION LTD. Copyright 2016 The go-ethereum Authors This file is part of the go-ethereum library.

The go-ethereum library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The go-ethereum library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	ConsTypeYPoS = iota
	ConsTypeSolo
)

Variables

View Source
var (
	ErrDatadirUsed    = errors.New("datadir already used by another process")
	ErrNodeStopped    = errors.New("node not started")
	ErrNodeRunning    = errors.New("node already running")
	ErrServiceUnknown = errors.New("unknown service")
)
View Source
var (
	DefaultConfig = Config{
		Name:      "YOUChain",
		DataDir:   "data",
		NetworkId: 1,

		RPC: rpc.NewDefaultConfig(),
		P2P: p2p.NewDefaultConfig(),
		// contains filtered or unexported fields
	}
)

Functions

func DefaultIPCEndpoint

func DefaultIPCEndpoint(clientIdentifier string) string

DefaultIPCEndpoint returns the IPC path used by default.

Types

type Config

type Config struct {
	Name      string `yaml:"name" json:"name"`
	DataDir   string `yaml:"datadir" json:"data_dir"`
	NodeType  string `yaml:"nodetype" json:"node_type"`
	NetworkId uint64 `yaml:"networkid" json:"network_id"`

	//rpc config
	RPC rpc.Config `yaml:"rpc" json:"rpc"`

	//p2p config
	P2P         p2p.Config `yaml:"p2p" json:"p2p"`
	P2PBootNode string     `yaml:"p2pbootnode" json:"p2p_bootnode"`
	P2pPort     int        `yaml:"p2pport" json:"p2p_port"`
	P2pDiscover int        `yaml:"p2pdiscover" json:"p2p_discover"`

	//miner config
	MiningEnabled bool `yaml:"mine" json:"mine"`

	//validator config
	ValAddr  string `yaml:"valaddr" json:"val_addr"`
	Password string `yaml:"-" json:"-"`
	Keep     bool   `yaml:"keep" json:"keep"` //whether to keep the validator key in plaintext

	//developer consensus config
	Genesis       string        `yaml:"genesis" json:"genesis"`
	ConsType      int           `yaml:"constype" json:"cons_type"` //consensus type: 0 - YPOS, 1 - Solo
	UConKey       string        `yaml:"uconkey" json:"ucon_key"`
	BlsSignKey    string        `yaml:"blssignkey" json:"bls_sign_key"`
	SoloBlockTime time.Duration `yaml:"soloblocktime" json:"solo_block_time"`

	//Metrics config
	Metrics MetricsConfig `yaml:"metrics" json:"metrics"`

	//DevOp config
	LogLevel   int    `yaml:"loglevel" json:"log_level"`
	LogVmodule string `yaml:"logvmodule" json:"log_vmodule"`
	LogPath    string `yaml:"logpath" json:"log_path"`

	BootNodeId      int    `yaml:"bootnodeid" json:"boot_nodeid"`
	BootUconFile    string `yaml:"bootuconfile" json:"bootuconfile"`
	BootNodeSvcName string `yaml:"bootnodesvcname" json:"boot_node_svc_name"`
	// contains filtered or unexported fields
}

func NewDefaultConfig

func NewDefaultConfig() Config

func (*Config) BlacklistDB

func (c *Config) BlacklistDB() string

func (*Config) IPCEndpoint

func (c *Config) IPCEndpoint() string

IPCEndpoint resolves an IPC endpoint based on a configured value, taking into account the set data folders as well as the designated platform we're currently running on.

func (*Config) NodeDB

func (c *Config) NodeDB() string

func (*Config) NodeKey

func (c *Config) NodeKey() *ecdsa.PrivateKey

func (*Config) NodeName

func (c *Config) NodeName() string

func (*Config) ResolvePath

func (c *Config) ResolvePath(path string) string

func (*Config) StaticNodes

func (c *Config) StaticNodes() []*enode.Node

func (*Config) TrustedNodes

func (c *Config) TrustedNodes() []*enode.Node

TrustedNodes returns a list of node enode URLs configured as trusted nodes.

func (*Config) Type

func (c *Config) Type() params.NodeType

Type returns the node type

type DuplicateServiceError

type DuplicateServiceError struct {
	Kind reflect.Type
}

DuplicateServiceError is returned during Node startup if a registered service constructor returns a service of the same type that was already started.

func (*DuplicateServiceError) Error

func (e *DuplicateServiceError) Error() string

Error generates a textual representation of the duplicate service error.

type InfluxDBConfig

type InfluxDBConfig struct {
	Hostname string `json:"hostname"`
	Database string `json:"database"`
	Username string `json:"-"`
	Password string `json:"-"`
}

type MetricsConfig

type MetricsConfig struct {
	Metrics bool `json:"metrics"`

	PProf     bool   `json:"pprof"`
	PProfHost string `json:"pprof_host"`
	PProfPort int    `json:"pprof_port"`

	InfluxDB       bool           `json:"influxdb"`
	InfluxDBConfig InfluxDBConfig `json:"influxdb_config"`
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

func New

func New(conf *Config) (*Node, error)

func (*Node) APIs

func (n *Node) APIs() []rpc.API

apis returns the collection of RPC descriptors this node offers.

func (*Node) Attach

func (n *Node) Attach() (*rpc.Client, error)

Attach creates an RPC client attached to an in-process API handler.

func (*Node) GetP2pServer

func (n *Node) GetP2pServer() *p2p.Server

func (*Node) Register

func (n *Node) Register(constructor ServiceConstructor) error

func (*Node) Server

func (n *Node) Server() *p2p.Server

Server retrieves the currently running P2P network layer. This method is meant only to inspect fields of the currently running server, life cycle management should be left to this Node entity.

func (*Node) Start

func (n *Node) Start() error

func (*Node) StartHTTP

func (n *Node) StartHTTP(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error)

func (*Node) StartRPC

func (n *Node) StartRPC(apis []rpc.API) error

startRPC is a helper method to start all the various RPC endpoint during node startup. It's not meant to be called at any time afterwards as it makes certain assumptions about the state of the node.

func (*Node) StartWS

func (n *Node) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error)

func (*Node) Stop

func (n *Node) Stop() error

func (*Node) StopRPC

func (n *Node) StopRPC() (bool, error)

StopRPC terminates an already running HTTP RPC API endpoint.

func (*Node) StopWS

func (n *Node) StopWS() (bool, error)

stopWS terminates the websocket RPC endpoint.

func (*Node) Wait

func (n *Node) Wait()

type PrivateAdminApi

type PrivateAdminApi struct {
	// contains filtered or unexported fields
}

func NewPrivateAdminApi

func NewPrivateAdminApi(node *Node) *PrivateAdminApi

func (*PrivateAdminApi) AddPeer

func (api *PrivateAdminApi) AddPeer(url string) (bool, error)

AddPeer requests connecting to a remote node, and also maintaining the new connection at all times, even reconnecting if it is lost.

func (*PrivateAdminApi) Blacklist

func (api *PrivateAdminApi) Blacklist() RPCBlacklistItem

func (*PrivateAdminApi) ClearBlacklistDB

func (api *PrivateAdminApi) ClearBlacklistDB()

func (*PrivateAdminApi) RemovePeer

func (api *PrivateAdminApi) RemovePeer(url string) (bool, error)

RemovePeer disconnects from a remote node if the connection exists

func (*PrivateAdminApi) RemovePeerFromBlacklist

func (api *PrivateAdminApi) RemovePeerFromBlacklist(ip string, rudpPort int) bool

func (*PrivateAdminApi) StartRPC

func (api *PrivateAdminApi) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error)

StopRPC terminates an already running HTTP RPC API endpoint.

func (*PrivateAdminApi) StartWS

func (api *PrivateAdminApi) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error)

StartWS starts the websocket RPC API server.

func (*PrivateAdminApi) StopRPC

func (api *PrivateAdminApi) StopRPC() (bool, error)

StopRPC terminates an already running HTTP RPC API endpoint.

func (*PrivateAdminApi) StopWS

func (api *PrivateAdminApi) StopWS() (bool, error)

StopRPC terminates an already running HTTP RPC API endpoint.

type PublicAdminApi

type PublicAdminApi struct {
	// contains filtered or unexported fields
}

func NewPublicAdminApi

func NewPublicAdminApi(node *Node) *PublicAdminApi

func (*PublicAdminApi) NodeInfo

func (api *PublicAdminApi) NodeInfo() (*p2p.NodeInfo, error)

NodeInfo retrieves all the information we know about the host node at the protocol granularity.

func (*PublicAdminApi) Peers

func (api *PublicAdminApi) Peers() ([]*p2p.PeerInfo, error)

Peers retrieves all the information we know about each individual peer at the protocol granularity.

type PublicNetApi

type PublicNetApi struct {
	// contains filtered or unexported fields
}

public api for net

func NewPublicNetApi

func NewPublicNetApi(node *Node) *PublicNetApi

func (*PublicNetApi) Listening

func (p *PublicNetApi) Listening() bool

Listening returns an indication if the node is listening for network connections.

func (*PublicNetApi) PeerCount

func (p *PublicNetApi) PeerCount() hexutil.Uint

PeerCount returns the number of connected peers

func (*PublicNetApi) Version

func (p *PublicNetApi) Version() string

type PublicNodeApi

type PublicNodeApi struct {
	// contains filtered or unexported fields
}

public api for youchain

func NewPublicNodeApi

func NewPublicNodeApi(node *Node) *PublicNodeApi

func (*PublicNodeApi) ClientVersion

func (n *PublicNodeApi) ClientVersion() string

ClientVersion returns the node name

func (*PublicNodeApi) Sha3

func (n *PublicNodeApi) Sha3(input hexutil.Bytes) hexutil.Bytes

Sha3 applies the ethereum sha3 implementation on the input. It assumes the input is hex encoded.

type RPCBlacklistItem

type RPCBlacklistItem struct {
	Count     int
	ItemsInfo []p2p.BlacklistItem
}

type Service

type Service interface {
	// Protocols retrieves the P2P protocols the service wishes to start.
	Protocols() []p2p.Protocol

	// Start is called after all services have been constructed and the networking
	// layer was also initialized to spawn any goroutines required by the service.
	Start(server *p2p.Server) error

	// Stop terminates all goroutines belonging to the service, blocking until they
	// are all terminated.
	Stop() error
}

Service is an individual protocol that can be registered into a node.

Notes:

• Service life-cycle management is delegated to the node. The service is allowed to initialize itself upon creation, but no goroutines should be spun up outside of the Start method.

• Restart logic is not required as the node will create a fresh instance every time a service is started.

type ServiceConstructor

type ServiceConstructor func(ctx *ServiceContext) (Service, error)

ServiceConstructor is the function signature of the constructors needed to be registered for service instantiation.

type ServiceContext

type ServiceContext struct {
	EventMux *event.TypeMux // Event multiplexer used for decoupled notifications
	// contains filtered or unexported fields
}

ServiceContext is a collection of service independent options inherited from the protocol stack, that is passed to all constructors to be optionally used; as well as utility methods to operate on the service environment.

func (*ServiceContext) OpenDatabase

func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int) (youdb.Database, error)

OpenDatabase opens an existing database with the given name (or creates one if no previous can be found) from within the node's data directory. If the node is an ephemeral one, a memory database is returned.

func (*ServiceContext) ResolvePath

func (ctx *ServiceContext) ResolvePath(path string) string

ResolvePath resolves a user path into the data directory if that was relative and if the user actually uses persistent storage. It will return an empty string for emphemeral storage and the user's own input for absolute paths.

func (*ServiceContext) Service

func (ctx *ServiceContext) Service(service interface{}) error

Service retrieves a currently running service registered of a specific type.

type StopError

type StopError struct {
	Server   error
	Services map[reflect.Type]error
}

StopError is returned if a Node fails to stop either any of its registered services or itself.

func (*StopError) Error

func (e *StopError) Error() string

Error generates a textual representation of the stop error.

Jump to

Keyboard shortcuts

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