@cryptotaxi247 / kubo / commits / 009301bf7

hide pubsub behind feature flag

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Sep 14, 2016 at 13:55 UTC 009301bf7f06393ea446398aafc54666ef1f6263
5 files changed +45 -8
cmd/ipfs/daemon.go
+11 -4
@@ -23,7 +23,7 @@ import (
23
24 "gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net"
25 "gx/ipfs/QmR3KwhXCRLTNZB59vELb2HhEWrGy9nuychepxFtj3wWYa/client_golang/prometheus"
26 -
26 + conn "gx/ipfs/QmUuwQUJmtvC6ReYcu7xaYKEUM3pD46H18dFn3LBhVt2Di/go-libp2p/p2p/net/conn"
27 mprome "gx/ipfs/QmXWro6iddJRbGWUoZDpTu6tjo5EXX4xJHHR9VczeoGZbw/go-metrics-prometheus"
28 pstore "gx/ipfs/QmYkwVGkwoPbMVQEbf6LonZg4SsCxGP3H7PBEtdNCNRyxD/go-libp2p-peerstore"
29 ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
@@ -47,6 +47,7 @@ const (
47 unencryptTransportKwd = "disable-transport-encryption"
48 unrestrictedApiAccessKwd = "unrestricted-api"
49 writableKwd = "writable"
50 + enableFloodSubKwd = "enable-pubsub-experiment"
51 // apiAddrKwd = "address-api"
52 // swarmAddrKwd = "address-swarm"
53 )
@@ -145,6 +146,7 @@ Headers.
146 cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").Default(true),
147 cmds.BoolOption(offlineKwd, "Run offline. Do not connect to the rest of the network but provide local API.").Default(false),
148 cmds.BoolOption(migrateKwd, "If true, assume yes at the migrate prompt. If false, assume no."),
149 + cmds.BoolOption(enableFloodSubKwd, "Instantiate the ipfs daemon with the experimental pubsub feature enabled."),
150
151 // TODO: add way to override addresses. tricky part: updating the config if also --init.
152 // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
@@ -266,14 +268,19 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
268 return
269 }
270
271 + offline, _, _ := req.Option(offlineKwd).Bool()
272 + pubsub, _, _ := req.Option(enableFloodSubKwd).Bool()
273 +
274 // Start assembling node config
275 ncfg := &core.BuildCfg{
276 Repo: repo,
277 Permament: true, // It is temporary way to signify that node is permament
273 - //TODO(Kubuxu): refactor Online vs Offline by adding Permement vs Epthemeral
278 + Online: !offline,
279 + ExtraOpts: map[string]bool{
280 + "pubsub": pubsub,
281 + },
282 + //TODO(Kubuxu): refactor Online vs Offline by adding Permanent vs Ephemeral
283 }
275 - offline, _, _ := req.Option(offlineKwd).Bool()
276 - ncfg.Online = !offline
284
285 routingOption, _, err := req.Option(routingOptionKwd).String()
286 if err != nil {
core/builder.go
+12 -1
@@ -32,6 +32,9 @@ type BuildCfg struct {
32 // If online is set, the node will have networking enabled
33 Online bool
34
35 + // ExtraOpts is a map of extra options used to configure the ipfs nodes creation
36 + ExtraOpts map[string]bool
37 +
38 // If permament then node should run more expensive processes
39 // that will improve performance in long run
40 Permament bool
@@ -44,6 +47,14 @@ type BuildCfg struct {
47 Repo repo.Repo
48 }
49
50 +func (cfg *BuildCfg) getOpt(key string) bool {
51 + if cfg.ExtraOpts == nil {
52 + return false
53 + }
54 +
55 + return cfg.ExtraOpts[key]
56 +}
57 +
58 func (cfg *BuildCfg) fillDefaults() error {
59 if cfg.Repo != nil && cfg.NilRepo {
60 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 {
195
196 if cfg.Online {
197 do := setupDiscoveryOption(rcfg.Discovery)
187 - if err := n.startOnlineServices(ctx, cfg.Routing, cfg.Host, do); err != nil {
198 + if err := n.startOnlineServices(ctx, cfg.Routing, cfg.Host, do, cfg.getOpt("pubsub")); err != nil {
199 return err
200 }
201 } else {
core/commands/pubsub.go
+17
@@ -4,6 +4,7 @@ import (
4 "bytes"
5 "context"
6 "encoding/binary"
7 + "fmt"
8 "io"
9 "sync"
10 "time"
@@ -28,6 +29,8 @@ subscribe to new messages on a given topic.
29
30 This is an experimental feature. It is not intended in its current state
31 to be used in a production environment.
32 +
33 +To use, the daemon must be run with '--enable-pubsub-experiment'.
34 `,
35 },
36 Subcommands: map[string]*cmds.Command{
@@ -44,6 +47,8 @@ ipfs pubsub sub subscribes to messages on a given topic.
47
48 This is an experimental feature. It is not intended in its current state
49 to be used in a production environment.
50 +
51 +To use, the daemon must be run with '--enable-pubsub-experiment'.
52 `,
53 },
54 Arguments: []cmds.Argument{
@@ -65,6 +70,11 @@ to be used in a production environment.
70 return
71 }
72
73 + if n.Floodsub == nil {
74 + res.SetError(fmt.Errorf("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use."), cmds.ErrNormal)
75 + return
76 + }
77 +
78 topic := req.Arguments()[0]
79 msgs, err := n.Floodsub.Subscribe(topic)
80 if err != nil {
@@ -176,6 +186,8 @@ ipfs pubsub pub publishes a message to a specified topic.
186
187 This is an experimental feature. It is not intended in its current state
188 to be used in a production environment.
189 +
190 +To use, the daemon must be run with '--enable-pubsub-experiment'.
191 `,
192 },
193 Arguments: []cmds.Argument{
@@ -196,6 +208,11 @@ to be used in a production environment.
208 return
209 }
210
211 + if n.Floodsub == nil {
212 + res.SetError(fmt.Errorf("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use."), cmds.ErrNormal)
213 + return
214 + }
215 +
216 topic := req.Arguments()[0]
217
218 for _, data := range req.Arguments()[1:] {
core/commands/root.go
+1 -1
@@ -99,13 +99,13 @@ var rootSubcommands = map[string]*cmds.Command{
99 "object": ocmd.ObjectCmd,
100 "pin": PinCmd,
101 "ping": PingCmd,
102 + "pubsub": PubsubCmd,
103 "refs": RefsCmd,
104 "repo": RepoCmd,
105 "resolve": ResolveCmd,
106 "stats": StatsCmd,
107 "swarm": SwarmCmd,
108 "tar": TarCmd,
108 - "pubsub": PubsubCmd,
109 "tour": tourCmd,
110 "file": unixfs.UnixFSCmd,
111 "update": ExternalBinary(),
core/core.go
+4 -2
@@ -129,7 +129,7 @@ type Mounts struct {
129 Ipns mount.Mount
130 }
131
132 -func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption) error {
132 +func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption, pubsub bool) error {
133
134 if n.PeerHost != nil { // already online.
135 return errors.New("node already online")
@@ -187,7 +187,9 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
187 go n.Reprovider.ProvideEvery(ctx, interval)
188 }
189
190 - n.Floodsub = floodsub.NewFloodSub(ctx, peerhost)
190 + if pubsub {
191 + n.Floodsub = floodsub.NewFloodSub(ctx, peerhost)
192 + }
193
194 // setup local discovery
195 if do != nil {