node

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 31 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnableGenericHub = func(cfg *Config) error {
	cfg.GenericHub = true
	return nil
}

EnableGenericHub enables an additional generic hub between peers. This can be used to exchange messages between peers that are not related to any blockchain event. For instance, messages could be used for authentication, or for other sort of application.

Functions

func DiscoveryService

func DiscoveryService(s ...ServiceDiscovery) func(cfg *Config) error

DiscoveryService Adds the service given as argument to the discovery services

func ExchangeKeys

func ExchangeKeys(s string) func(cfg *Config) error

func FromBase64

func FromBase64(enablemDNS, enableDHT bool, bb string, d *discovery.DHT, m *discovery.MDNS) func(cfg *Config) error

func FromYaml

func FromYaml(enablemDNS, enableDHT bool, path string, d *discovery.DHT, m *discovery.MDNS) func(cfg *Config) error

func GenPrivKey added in v0.19.1

func GenPrivKey(seed int64) (crypto.PrivKey, error)

func GenericChannelHandlers added in v0.13.0

func GenericChannelHandlers(h ...Handler) func(cfg *Config) error

GenericChannelHandlers adds a handler to the list that is called on each received message in the generic channel (not the one allocated for the blockchain)

func Handlers

func Handlers(h ...Handler) func(cfg *Config) error

Handlers adds a handler to the list that is called on each received message

func Insecure

func Insecure(b bool) func(cfg *Config) error

func LibP2PLogLevel

func LibP2PLogLevel(l log.LogLevel) func(cfg *Config) error

func ListenAddresses

func ListenAddresses(ss ...string) func(cfg *Config) error

func Logger

func Logger(l log.StandardLogger) func(cfg *Config) error

func MaxMessageSize

func MaxMessageSize(i int) func(cfg *Config) error

func NetSetLimit added in v0.11.0

func NetSetLimit(mgr network.ResourceManager, scope string, limit rcmgr.Limit) error

func RoomName

func RoomName(s string) func(cfg *Config) error

func SealKeyInterval

func SealKeyInterval(i int) func(cfg *Config) error

func SealKeyLength

func SealKeyLength(i int) func(cfg *Config) error

func WithBlacklist added in v0.8.4

func WithBlacklist(i ...string) func(cfg *Config) error

func WithDiscoveryBootstrapPeers

func WithDiscoveryBootstrapPeers(a discovery.AddrList) func(cfg *Config) error

func WithDiscoveryInterval

func WithDiscoveryInterval(t time.Duration) func(cfg *Config) error

func WithInterfaceAddress

func WithInterfaceAddress(i string) func(cfg *Config) error

func WithLedgerAnnounceTime

func WithLedgerAnnounceTime(t time.Duration) func(cfg *Config) error

func WithLedgerInterval

func WithLedgerInterval(t time.Duration) func(cfg *Config) error

func WithLibp2pAdditionalOptions

func WithLibp2pAdditionalOptions(i ...libp2p.Option) func(cfg *Config) error

func WithLibp2pOptions

func WithLibp2pOptions(i ...libp2p.Option) func(cfg *Config) error

WithLibp2pOptions Overrides defaults options

func WithNetworkService

func WithNetworkService(ns ...NetworkService) func(cfg *Config) error

func WithPrivKey added in v0.19.1

func WithPrivKey(b []byte) func(cfg *Config) error

func WithStaticPeer added in v0.19.1

func WithStaticPeer(ip string, p peer.ID) func(cfg *Config) error

func WithStore

func WithStore(s blockchain.Store) func(cfg *Config) error

func WithStreamHandler

func WithStreamHandler(id protocol.Protocol, h StreamHandler) func(cfg *Config) error

WithStreamHandler adds a handler to the list that is called on each received message

Types

type Config

