channel

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotOwner       = errors.New("Not owner of key - (Beam)")
	ErrNotFound       = errors.New("Key not found in store - (Beam)")
	ErrInvalidMessage = errors.New("Invalid message received in Pubsub Topic - (Beam)")
)

Functions

func DeleteStoreKey added in v0.14.0

func DeleteStoreKey(s *v1.ChannelStore, key string, b *channel) error

Delete deletes an entry from the store and publishes an event

func GetKey added in v0.14.0

func GetKey(s *v1.ChannelStore, key string) ([]byte, error)

Get returns the value of the entry

func HandleStore added in v0.14.0

func HandleStore(s *v1.ChannelStore, e *v1.ChannelEvent, b *channel) error

Handle checks the event type and handles it with the store

func NewStore added in v0.12.5

func NewStore(opts *options) *v1.ChannelStore

NewStore creates a new store

func PublishEvent added in v0.14.0

func PublishEvent(ctx context.Context, t *ps.Topic, e *v1.ChannelEvent) error

Publish publishes the event to the topic

func PutStoreKey added in v0.14.0

func PutStoreKey(s *v1.ChannelStore, key string, value []byte, b *channel) error

Put puts an entry into the store and publishes an event

func SetStoreEntry added in v0.14.0

func SetStoreEntry(se *v1.ChannelStoreRecord, value []byte, selfID string) (*v1.ChannelEvent, error)

Set updates the entry in the store and publishes an event

Types

type Channel

type Channel interface {
	// Did returns the DID of the channel.
	Did() string

	// Get returns the value for the given key.
	Get(key string) ([]byte, error)

	// Put stores the value for the given key.
	Put(key string, value []byte) error

	// Delete removes the value for the given key.
	Delete(key string) error

	// Read returns a list of all peers subscribed to the channel topic.
	Read() []peer.ID

	// Publish publishes the given message to the channel topic.
	Publish(text string, data []byte) error

	// Listen subscribes to the beam topic and returns a channel that will
	// receive events.
	Listen() (<-chan *v1.ChannelMessage, error)

	// Close closes the channel.
	Close() error
}

Channel is a pubsub based Key-Value store for Libp2p nodes.

func New

func New(ctx context.Context, n nh.HostImpl, id string, options ...Option) (Channel, error)

New creates a new beam with the given name and options.

type Option

type Option func(*options)

Option is a function that modifies the beam options.

func WithCapacity

func WithCapacity(capacity int) Option

WithCapacity sets the capacity of the beam store.

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets the time-to-live for the beam store entries

Jump to

Keyboard shortcuts

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