node

package
v0.0.0-...-bea6611 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

kbn runs a bootstrap node for the Klaytn Node Discovery Protocol.

A bootstrap node is a kind of registry service which has every nodes' information and delivers it to a querying node to help the node to join the network.

Source Files

Each file contains the following contents

  • api.go : Provides various APIs to use bootnode services
  • backend.go : Provides supporting functions for APIs
  • config.go : Provides `bootnodeConfig` which contains a configuration and accompanying setter and parser functions
  • main.go : Main entry point of the application
  • node.go : Provides `Node` struct which defines what kind of APIs can be provided through which port and protocols

Index

Constants

View Source
const (
	GenerateNodeKeySpecified = iota
	NoPrivateKeyPathSpecified
	NodeKeyDuplicated
	WriteOutAddress
	GoodToGo
)

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")
)

Functions

func DefaultIPCEndpoint

func DefaultIPCEndpoint(clientIdentifier string) string

func SetAuthorizedNodes

func SetAuthorizedNodes(ctx *cli.Context, cfg *GuardianConfig)

func SetIPC

func SetIPC(ctx *cli.Context, cfg *GuardianConfig)

setIPC creates an IPC path configuration from the set command line flags, returning an empty string if IPC was explicitly disabled, or the set path.

func SetP2PConfig

func SetP2PConfig(ctx *cli.Context, cfg *GuardianConfig)

func SplitAndTrim

func SplitAndTrim(input string) []string

splitAndTrim splits input separated by a comma and trims excessive white space from the substrings.

Types

type GuardianConfig

type GuardianConfig struct {

	// Authorized Nodes are used as pre-configured nodes list which are only
	// bonded with this bootnode.
	AuthorizedNodes []*discover.Node

	// DataDir is the file system folder the node should use for any data storage
	// requirements. The configured data directory will not be directly shared with
	// registered services, instead those can use utility methods to create/access
	// databases or flat files. This enables ephemeral nodes which can fully reside
	// in memory.
	DataDir string

	// IPCPath is the requested location to place the IPC endpoint. If the path is
	// a simple file name, it is placed inside the data directory (or on the root
	// pipe path on Windows), whereas if it's a resolvable path name (absolute or
	// relative), then that specific path is enforced. An empty path disables IPC.
	IPCPath string `toml:",omitempty"`

	// Logger is a custom logger to use with the p2p.Server.
	Logger log.Logger `toml:",omitempty"`
	// contains filtered or unexported fields
}

func NewGuardianConfig

func NewGuardianConfig(ctx *cli.Context) *GuardianConfig

func (*GuardianConfig) CheckCMDState

func (cfg *GuardianConfig) CheckCMDState() int

func (*GuardianConfig) DoWriteOutAddress

func (cfg *GuardianConfig) DoWriteOutAddress()

func (*GuardianConfig) GenerateNodeKey

func (cfg *GuardianConfig) GenerateNodeKey()

func (*GuardianConfig) IPCEndpoint

func (c *GuardianConfig) 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 (*GuardianConfig) ReadNodeKey

func (cfg *GuardianConfig) ReadNodeKey() error

func (*GuardianConfig) ValidateNetworkParameter

func (cfg *GuardianConfig) ValidateNetworkParameter() error

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 *GuardianConfig) (*Node, error)

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

func (*Node) APIs

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

func (*Node) Attach

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

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

func (*Node) DataDir

func (n *Node) DataDir() string

DataDir retrieves the current datadir used by the protocol stack. Deprecated: No files should be stored in this directory, use InstanceDir instead.

func (*Node) IPCEndpoint

func (n *Node) IPCEndpoint() string

IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.

func (*Node) RPCHandler

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

RPCHandler returns the in-process RPC request handler.

func (*Node) Restart

func (n *Node) Restart() error

Restart terminates a running node and boots up a new one in its place. If the node isn't running, an error is returned.

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) 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. If the node is not running at the time of invocation, the method immediately returns.

type PrivateGuardianAdminAPI

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

PrivateAdminAPI is the collection of administrative API methods exposed only over a secure RPC channel.

func NewPrivateGuardianAdminAPI

func NewPrivateGuardianAdminAPI(node *Node) *PrivateGuardianAdminAPI

NewPrivateAdminAPI creates a new API definition for the private admin methods of the node itself.

func (*PrivateGuardianAdminAPI) AddPeer

func (api *PrivateGuardianAdminAPI) 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 (*PrivateGuardianAdminAPI) PeerEvents

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

PeerEvents creates an RPC subscription which receives peer events from the node's p2p.Server

func (*PrivateGuardianAdminAPI) RemovePeer

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

RemovePeer disconnects from a a remote node if the connection exists

type PublicGuardianAdminAPI

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

PublicAdminAPI is the collection of administrative API methods exposed over both secure and unsecure RPC channels.

func NewPublicGuardianAdminAPI

func NewPublicGuardianAdminAPI(node *Node) *PublicGuardianAdminAPI

NewPublicAdminAPI creates a new API definition for the public admin methods of the node itself.

func (*PublicGuardianAdminAPI) Datadir

func (api *PublicGuardianAdminAPI) Datadir() string

Datadir retrieves the current data directory the node is using.

func (*PublicGuardianAdminAPI) NodeInfo

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

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

func (*PublicGuardianAdminAPI) Peers

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

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

Jump to

Keyboard shortcuts

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