type Config struct {
	// ExchangeKey is a Symmetric key used to seal the messages
	ExchangeKey string

	// RoomName is the OTP token gossip room where all peers are subscribed to
	RoomName string

	// ListenAddresses is the discovery peer initial bootstrap addresses
	ListenAddresses []discovery.AddrList

	// Insecure disables secure p2p e2e encrypted communication
	Insecure bool

	// Handlers are a list of handlers subscribed to messages received by the vpn interface
	Handlers, GenericChannelHandler []Handler

	MaxMessageSize  int
	SealKeyInterval int

	ServiceDiscovery []ServiceDiscovery
	NetworkServices  []NetworkService
	Logger           log.StandardLogger

	SealKeyLength    int
	InterfaceAddress string

	Store blockchain.Store

	// Handle is a handle consumed by HumanInterfaces to handle received messages
	Handle                     func(bool, *hub.Message)
	StreamHandlers             map[protocol.Protocol]StreamHandler
	AdditionalOptions, Options []libp2p.Option

	DiscoveryInterval, LedgerSyncronizationTime, LedgerAnnounceTime time.Duration
	DiscoveryBootstrapPeers                                         discovery.AddrList

	Whitelist, Blacklist []string

	// GenericHub enables generic hub
	GenericHub bool

	PrivateKey []byte
	PeerTable  map[string]peer.ID

	Sealer    Sealer
	PeerGater Gater
}

Config is the node configuration

func (*Config) Apply

func (cfg *Config) Apply(opts ...Option) error

Apply applies the given options to the config, returning the first error encountered (if any).

type Gater added in v0.12.1

type Gater interface {
	Gate(*Node, peer.ID) bool
	Enable()
	Disable()
	Enabled() bool
}

type Handler

type Handler func(*blockchain.Ledger, *hub.Message, chan *hub.Message) error

type NetworkService

type NetworkService func(context.Context, Config, *Node, *blockchain.Ledger) error

NetworkService is a service running over the network. It takes a context, a node and a ledger

type Node

type Node struct {
	MessageHub *hub.MessageHub

	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(p ...Option) (*Node, error)

func (*Node) BlockSubnet added in v0.8.4

func (e *Node) BlockSubnet(cidr string) error

BlockSubnet blocks the CIDR subnet from connections

func (*Node) ConnectionGater added in v0.8.4

func (e *Node) ConnectionGater() *conngater.BasicConnectionGater

ConnectionGater returns the underlying libp2p conngater

func (*Node) Host

func (e *Node) Host() host.Host

Host returns the libp2p peer host

func (*Node) Ledger

func (e *Node) Ledger() (*blockchain.Ledger, error)

Ledger return the ledger which uses the node connection to broadcast messages

func (*Node) PeerGater added in v0.13.0

func (e *Node) PeerGater() Gater

PeerGater returns the node peergater

func (*Node) PublishMessage added in v0.13.0

func (e *Node) PublishMessage(m *hub.Message) error

PublishMessage publishes a message to the generic channel (if enabled) See GenericChannelHandlers(..) to attach handlers to receive messages from this channel.

func (*Node) Start

func (e *Node) Start(ctx context.Context) error

Start joins the node over the p2p network

type OTP

type OTP struct {
	DHT    OTPConfig `yaml:"dht"`
	Crypto OTPConfig `yaml:"crypto"`
}

type OTPConfig

type OTPConfig struct {
	Interval int    `yaml:"interval"`
	Key      string `yaml:"key"`
	Length   int    `yaml:"length"`
}

type Option

type Option func(cfg *Config) error

func WithPeerGater added in v0.12.1

func WithPeerGater(d Gater) Option

func WithSealer added in v0.8.5

func WithSealer(i Sealer) Option

type Sealer added in v0.8.5

type Sealer interface {
	Seal(string, string) (string, error)
	Unseal(string, string) (string, error)
}

type ServiceDiscovery

type ServiceDiscovery interface {
	Run(log.StandardLogger, context.Context, host.Host) error
	Option(context.Context) func(c *libp2p.Config) error
}

type StreamHandler added in v0.7.2

type StreamHandler func(*Node, *blockchain.Ledger) func(stream network.Stream)

type YAMLConnectionConfig

type YAMLConnectionConfig struct {
	OTP OTP `yaml:"otp"`

	RoomName       string `yaml:"room"`
	Rendezvous     string `yaml:"rendezvous"`
	MDNS           string `yaml:"mdns"`
	MaxMessageSize int    `yaml:"max_message_size"`
}

func GenerateNewConnectionData

func GenerateNewConnectionData(i ...int) *YAMLConnectionConfig

func (YAMLConnectionConfig) Base64

func (y YAMLConnectionConfig) Base64() string

Base64 returns the base64 string representation of the connection

func (YAMLConnectionConfig) YAML

func (y YAMLConnectionConfig) YAML() string

YAML returns the connection config as yaml string

Jump to

Keyboard shortcuts

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