 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
- Variables
- func DefaultDataDir() string
- func DefaultHTTPEndpoint() string
- func DefaultIPCEndpoint(clientIdentifier string) string
- func DefaultWSEndpoint() string
- type Config
- func (c *Config) AccountConfig() (int, int, string, error)
- func (c *Config) HTTPEndpoint() string
- func (c *Config) IPCEndpoint() string
- func (c *Config) NodeDB() string
- func (c *Config) NodeKey() *ecdsa.PrivateKey
- func (c *Config) NodeName() string
- func (c *Config) ResolvePath(path string) string
- func (c *Config) StaticNodes() []*discover.Node
- func (c *Config) TrustedNodes() []*discover.Node
- func (c *Config) WSEndpoint() string
 
- type DuplicateServiceError
- type Node
- func (n *Node) AccountManager() *accounts.Manager
- func (n *Node) Attach() (*rpc.Client, error)
- func (n *Node) Close() error
- func (n *Node) DataDir() string
- func (n *Node) EventMux() *event.TypeMux
- func (n *Node) GatherProtocols() []p2p.Protocol
- func (n *Node) GatherServices() error
- func (n *Node) GetHTTPHandler() (*rpc.Server, error)
- func (n *Node) GetLogger() log.Logger
- func (n *Node) GetWSHandler() (*rpc.Server, error)
- func (n *Node) HTTPEndpoint() string
- func (n *Node) IPCEndpoint() string
- func (n *Node) InstanceDir() string
- func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) (neatdb.Database, error)
- func (n *Node) RPCHandler() (*rpc.Server, error)
- func (n *Node) Register(constructor ServiceConstructor) error
- func (n *Node) ResolvePath(x string) string
- func (n *Node) Restart() error
- func (n *Node) RpcAPIs() []rpc.API
- func (n *Node) Server() *p2p.Server
- func (n *Node) Service(service interface{}) error
- func (n *Node) SetP2PServer(p2pServer *p2p.Server)
- func (n *Node) Start() error
- func (n *Node) Start1() error
- func (n *Node) Stop() error
- func (n *Node) StopChan() <-chan struct{}
- func (n *Node) WSEndpoint() string
- func (n *Node) Wait()
 
- type PrivateAdminAPI
- func (api *PrivateAdminAPI) AddPeer(url string) (bool, error)
- func (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error)
- func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error)
- func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error)
- func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error)
- func (api *PrivateAdminAPI) StopRPC() (bool, error)
- func (api *PrivateAdminAPI) StopWS() (bool, error)
 
- type PublicAdminAPI
- type PublicDebugAPI
- type PublicWeb3API
- type Service
- type ServiceConstructor
- type ServiceContext
- func (ctx *ServiceContext) ChainId() string
- func (ctx *ServiceContext) NodeKey() *ecdsa.PrivateKey
- func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int, namespace string) (neatdb.Database, error)
- func (ctx *ServiceContext) ResolvePath(path string) string
- func (ctx *ServiceContext) Service(service interface{}) error
 
- type StopError
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 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) HTTPEndpoint ¶
func (*Config) IPCEndpoint ¶
func (*Config) NodeKey ¶
func (c *Config) NodeKey() *ecdsa.PrivateKey
func (*Config) ResolvePath ¶
func (*Config) StaticNodes ¶
func (*Config) TrustedNodes ¶
func (*Config) WSEndpoint ¶
type DuplicateServiceError ¶
func (*DuplicateServiceError) Error ¶
func (e *DuplicateServiceError) Error() string
type Node ¶
type Node struct {
	// contains filtered or unexported fields
}
    func (*Node) AccountManager ¶
func (*Node) GatherProtocols ¶
func (*Node) GatherServices ¶
func (*Node) HTTPEndpoint ¶
func (*Node) IPCEndpoint ¶
func (*Node) InstanceDir ¶
func (*Node) OpenDatabase ¶
func (*Node) Register ¶
func (n *Node) Register(constructor ServiceConstructor) error
func (*Node) ResolvePath ¶
func (*Node) SetP2PServer ¶
func (*Node) WSEndpoint ¶
type PrivateAdminAPI ¶
type PrivateAdminAPI struct {
	// contains filtered or unexported fields
}
    func NewPrivateAdminAPI ¶
func NewPrivateAdminAPI(node *Node) *PrivateAdminAPI
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) 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
type PublicDebugAPI ¶
type PublicDebugAPI struct {
	// contains filtered or unexported fields
}
    func NewPublicDebugAPI ¶
func NewPublicDebugAPI(node *Node) *PublicDebugAPI
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
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/neatlab/neatio/network/node"
	"github.com/neatlab/neatio/network/p2p"
	"github.com/neatlab/neatio/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)
	}
}
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 (*ServiceContext) ResolvePath ¶
func (ctx *ServiceContext) ResolvePath(path string) string
func (*ServiceContext) Service ¶
func (ctx *ServiceContext) Service(service interface{}) error
 Click to show internal directories. 
   Click to hide internal directories.