node

package
v0.0.0-...-5d85a61 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	DefaultHTTPHost = "localhost"
	DefaultHTTPPort = 9915
	DefaultWSHost   = "localhost"
	DefaultWSPort   = 9916
)

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{
	GeneralDataDir:   DefaultDataDir(),
	DataDir:          DefaultDataDir(),
	HTTPPort:         DefaultHTTPPort,
	HTTPModules:      []string{"net", "web3"},
	HTTPVirtualHosts: []string{"localhost"},
	HTTPTimeouts:     rpc.DefaultHTTPTimeouts,
	WSPort:           DefaultWSPort,
	WSModules:        []string{"net", "web3"},
	P2P: p2p.Config{
		ListenAddr: ":9910",
		MaxPeers:   200,
		NAT:        nat.Any(),
	},
}

Functions

func DefaultDataDir

func DefaultDataDir() string

func DefaultHTTPEndpoint

func DefaultHTTPEndpoint() string

func DefaultIPCEndpoint

func DefaultIPCEndpoint(clientIdentifier string) string

func DefaultWSEndpoint

func DefaultWSEndpoint() string

Types

type Config

type Config struct {
	Name string `toml:"-"`

	ChainId string `toml:",omitempty"`

	UserIdent string `toml:",omitempty"`

	Version string `toml:"-"`

	GeneralDataDir string

	DataDir string

	P2P p2p.Config

	KeyStoreDir string `toml:",omitempty"`

	UseLightweightKDF bool `toml:",omitempty"`

	NoUSB bool `toml:",omitempty"`

	IPCPath string `toml:",omitempty"`

	HTTPHost string `toml:",omitempty"`

	HTTPPort int `toml:",omitempty"`

	HTTPCors []string `toml:",omitempty"`

	HTTPVirtualHosts []string `toml:",omitempty"`

	HTTPModules []string `toml:",omitempty"`

	HTTPTimeouts rpc.HTTPTimeouts

	WSHost string `toml:",omitempty"`

	WSPort int `toml:",omitempty"`

	WSOrigins []string `toml:",omitempty"`

	WSModules []string `toml:",omitempty"`

	WSExposeAll bool `toml:",omitempty"`

	Logger log.Logger `toml:",omitempty"`
}

func (*Config) AccountConfig

func (c *Config) AccountConfig() (int, int, string, error)

func (*Config) HTTPEndpoint

func (c *Config) HTTPEndpoint() string

func (*Config) IPCEndpoint

func (c *Config) IPCEndpoint() string

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() []*discover.Node

func (*Config) TrustedNodes

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

func (*Config) WSEndpoint

func (c *Config) WSEndpoint() string

type DuplicateServiceError

type DuplicateServiceError struct {
	Kind reflect.Type
}

func (*DuplicateServiceError) Error

func (e *DuplicateServiceError) Error() string

type Node

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

func New

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

func (*Node) AccountManager

func (n *Node) AccountManager() *accounts.Manager

func (*Node) Attach

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

func (*Node) Close

func (n *Node) Close() error

func (*Node) DataDir

func (n *Node) DataDir() string

func (*Node) EventMux

func (n *Node) EventMux() *event.TypeMux

func (*Node) GatherProtocols

func (n *Node) GatherProtocols() []p2p.Protocol

func (*Node) GatherServices

func (n *Node) GatherServices() error

func (*Node) GetHTTPHandler

func (n *Node) GetHTTPHandler() (*rpc.Server, error)

func (*Node) GetLogger

func (n *Node) GetLogger() log.Logger

func (*Node) GetWSHandler

func (n *Node) GetWSHandler() (*rpc.Server, error)

func (*Node) HTTPEndpoint

func (n *Node) HTTPEndpoint() string

func (*Node) IPCEndpoint

func (n *Node) IPCEndpoint() string

func (*Node) InstanceDir

func (n *Node) InstanceDir() string

func (*Node) OpenDatabase

func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) (ligodb.Database, error)

func (*Node) RPCHandler

func (n *Node) RPCHandler() (*rpc.Server, error)

func (*Node) Register

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

