Documentation
¶
Index ¶
Constants ¶
const Subsystem = "MSGX"
Subsystem defines the logging code for this subsystem.
Variables ¶
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.
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) 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()
}
MsgRouter 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.