pubsub

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventPeerJoin

func NewEventPeerJoin(p core.PeerID, topic string) interface{}

NewEventPeerJoin creates a new EventPubSubJoin event

func NewEventPeerLeave

func NewEventPeerLeave(p core.PeerID, topic string) interface{}

NewEventPeerLeave creates a new EventPubSubLeave event

Types

type EventPubSubJoin

type EventPubSubJoin struct {
	Topic string
	Peer  core.PeerID
}

EventPubSubJoin Is an event triggered when a peer joins the channel

type EventPubSubLeave

type EventPubSubLeave struct {
	Topic string
	Peer  core.PeerID
}

EventPubSubLeave Is an event triggered when a peer leave the channel

type EventPubSubMessage

type EventPubSubMessage struct {
	Content []byte
	From    core.PeerID
}

EventPubSubMessage Indicates a new message posted on a pubsub topic

func NewEventMessage

func NewEventMessage(from core.PeerID, content []byte) *EventPubSubMessage

Creates a new Message event

type EventPubSubPayload

type EventPubSubPayload struct {
	Payload []byte
	Peer    core.PeerID
}

EventPubSubPayload An event received on new messages

func NewEventPayload

func NewEventPayload(payload []byte, peerid core.PeerID) *EventPubSubPayload

NewEventPayload Creates a new Message event

type PubSubInterface

type PubSubInterface interface {
	// TopicSubscribe Subscribes to a topic
	TopicSubscribe(ctx context.Context, topic string) (PubSubTopic, error)
}

func NewPubSub

func NewPubSub(api coreapi.CoreAPI, id core.PeerID, pollInterval time.Duration, logger *zap.Logger) PubSubInterface

type PubSubTopic

type PubSubTopic interface {
	// Publish Posts a new message on a topic
	Publish(ctx context.Context, message []byte) error

	// Peers Lists peers connected to the topic
	Peers(ctx context.Context) ([]core.PeerID, error)

	// WatchPeers subscribes to peers joining or leaving the topic
	WatchPeers(ctx context.Context) (<-chan interface{}, error)

	// WatchMessages Subscribes to new messages
	WatchMessages(ctx context.Context) (<-chan *EventPubSubMessage, error)

	// Topic Returns the topic name
	Topic() string
}

PubSubTopic is a pub sub subscription to a topic

Jump to

Keyboard shortcuts

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