pubsub

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildChannelSubscription

type BuildChannelSubscription interface {
	// Directive indicates BuildChannelSubscription is a directive.
	directive.Directive

	// BuildChannelSubscriptionChannelID returns the channel ID constraint.
	// Cannot be empty.
	BuildChannelSubscriptionChannelID() string
	// BuildChannelSubscriptionPrivKey returns the private key to use to subscribe.
	// Cannot be empty.
	BuildChannelSubscriptionPrivKey() crypto.PrivKey
}

BuildChannelSubscription is a directive to subscribe to a channel.

func NewBuildChannelSubscription

func NewBuildChannelSubscription(channelID string, privKey crypto.PrivKey) BuildChannelSubscription

NewBuildChannelSubscription constructs a new BuildChannelSubscription directive.

type BuildChannelSubscriptionValue

type BuildChannelSubscriptionValue = Subscription

BuildChannelSubscriptionValue is the result type for BuildChannelSubscription. The value is removed and replaced when necessary.

func ExBuildChannelSubscription added in v0.8.9

func ExBuildChannelSubscription(
	ctx context.Context,
	b bus.Bus,
	returnIfIdle bool,
	channelID string,
	privKey crypto.PrivKey,
	valDisposeCallback func(),
) (BuildChannelSubscriptionValue, directive.Instance, directive.Reference, error)

ExBuildChannelSubscription executes the BuildChannelSubscription directive. Waits for the channel subscription to be built. If values are returned, returns vals, valsRef, nil Otherwise returns nil, nil, err

type Controller

type Controller interface {
	// Controller is the controllerbus controller interface.
	controller.Controller

	// GetPubSub returns the controlled PubSub router.
	// This may wait for the PubSub to be ready.
	GetPubSub(ctx context.Context) (PubSub, error)
}

Controller is a PubSub controller.

type Message

type Message interface {
	// GetFrom returns the peer ID of the sender.
	GetFrom() peer.ID
	// GetAuthenticated indicates if the signature is valid.
	GetAuthenticated() bool
	// GetData returns the message data.
	GetData() []byte
}

Message is a pubsub message.

type PeerLinkTuple

type PeerLinkTuple struct {
	PeerID peer.ID
	LinkID uint64
}

PeerLinkTuple is the peer-id link-id tuple.

func NewPeerLinkTuple

func NewPeerLinkTuple(lnk link.Link) PeerLinkTuple

NewPeerLinkTuple constructs a new peer link tuple.

type PubSub

type PubSub interface {
	// Execute executes the PubSub routines.
	Execute(ctx context.Context) error
	// AddPeerStream adds a negotiated peer stream.
	// Two streams will be negotiated, one outgoing, one incoming.
	// The pubsub should communicate over the stream.
	AddPeerStream(tpl PeerLinkTuple, initiator bool, mstrm link.MountedStream)
	// AddSubscription adds a channel subscription, returning a subscription handle.
	AddSubscription(ctx context.Context, privKey crypto.PrivKey, channelID string) (Subscription, error)
	// Close closes the pubsub.
	Close()
}

PubSub is an implementation of a pub-sub message router. The PubSub controller provides a common implementation for pub-sub routers. The PubSub interface declares the requirements for a router. The router is constructed with a private key which is used for communications. Each subscription also has a private key to identify the publisher/subscriber. Publishing is performed by first subscribing and then publishing to the subscription.

type PubSubHandler

type PubSubHandler interface{}

PubSubHandler manages a PubSub and receives event callbacks. This is typically fulfilled by the PubSub controller.

type Subscription

type Subscription interface {
	// GetPeerId returns the peer ID for this subscription derived from private key.
	GetPeerId() peer.ID
	// GetChannelId returns the channel id.
	GetChannelId() string
	// Publish writes to the channel using the subscription's private key.
	Publish(data []byte) error
	// AddHandler adds a callback that is called with each received message.
	// The callback should not block.
	// Returns a remove function.
	// The handler(s) are also removed when the subscription is released.
	AddHandler(cb func(m Message)) func()
	// Release releases the subscription handle, clearing the handlers.
	Release()
}

Subscription is a pubsub channel subscription handle.

Directories

Path Synopsis
util

Jump to

Keyboard shortcuts

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