master
go 48 lines 1.16 KB
Raw
1 package iface
2
3 import (
4 "context"
5 "io"
6
7 "github.com/ipfs/kubo/core/coreiface/options"
8
9 "github.com/libp2p/go-libp2p/core/peer"
10 )
11
12 // PubSubSubscription is an active PubSub subscription
13 type PubSubSubscription interface {
14 io.Closer
15
16 // Next return the next incoming message
17 Next(context.Context) (PubSubMessage, error)
18 }
19
20 // PubSubMessage is a single PubSub message
21 type PubSubMessage interface {
22 // From returns id of a peer from which the message has arrived
23 From() peer.ID
24
25 // Data returns the message body
26 Data() []byte
27
28 // Seq returns message identifier
29 Seq() []byte
30
31 // Topics returns list of topics this message was set to
32 Topics() []string
33 }
34
35 // PubSubAPI specifies the interface to PubSub
36 type PubSubAPI interface {
37 // Ls lists subscribed topics by name
38 Ls(context.Context) ([]string, error)
39
40 // Peers list peers we are currently pubsubbing with
41 Peers(context.Context, ...options.PubSubPeersOption) ([]peer.ID, error)
42
43 // Publish a message to a given pubsub topic
44 Publish(context.Context, string, []byte) error
45
46 // Subscribe to messages on a given topic
47 Subscribe(context.Context, string, ...options.PubSubSubscribeOption) (PubSubSubscription, error)
48 }