node

package
v0.0.0-...-91a82d4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: LGPL-3.0 Imports: 32 Imported by: 2

README

protocols

uranus protocol

  1. implementation of sync transaction
  2. implementation of sync block
  3. implementation of broadcast transaction
  4. implementation of broadcast block

Documentation

Index

Constants

View Source
const (
	StatusMsg                   = iota + 1000 //1000
	NewBlockHashesMsg                         //1001
	TxMsg                                     //1002
	GetBlockHashesMsg                         //1003
	BlockHashesMsg                            //1004
	GetBlocksMsg                              //1005
	BlocksMsg                                 //1006
	NewBlockMsg                               //1007
	GetBlockHashesFromNumberMsg               //1008
	ConfirmedMsg                              //1009
)

Variables

View Source
var (
	ErrServiceUnknown = errors.New("unknown service")
	ErrNodeStopped    = errors.New("node not started")
	ErrNodeRunning    = errors.New("node already running")
)
View Source
var DefaultName = "uranus"

Functions

This section is empty.

Types

type Config

type Config struct {
	Name    string
	DataDir string `mapstructure:"node-datadir"`

	Host string   `mapstructure:"rpc-host"`
	Port int      `mapstructure:"rpc-port"`
	Cors []string `mapstructure:"rpc-cors"`

	WSHost    string   `mapstructure:"ws-host"`
	WSPort    int      `mapstructure:"ws-port"`
	WSOrigins []string `mapstructure:"ws-origins"`

	P2P *p2p.Config
}

Config config of node

func NewConfig

func NewConfig(dataDir string) *Config

NewConfig initialize node config

func (*Config) Endpoint

func (c *Config) Endpoint() string

Endpoint resolves an endpoint based on the configured host interface and port parameters.

func (*Config) WSEndpoint

func (c *Config) WSEndpoint() string

WSEndpoint resolves a websocket endpoint based on the configured host interface and port parameters.

type Constructor

type Constructor func(ctx *Context) (Service, error)

type Context

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

Context of service context

func (*Context) OpenDatabase

func (ctx *Context) OpenDatabase(name string, cache int, handles int) (db.Database, error)

OpenDatabase opens an existing database.

func (*Context) ResolvePath

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

ResolvePath resolves a user path into the data directory .

func (*Context) Service

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

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

type Node

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

Node is a container on which services can be registered.

func New

func New(conf *Config) *Node

New creates a new P2P node, ready for protocol registration.

func (*Node) Register

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

Register injects a new service into the node's stack.

func (*Node) Restart

func (n *Node) Restart() error

Restart terminates a running node .

func (*Node) Service

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

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

func (*Node) Start

func (n *Node) Start() error

Start create a live node and starts running it.

func (*Node) Stop

func (n *Node) Stop() error

Stop terminates a running node along with all it's services. In the node was not started, an error is returned.

func (*Node) Wait

func (n *Node) Wait()

Wait blocks the thread until the node is stopped.

type NodeInfo

type NodeInfo struct {
	Difficulty *big.Int   `json:"difficulty"`
	Genesis    utils.Hash `json:"genesis"`
	Head       utils.Hash `json:"head"`
}

type PeerInfo

type PeerInfo struct {
	Version    int      `json:"version"`
	Difficulty *big.Int `json:"difficulty"`
	Head       string   `json:"head"`
}

type ProtocolManager

type ProtocolManager struct {
	SubProtocols []*p2p.Protocol
	// contains filtered or unexported fields
}

func NewProtocolManager

func NewProtocolManager(mux *feed.TypeMux, config *params.ChainConfig, txpool *txpool.TxPool, blockchain *core.BlockChain, chaindb db.Database, engine consensus.Engine) (*ProtocolManager, error)

func (*ProtocolManager) BroadcastBlock

func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool)

func (*ProtocolManager) BroadcastConfirmed

func (pm *ProtocolManager) BroadcastConfirmed(confirmed *types.Confirmed)

func (*ProtocolManager) BroadcastTxs

func (pm *ProtocolManager) BroadcastTxs(txs types.Transactions)

func (*ProtocolManager) NodeInfo

func (pm *ProtocolManager) NodeInfo() *NodeInfo

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start(maxPeers int)

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

type Service

type Service interface {
	//  P2P protocols the service .
	Protocols() []*p2p.Protocol

	// APIs retrieves the list of RPC descriptors the service provides
	APIs() []rpc.API

	// Start start service before all services have been constructed and the networkinglayer was also initialized.
	Start(p2pServer *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.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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