coreapi: implement pubsub api
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@0d0069ff23a4dd26fa62fd91e5875b2526742da5 This commit was moved from ipfs/boxo@1b8732304c12b825e9a8fd69b51494c9c67f39d0
Łukasz Magiera committed
Mar 10, 2018 at 19:28 UTC
729bb03d1b244e9ec7e27a28fa347ec79c15ae0c
4 files changed
+13
-16
core/coreiface/coreapi.go
+3
@@ -37,6 +37,9 @@ type CoreAPI interface {
37
// Swarm returns an implementation of Swarm API
38
Swarm() SwarmAPI
39
40
+ // PubSub returns an implementation of PubSub API
41
+ PubSub() PubSubAPI
42
+
43
// ResolvePath resolves the path using Unixfs resolver
44
ResolvePath(context.Context, Path) (ResolvedPath, error)
45
core/coreiface/errors.go
+1
-1
@@ -4,5 +4,5 @@ import "errors"
4
5
var (
6
ErrIsDir = errors.New("object is a directory")
7
- ErrOffline = errors.New("can't resolve, ipfs node is offline")
7
+ ErrOffline = errors.New("this action must be run in online mode, try running 'ipfs daemon' first")
8
)
core/coreiface/options/pubsub.go
+5
-3
@@ -39,16 +39,18 @@ func PubSubSubscribeOptions(opts ...PubSubSubscribeOption) (*PubSubSubscribeSett
39
return options, nil
40
}
41
42
-type PubSubOptions struct{}
42
+type pubsubOpts struct{}
43
44
-func (api *PubSubOptions) WithTopic(topic string) PubSubPeersOption {
44
+var PubBub nameOpts
45
+
46
+func (pubsubOpts) Topic(topic string) PubSubPeersOption {
47
return func(settings *PubSubPeersSettings) error {
48
settings.Topic = topic
49
return nil
50
}
51
}
52
51
-func (api *PubSubOptions) WithDiscover(discover bool) PubSubSubscribeOption {
53
+func (pubsubOpts) Discover(discover bool) PubSubSubscribeOption {
54
return func(settings *PubSubSubscribeSettings) error {
55
settings.Discover = discover
56
return nil
core/coreiface/pubsub.go
+4
-12
@@ -6,15 +6,15 @@ import (
6
7
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8
9
- peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
9
+ peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
10
)
11
12
// PubSubSubscription is an active PubSub subscription
13
type PubSubSubscription interface {
14
io.Closer
15
16
- // Chan return incoming message channel
17
- Chan(context.Context) <-chan PubSubMessage
16
+ // Next return the next incoming message
17
+ Next(context.Context) (PubSubMessage, error)
18
}
19
20
// PubSubMessage is a single PubSub message
@@ -35,17 +35,9 @@ type PubSubAPI interface {
35
// TODO: WithTopic
36
Peers(context.Context, ...options.PubSubPeersOption) ([]peer.ID, error)
37
38
- // WithTopic is an option for peers which specifies a topic filter for the
39
- // function
40
- WithTopic(topic string) options.PubSubPeersOption
41
-
38
// Publish a message to a given pubsub topic
39
Publish(context.Context, string, []byte) error
40
41
// Subscribe to messages on a given topic
46
- Subscribe(context.Context, string) (PubSubSubscription, error)
47
-
48
- // WithDiscover is an option for Subscribe which specifies whether to try to
49
- // discover other peers subscribed to the same topic
50
- WithDiscover(discover bool) options.PubSubSubscribeOption
42
+ Subscribe(context.Context, string, ...options.PubSubSubscribeOption) (PubSubSubscription, error)
43
}