func (*Node) ResolvePath

func (n *Node) ResolvePath(x string) string

func (*Node) Restart

func (n *Node) Restart() error

func (*Node) RpcAPIs

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

func (*Node) Server

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

func (*Node) Service

func (n *Node) Service(service interface{}) error

func (*Node) SetP2PServer

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

func (*Node) Start

func (n *Node) Start() error

func (*Node) Start1

func (n *Node) Start1() error

func (*Node) Stop

func (n *Node) Stop() error

func (*Node) StopChan

func (n *Node) StopChan() <-chan struct{}

func (*Node) WSEndpoint

func (n *Node) WSEndpoint() string

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)

func (*PrivateAdminAPI) PeerEvents

func (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error)

func (*PrivateAdminAPI) RemovePeer

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

func (*PrivateAdminAPI) StartRPC

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

func (*PrivateAdminAPI) StartWS

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

func (*PrivateAdminAPI) StopRPC

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

func (*PrivateAdminAPI) StopWS

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

type PublicAdminAPI

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

func NewPublicAdminAPI

func NewPublicAdminAPI(node *Node) *PublicAdminAPI

func (*PublicAdminAPI) Datadir

func (api *PublicAdminAPI) Datadir() string

func (*PublicAdminAPI) NodeInfo

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

func (*PublicAdminAPI) Peers

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

type PublicDebugAPI

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

func NewPublicDebugAPI

func NewPublicDebugAPI(node *Node) *PublicDebugAPI

func (*PublicDebugAPI) Metrics

func (api *PublicDebugAPI) Metrics(raw bool) (map[string]interface{}, error)

type PublicWeb3API

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

func NewPublicWeb3API

func NewPublicWeb3API(stack *Node) *PublicWeb3API

func (*PublicWeb3API) ClientVersion

func (s *PublicWeb3API) ClientVersion() string

func (*PublicWeb3API) Sha3

func (s *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes

type Service

type Service interface {
	Protocols() []p2p.Protocol

	APIs() []rpc.API

	Start(server *p2p.Server) error

	Stop() error
}
Example
package main

import (
	"fmt"
	"log"

	"github.com/ligo-ai/ligo-chain/network/node"
	"github.com/ligo-ai/ligo-chain/network/p2p"
	"github.com/ligo-ai/ligo-chain/network/rpc"
)

type SampleService struct{}

func (s *SampleService) Protocols() []p2p.Protocol { return nil }
func (s *SampleService) APIs() []rpc.API           { return nil }
func (s *SampleService) Start(*p2p.Server) error   { fmt.Println("Service starting..."); return nil }
func (s *SampleService) Stop() error               { fmt.Println("Service stopping..."); return nil }

func main() {

	stack, err := node.New(&node.Config{})
	if err != nil {
		log.Fatalf("Failed to create network node: %v", err)
	}

	constructor := func(context *node.ServiceContext) (node.Service, error) {
		return new(SampleService), nil
	}
	if err := stack.Register(constructor); err != nil {
		log.Fatalf("Failed to register service: %v", err)
	}

	if err := stack.Start(); err != nil {
		log.Fatalf("Failed to start the protocol stack: %v", err)
	}
	if err := stack.Restart(); err != nil {
		log.Fatalf("Failed to restart the protocol stack: %v", err)
	}
	if err := stack.Stop(); err != nil {
		log.Fatalf("Failed to stop the protocol stack: %v", err)
	}

}
Output:

type ServiceConstructor

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

type ServiceContext

type ServiceContext struct {
	EventMux       *event.TypeMux
	AccountManager *accounts.Manager
	// contains filtered or unexported fields
}

func (*ServiceContext) ChainId

func (ctx *ServiceContext) ChainId() string

func (*ServiceContext) NodeKey

func (ctx *ServiceContext) NodeKey() *ecdsa.PrivateKey

func (*ServiceContext) OpenDatabase

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

func (*ServiceContext) ResolvePath

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

func (*ServiceContext) Service

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

type StopError

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

func (*StopError) Error

func (e *StopError) Error() string

Jump to

Keyboard shortcuts

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