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
go-dms3
Commits
009301bf
Commit
009301bf
authored
Sep 14, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hide pubsub behind feature flag
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
ff770fad
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
8 deletions
+45
-8
cmd/ipfs/daemon.go
cmd/ipfs/daemon.go
+11
-4
core/builder.go
core/builder.go
+12
-1
core/commands/pubsub.go
core/commands/pubsub.go
+17
-0
core/commands/root.go
core/commands/root.go
+1
-1
core/core.go
core/core.go
+4
-2
No files found.
cmd/ipfs/daemon.go
View file @
009301bf
...
...
@@ -23,7 +23,7 @@ import (
"gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net"
"gx/ipfs/QmR3KwhXCRLTNZB59vELb2HhEWrGy9nuychepxFtj3wWYa/client_golang/prometheus"
conn
"gx/ipfs/QmUuwQUJmtvC6ReYcu7xaYKEUM3pD46H18dFn3LBhVt2Di/go-libp2p/p2p/net/conn"
mprome
"gx/ipfs/QmXWro6iddJRbGWUoZDpTu6tjo5EXX4xJHHR9VczeoGZbw/go-metrics-prometheus"
pstore
"gx/ipfs/QmYkwVGkwoPbMVQEbf6LonZg4SsCxGP3H7PBEtdNCNRyxD/go-libp2p-peerstore"
ma
"gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
...
...
@@ -47,6 +47,7 @@ const (
unencryptTransportKwd
=
"disable-transport-encryption"
unrestrictedApiAccessKwd
=
"unrestricted-api"
writableKwd
=
"writable"
enableFloodSubKwd
=
"enable-pubsub-experiment"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
)
...
...
@@ -145,6 +146,7 @@ Headers.
cmds
.
BoolOption
(
adjustFDLimitKwd
,
"Check and raise file descriptor limits if needed"
)
.
Default
(
true
),
cmds
.
BoolOption
(
offlineKwd
,
"Run offline. Do not connect to the rest of the network but provide local API."
)
.
Default
(
false
),
cmds
.
BoolOption
(
migrateKwd
,
"If true, assume yes at the migrate prompt. If false, assume no."
),
cmds
.
BoolOption
(
enableFloodSubKwd
,
"Instantiate the ipfs daemon with the experimental pubsub feature enabled."
),
// TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
...
...
@@ -266,14 +268,19 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
return
}
offline
,
_
,
_
:=
req
.
Option
(
offlineKwd
)
.
Bool
()
pubsub
,
_
,
_
:=
req
.
Option
(
enableFloodSubKwd
)
.
Bool
()
// Start assembling node config
ncfg
:=
&
core
.
BuildCfg
{
Repo
:
repo
,
Permament
:
true
,
// It is temporary way to signify that node is permament
//TODO(Kubuxu): refactor Online vs Offline by adding Permement vs Epthemeral
Online
:
!
offline
,
ExtraOpts
:
map
[
string
]
bool
{
"pubsub"
:
pubsub
,
},
//TODO(Kubuxu): refactor Online vs Offline by adding Permanent vs Ephemeral
}
offline
,
_
,
_
:=
req
.
Option
(
offlineKwd
)
.
Bool
()
ncfg
.
Online
=
!
offline
routingOption
,
_
,
err
:=
req
.
Option
(
routingOptionKwd
)
.
String
()
if
err
!=
nil
{
...
...
core/builder.go
View file @
009301bf
...
...
@@ -32,6 +32,9 @@ type BuildCfg struct {
// If online is set, the node will have networking enabled
Online
bool
// ExtraOpts is a map of extra options used to configure the ipfs nodes creation
ExtraOpts
map
[
string
]
bool
// If permament then node should run more expensive processes
// that will improve performance in long run
Permament
bool
...
...
@@ -44,6 +47,14 @@ type BuildCfg struct {
Repo
repo
.
Repo
}
func
(
cfg
*
BuildCfg
)
getOpt
(
key
string
)
bool
{
if
cfg
.
ExtraOpts
==
nil
{
return
false
}
return
cfg
.
ExtraOpts
[
key
]
}
func
(
cfg
*
BuildCfg
)
fillDefaults
()
error
{
if
cfg
.
Repo
!=
nil
&&
cfg
.
NilRepo
{
return
errors
.
New
(
"cannot set a repo and specify nilrepo at the same time"
)
...
...
@@ -184,7 +195,7 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
if
cfg
.
Online
{
do
:=
setupDiscoveryOption
(
rcfg
.
Discovery
)
if
err
:=
n
.
startOnlineServices
(
ctx
,
cfg
.
Routing
,
cfg
.
Host
,
do
);
err
!=
nil
{
if
err
:=
n
.
startOnlineServices
(
ctx
,
cfg
.
Routing
,
cfg
.
Host
,
do
,
cfg
.
getOpt
(
"pubsub"
)
);
err
!=
nil
{
return
err
}
}
else
{
...
...
core/commands/pubsub.go
View file @
009301bf
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"fmt"
"io"
"sync"
"time"
...
...
@@ -28,6 +29,8 @@ subscribe to new messages on a given topic.
This is an experimental feature. It is not intended in its current state
to be used in a production environment.
To use, the daemon must be run with '--enable-pubsub-experiment'.
`
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
...
...
@@ -44,6 +47,8 @@ ipfs pubsub sub subscribes to messages on a given topic.
This is an experimental feature. It is not intended in its current state
to be used in a production environment.
To use, the daemon must be run with '--enable-pubsub-experiment'.
`
,
},
Arguments
:
[]
cmds
.
Argument
{
...
...
@@ -65,6 +70,11 @@ to be used in a production environment.
return
}
if
n
.
Floodsub
==
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use."
),
cmds
.
ErrNormal
)
return
}
topic
:=
req
.
Arguments
()[
0
]
msgs
,
err
:=
n
.
Floodsub
.
Subscribe
(
topic
)
if
err
!=
nil
{
...
...
@@ -176,6 +186,8 @@ ipfs pubsub pub publishes a message to a specified topic.
This is an experimental feature. It is not intended in its current state
to be used in a production environment.
To use, the daemon must be run with '--enable-pubsub-experiment'.
`
,
},
Arguments
:
[]
cmds
.
Argument
{
...
...
@@ -196,6 +208,11 @@ to be used in a production environment.
return
}
if
n
.
Floodsub
==
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use."
),
cmds
.
ErrNormal
)
return
}
topic
:=
req
.
Arguments
()[
0
]
for
_
,
data
:=
range
req
.
Arguments
()[
1
:
]
{
...
...
core/commands/root.go
View file @
009301bf
...
...
@@ -99,13 +99,13 @@ var rootSubcommands = map[string]*cmds.Command{
"object"
:
ocmd
.
ObjectCmd
,
"pin"
:
PinCmd
,
"ping"
:
PingCmd
,
"pubsub"
:
PubsubCmd
,
"refs"
:
RefsCmd
,
"repo"
:
RepoCmd
,
"resolve"
:
ResolveCmd
,
"stats"
:
StatsCmd
,
"swarm"
:
SwarmCmd
,
"tar"
:
TarCmd
,
"pubsub"
:
PubsubCmd
,
"tour"
:
tourCmd
,
"file"
:
unixfs
.
UnixFSCmd
,
"update"
:
ExternalBinary
(),
...
...
core/core.go
View file @
009301bf
...
...
@@ -129,7 +129,7 @@ type Mounts struct {
Ipns
mount
.
Mount
}
func
(
n
*
IpfsNode
)
startOnlineServices
(
ctx
context
.
Context
,
routingOption
RoutingOption
,
hostOption
HostOption
,
do
DiscoveryOption
)
error
{
func
(
n
*
IpfsNode
)
startOnlineServices
(
ctx
context
.
Context
,
routingOption
RoutingOption
,
hostOption
HostOption
,
do
DiscoveryOption
,
pubsub
bool
)
error
{
if
n
.
PeerHost
!=
nil
{
// already online.
return
errors
.
New
(
"node already online"
)
...
...
@@ -187,7 +187,9 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
go
n
.
Reprovider
.
ProvideEvery
(
ctx
,
interval
)
}
n
.
Floodsub
=
floodsub
.
NewFloodSub
(
ctx
,
peerhost
)
if
pubsub
{
n
.
Floodsub
=
floodsub
.
NewFloodSub
(
ctx
,
peerhost
)
}
// setup local discovery
if
do
!=
nil
{
...
...
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