mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
coreapi: implement pubsub api
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@0d0069ff23 This commit was moved from ipfs/boxo@1b8732304c
This commit is contained in:
parent
f9a9347006
commit
729bb03d1b
@ -37,6 +37,9 @@ type CoreAPI interface {
|
||||
// Swarm returns an implementation of Swarm API
|
||||
Swarm() SwarmAPI
|
||||
|
||||
// PubSub returns an implementation of PubSub API
|
||||
PubSub() PubSubAPI
|
||||
|
||||
// ResolvePath resolves the path using Unixfs resolver
|
||||
ResolvePath(context.Context, Path) (ResolvedPath, error)
|
||||
|
||||
|
||||
@ -4,5 +4,5 @@ import "errors"
|
||||
|
||||
var (
|
||||
ErrIsDir = errors.New("object is a directory")
|
||||
ErrOffline = errors.New("can't resolve, ipfs node is offline")
|
||||
ErrOffline = errors.New("this action must be run in online mode, try running 'ipfs daemon' first")
|
||||
)
|
||||
|
||||
@ -39,16 +39,18 @@ func PubSubSubscribeOptions(opts ...PubSubSubscribeOption) (*PubSubSubscribeSett
|
||||
return options, nil
|
||||
}
|
||||
|
||||
type PubSubOptions struct{}
|
||||
type pubsubOpts struct{}
|
||||
|
||||
func (api *PubSubOptions) WithTopic(topic string) PubSubPeersOption {
|
||||
var PubBub nameOpts
|
||||
|
||||
func (pubsubOpts) Topic(topic string) PubSubPeersOption {
|
||||
return func(settings *PubSubPeersSettings) error {
|
||||
settings.Topic = topic
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (api *PubSubOptions) WithDiscover(discover bool) PubSubSubscribeOption {
|
||||
func (pubsubOpts) Discover(discover bool) PubSubSubscribeOption {
|
||||
return func(settings *PubSubSubscribeSettings) error {
|
||||
settings.Discover = discover
|
||||
return nil
|
||||
|
||||
@ -6,15 +6,15 @@ import (
|
||||
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
|
||||
peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
|
||||
)
|
||||
|
||||
// PubSubSubscription is an active PubSub subscription
|
||||
type PubSubSubscription interface {
|
||||
io.Closer
|
||||
|
||||
// Chan return incoming message channel
|
||||
Chan(context.Context) <-chan PubSubMessage
|
||||
// Next return the next incoming message
|
||||
Next(context.Context) (PubSubMessage, error)
|
||||
}
|
||||
|
||||
// PubSubMessage is a single PubSub message
|
||||
@ -35,17 +35,9 @@ type PubSubAPI interface {
|
||||
// TODO: WithTopic
|
||||
Peers(context.Context, ...options.PubSubPeersOption) ([]peer.ID, error)
|
||||
|
||||
// WithTopic is an option for peers which specifies a topic filter for the
|
||||
// function
|
||||
WithTopic(topic string) options.PubSubPeersOption
|
||||
|
||||
// Publish a message to a given pubsub topic
|
||||
Publish(context.Context, string, []byte) error
|
||||
|
||||
// Subscribe to messages on a given topic
|
||||
Subscribe(context.Context, string) (PubSubSubscription, error)
|
||||
|
||||
// WithDiscover is an option for Subscribe which specifies whether to try to
|
||||
// discover other peers subscribed to the same topic
|
||||
WithDiscover(discover bool) options.PubSubSubscribeOption
|
||||
Subscribe(context.Context, string, ...options.PubSubSubscribeOption) (PubSubSubscription, error)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user