Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
interface-go-dms3-core
Commits
0d0069ff
Commit
0d0069ff
authored
Mar 10, 2018
by
Łukasz Magiera
Committed by
Steven Allen
Oct 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: implement pubsub api
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
ccaec46f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
16 deletions
+13
-16
coreapi.go
coreapi.go
+3
-0
errors.go
errors.go
+1
-1
options/pubsub.go
options/pubsub.go
+5
-3
pubsub.go
pubsub.go
+4
-12
No files found.
coreapi.go
View file @
0d0069ff
...
...
@@ -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
)
...
...
errors.go
View file @
0d0069ff
...
...
@@ -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
"
)
)
options/pubsub.go
View file @
0d0069ff
...
...
@@ -39,16 +39,18 @@ func PubSubSubscribeOptions(opts ...PubSubSubscribeOption) (*PubSubSubscribeSett
return
options
,
nil
}
type
P
ub
S
ubOpt
ion
s
struct
{}
type
p
ub
s
ubOpts
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
*
P
ub
S
ubOpt
ions
)
With
Discover
(
discover
bool
)
PubSubSubscribeOption
{
func
(
p
ub
s
ubOpt
s
)
Discover
(
discover
bool
)
PubSubSubscribeOption
{
return
func
(
settings
*
PubSubSubscribeSettings
)
error
{
settings
.
Discover
=
discover
return
nil
...
...
pubsub.go
View file @
0d0069ff
...
...
@@ -6,15 +6,15 @@ import (
options
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
peer
"gx/ipfs/Qm
ZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS
/go-libp2p-peer"
peer
"gx/ipfs/Qm
QsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W
/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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment