adapters

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterLifecycles

func RegisterLifecycles(lifecycles LifecycleConstructors)

RegisterLifecycles registers the given Services which can then be used to start devp2p nodes using either the Exec or Docker adapters.

It should be called in an init function so that it has the opportunity to execute the services before main() is called.

Types

type LifecycleConstructor

type LifecycleConstructor func(ctx *ServiceContext, stack *node.Node) (node.Lifecycle, error)

LifecycleConstructor allows a Lifecycle to be constructed during node start-up. While the service-specific package usually takes care of Lifecycle creation and registration, for testing purposes, it is useful to be able to construct a Lifecycle on spot.

type LifecycleConstructors

type LifecycleConstructors map[string]LifecycleConstructor

LifecycleConstructors stores LifecycleConstructor functions to call during node start-up.

type Node

type Node interface {
	// Addr returns the node's address (e.g. an Enode URL)
	Addr() []byte

	// Client returns the RPC client which is created once the node is
	// up and running
	Client() (*rpc.Client, error)

	// ServeRPC serves RPC requests over the given connection
	ServeRPC(*websocket.Conn) error

	// Start starts the node with the given snapshots
	Start(snapshots map[string][]byte) error

	// Stop stops the node
	Stop() error

	// NodeInfo returns information about the node
	NodeInfo() *p2p.NodeInfo

	// Snapshots creates snapshots of the running services
	Snapshots() (map[string][]byte, error)
}

Node represents a node in a simulation network which is created by a NodeAdapter, for example:

* SimNode - An in-memory node * ExecNode - A child process node * DockerNode - A Docker container node

type NodeAdapter

type NodeAdapter interface {
	// Name returns the name of the adapter for logging purposes
	Name() string

	// NewNode creates a new node with the given configuration
	NewNode(config *NodeConfig) (Node, error)
}

NodeAdapter is used to create Nodes in a simulation network

type NodeConfig

type NodeConfig struct {
	// ID is the node's ID which is used to identify the node in the
	// simulation network
	ID enode.ID

	// PrivateKey is the node's private key which is used by the devp2p
	// stack to encrypt communications
	PrivateKey *ecdsa.PrivateKey

	// Enable peer events for Msgs
	EnableMsgEvents bool

	// Name is a human friendly name for the node like "node01"
	Name string

	// Use an existing database instead of a temporary one if non-empty
	DataDir string

	// Lifecycles are the names of the service lifecycles which should be run when
	// starting the node (for SimNodes it should be the names of service lifecycles
	// contained in SimAdapter.lifecycles, for other nodes it should be
	// service lifecycles registered by calling the RegisterLifecycle function)
	Lifecycles []string

	// Properties are the names of the properties this node should hold
	// within running services (e.g. "bootnode", "lightnode" or any custom values)
	// These values need to be checked and acted upon by node Services
	Properties []string

	// ENR Record with entries to overwrite
	Record enr.Record

	// function to sanction or prevent suggesting a peer
	Reachable func(id enode.ID) bool

	Port uint16

	// LogFile is the log file name of the p2p node at runtime.
	//
	// The default value is empty so that the default log writer
	// is the system standard output.
	LogFile string

	// LogVerbosity is the log verbosity of the p2p node at runtime.
	//
	// The default verbosity is INFO.
	LogVerbosity log.Lvl
	// contains filtered or unexported fields
}

NodeConfig is the configuration used to start a node in a simulation network

func RandomNodeConfig

func RandomNodeConfig() *NodeConfig

RandomNodeConfig returns node configuration with a randomly generated ID and PrivateKey

func (*NodeConfig) MarshalJSON

func (n *NodeConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface by encoding the config fields as strings

func (*NodeConfig) Node

func (n *NodeConfig) Node() *enode.Node

Node returns the node descriptor represented by the config.

func (*NodeConfig) UnmarshalJSON

func (n *NodeConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface by decoding the json string values into the config fields

type RPCDialer

type RPCDialer interface {
	DialRPC(id enode.ID) (*rpc.Client, error)
}

RPCDialer is used when initialising services which need to connect to other nodes in the network (for example a simulated Swarm node which needs to connect to a Geth node to resolve ENS names)

type ServiceContext

type ServiceContext struct {
	RPCDialer

	Config   *NodeConfig
	Snapshot []byte
}

ServiceContext is a collection of options and methods which can be utilised when starting services

Jump to

Keyboard shortcuts

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