embed

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package embed provides a simplified way to run a webmesh node in-process.

Index

Constants

View Source
const ProtocolCode = 613

ProtocolCode is the code for the webmesh libp2p protocol.

Variables

View Source
var Protocol = multiaddr.Protocol{
	Name:       "webmesh",
	Code:       ProtocolCode,
	VCode:      multiaddr.CodeToVarint(ProtocolCode),
	Size:       -1,
	Path:       false,
	Transcoder: multiaddr.NewTranscoderFromFunctions(protocolStrToBytes, protocolBytesToStr, validateBytes),
}

Protocol is the webmesh libp2p protocol.

Functions

func WithWebmeshTransport added in v0.5.1

func WithWebmeshTransport(config *config.Config) p2pconfig.Option

WithWebmeshTransport returns a libp2p option that configures the transport to use the embedded node.

Types

type NewTransportFunc added in v0.5.1

type NewTransportFunc func(upgrader transport.Upgrader, host host.Host, rcmgr network.ResourceManager, privKey p2pcrypto.PrivKey) (transport.Transport, error)

NewTransportFunc is the signature of a function that returns a new transport.

type Node

type Node interface {
	transport.Dialer
	transport.NodeDialer
	transport.LeaderDialer

	// Start starts the node.
	Start(ctx context.Context) error
	// Stop stops the node.
	Stop(ctx context.Context) error
	// Errors returns a channel of errors that occur during the lifetime of the node.
	// At the moment, any error is fatal and will cause the node to stop.
	Errors() <-chan error
	// Mesh returns the underlying mesh instance.
	Mesh() mesh.Mesh
	// Raft is the underlying Raft instance.
	Raft() raft.Raft
	// Storage is the underlying storage instance.
	Storage() storage.MeshStorage
	// Services returns the underlying services instance if it is running.
	Services() *services.Server
	// MeshDNS returns the underlying MeshDNS instance if it is running.
	MeshDNS() *meshdns.Server
	// AddressV4 returns the IPv4 address of the node.
	AddressV4() netip.Prefix
	// AddressV6 returns the IPv6 address of the node.
	AddressV6() netip.Prefix
}

Node is an embedded webmesh node.

func NewNode

func NewNode(ctx context.Context, config *config.Config) (Node, error)

NewNode creates a new embedded webmesh node.

func NewNodeWithKey added in v0.5.1

func NewNodeWithKey(ctx context.Context, config *config.Config, key crypto.Key) (Node, error)

NewNodeWithKey returns a new node using the given key.

func NewNodeWithKeyAndHost added in v0.5.1

func NewNodeWithKeyAndHost(ctx context.Context, config *config.Config, key crypto.Key, host host.Host) (Node, error)

NewNodeWithKeyAndHost returns a new node using the given key and pre-created libp2p host. This is mostly intended for use with transports.

type Transport added in v0.5.1

type Transport interface {
	io.Closer
	transport.Transport
}

Jump to

Keyboard shortcuts

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