msgmux

package
v0.21.8-beta Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Subsystem = "MSGX"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (
	// ErrDuplicateEndpoint is returned when an endpoint is registered with
	// a name that already exists.
	ErrDuplicateEndpoint = fmt.Errorf("endpoint already registered")

	// ErrUnableToRouteMsg is returned when a message is unable to be
	// routed to any endpoints.
	ErrUnableToRouteMsg = fmt.Errorf("unable to route message")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type Endpoint

type Endpoint interface {
	// Name returns the name of this endpoint. This MUST be unique across
	// all registered endpoints.
	Name() EndpointName

	// CanHandle returns true if the target message can be routed to this
	// endpoint.
	CanHandle(msg PeerMsg) bool

	// SendMessage handles the target message, and returns true if the
	// message was able being processed.
	SendMessage(ctx context.Context, msg PeerMsg) bool
}

Endpoint is an interface that represents a message endpoint, or the sub-system that will handle processing an incoming wire message.

type EndpointName

type EndpointName = string

EndpointName is the name of a given endpoint. This MUST be unique across all registered endpoints.

type EndpointsMap

type EndpointsMap map[EndpointName]Endpoint

EndpointsMap is a map of all registered endpoints.

type MultiMsgRouter

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

MultiMsgRouter is a type of message router that is capable of routing new incoming messages, permitting a message to be routed to multiple registered endpoints.

func NewMultiMsgRouter

func NewMultiMsgRouter() *MultiMsgRouter

NewMultiMsgRouter creates a new instance of a peer message router.

func (*MultiMsgRouter) RegisterEndpoint

func (p *MultiMsgRouter) RegisterEndpoint(endpoint Endpoint) error

RegisterEndpoint registers a new endpoint with the router. If a duplicate endpoint exists, an error is returned.

func (*MultiMsgRouter) RouteMsg

func (p *MultiMsgRouter) RouteMsg(msg PeerMsg) error

RouteMsg attempts to route the target message to a registered endpoint. If ANY endpoint could handle the message, then nil is returned.

func (*MultiMsgRouter) Start

func (p *MultiMsgRouter) Start(ctx context.Context)

Start starts the peer message router.

func (*MultiMsgRouter) Stop

func (p *MultiMsgRouter) Stop()

Stop stops the peer message router.

func (*MultiMsgRouter) UnregisterEndpoint

func (p *MultiMsgRouter) UnregisterEndpoint(name EndpointName) error

UnregisterEndpoint unregisters the target endpoint from the router.

type PeerMsg

type PeerMsg struct {
	lnwire.Message

	// PeerPub is the public key of the peer that sent this message.
	PeerPub btcec.PublicKey
}

PeerMsg is a wire message that includes the public key of the peer that sent it.

type Router

type Router interface {
	// RegisterEndpoint registers a new endpoint with the router. If a
	// duplicate endpoint exists, an error is returned.
	RegisterEndpoint(Endpoint) error

	// UnregisterEndpoint unregisters the target endpoint from the router.
	UnregisterEndpoint(EndpointName) error

	// RouteMsg attempts to route the target message to a registered
	// endpoint. If ANY endpoint could handle the message, then nil is
	// returned. Otherwise, ErrUnableToRouteMsg is returned.
	RouteMsg(PeerMsg) error

	// Start starts the peer message router.
	Start(ctx context.Context)

	// Stop stops the peer message router.
	Stop()
}

Router is an interface that represents a message router, which is generic sub-system capable of routing any incoming wire message to a set of registered endpoints.

Jump to

Keyboard shortcuts

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