Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrResponseNotReceived indicates a response was not received after publishing a message. ErrResponseNotReceived = errors.New("response not received") )
Functions ¶
This section is empty.
Types ¶
type EventHandler ¶
EventHandler is used to receive topic peer events.
type MessageHandler ¶
MessageHandler is used to receive topic messages.
type PublishOption ¶
type PublishOption func(*PublishOptions) error
PublishOption defines a Publish option.
func WithIgnoreResponse ¶
func WithIgnoreResponse(enable bool) PublishOption
WithIgnoreResponse indicates whether or not Publish will wait for a response(s) from the receiver(s). Default: disabled.
func WithMultiResponse ¶
func WithMultiResponse(enable bool) PublishOption
WithMultiResponse indicates whether or not Publish will wait for multiple responses before returning. Default: disabled.
func WithPubOpts ¶
func WithPubOpts(opts ...pubsub.PubOpt) PublishOption
WithPubOpts sets native pubsub.PubOpt options.
func WithRepublishing ¶ added in v0.0.5
func WithRepublishing(enable bool) PublishOption
WithRepublishing indicates whether or not Publish will continue republishing to newly joined peers as long as the context hasn't expired or is not canceled. Default: disabled.
type PublishOptions ¶
type PublishOptions struct {
// contains filtered or unexported fields
}
PublishOptions defines options for Publish.
type Response ¶
type Response struct { // ID is the cid.Cid of the received message. ID string // From is the peer.ID of the sender. From peer.ID // Data is the message data. Data []byte // Err is an error from the sender. Err error }
Response wraps a message response.
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic provides a nice interface to a libp2p pubsub topic.
func NewTopic ¶
func NewTopic(ctx context.Context, ps *pubsub.PubSub, host peer.ID, topic string, subscribe bool) (*Topic, error)
NewTopic returns a new topic for the host.
func (*Topic) Publish ¶
func (t *Topic) Publish( ctx context.Context, data []byte, opts ...PublishOption, ) (<-chan Response, error)
Publish data. Note that the data may arrive peers duplicated. And as a result, if WithMultiResponse is supplied, the response may be duplicated as well. See PublishOptions for option details.
func (*Topic) SetEventHandler ¶
func (t *Topic) SetEventHandler(handler EventHandler)
SetEventHandler sets a handler func that will be called with peer events.
func (*Topic) SetMessageHandler ¶
func (t *Topic) SetMessageHandler(handler MessageHandler)
SetMessageHandler sets a handler func that will be called with topic messages. A subscription is required for the handler to be called.