pubsub

package
v1.10.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: Apache-2.0, MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeMessage

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

FakeMessage is a simple pubsub message

func (*FakeMessage) GetData

func (m *FakeMessage) GetData() []byte

GetData returns the message's payload

func (*FakeMessage) GetFrom

func (m *FakeMessage) GetFrom() peer.ID

GetFrom returns the message's sender ID

type FakeSubscription

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

FakeSubscription is a fake pubsub subscription.

func NewFakeSubscription

func NewFakeSubscription(topic string, bufSize int) *FakeSubscription

NewFakeSubscription builds a new fake subscription to a topic.

func (*FakeSubscription) AwaitCancellation

func (s *FakeSubscription) AwaitCancellation()

AwaitCancellation waits for the subscription to be canceled by the subscriber.

func (*FakeSubscription) Cancel

func (s *FakeSubscription) Cancel()

Cancel cancels this subscription, after which no subsequently posted messages will be received.

func (*FakeSubscription) Fail

func (s *FakeSubscription) Fail(err error)

Fail causes subsequent reads from this subscription to fail.

func (*FakeSubscription) Next

func (s *FakeSubscription) Next(ctx context.Context) (Message, error)

Next returns the next messages from this subscription.

func (*FakeSubscription) Post

func (s *FakeSubscription) Post(msg Message)

Post posts a new message to this subscription.

func (*FakeSubscription) Topic

func (s *FakeSubscription) Topic() string

Topic returns this subscription's topic.

type Message

type Message interface {
	GetSource() peer.ID
	GetSender() peer.ID
	GetData() []byte
}

Message defines the common interface for venus message consumers. It's a subset of the go-libp2p-pubsub/pubsub.go Message type.

type Subscription

type Subscription interface {
	// Topic returns this subscription's topic name
	Topic() string
	// Next returns the next message from this subscription
	Next(ctx context.Context) (Message, error)
	// Cancel cancels this subscription
	Cancel()
}

Subscription is a handle to a pubsub subscription. This matches part of the interface to a libp2p.pubsub.Subscription.

type Topic

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

Topic publishes and subscribes to a libp2p pubsub topic

func NewTopic

func NewTopic(topic *libp2p.Topic) *Topic

NewTopic builds a new topic.

func (*Topic) Publish

func (t *Topic) Publish(ctx context.Context, data []byte) error

Publish publishes to a pubsub topic. It blocks until there is at least one peer on the mesh that can receive the publish.

func (*Topic) Subscribe

func (t *Topic) Subscribe() (Subscription, error)

Subscribe subscribes to a pubsub topic

Jump to

Keyboard shortcuts

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