mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
hide pubsub behind feature flag
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
parent
dfc7d1dd8d
commit
1e1a772bd0
@ -11,11 +11,6 @@ import (
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net"
|
||||
_ "gx/ipfs/QmV3NSS3A1kX5s28r7yLczhDsXzkgo65cqRgKFXYunWZmD/metrics/runtime"
|
||||
|
||||
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
commands "github.com/ipfs/go-ipfs/core/commands"
|
||||
@ -25,7 +20,11 @@ import (
|
||||
nodeMount "github.com/ipfs/go-ipfs/fuse/node"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
|
||||
|
||||
"gx/ipfs/QmPpRcbNUXauP3zWZ1NJMLWpe4QnmEHrd2ba2D3yqWznw7/go-multiaddr-net"
|
||||
conn "gx/ipfs/QmUuwQUJmtvC6ReYcu7xaYKEUM3pD46H18dFn3LBhVt2Di/go-libp2p/p2p/net/conn"
|
||||
_ "gx/ipfs/QmV3NSS3A1kX5s28r7yLczhDsXzkgo65cqRgKFXYunWZmD/metrics/runtime"
|
||||
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
|
||||
util "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
|
||||
pstore "gx/ipfs/QmdMfSLMDBDYhtc4oF3NYGCZr5dy4wQb6Ji26N4D4mdxa2/go-libp2p-peerstore"
|
||||
prometheus "gx/ipfs/QmdhsRK1EK2fvAz2i2SH5DEfkL6seDuyMYEsxKa9Braim3/client_golang/prometheus"
|
||||
@ -45,6 +44,7 @@ const (
|
||||
unencryptTransportKwd = "disable-transport-encryption"
|
||||
unrestrictedApiAccessKwd = "unrestricted-api"
|
||||
writableKwd = "writable"
|
||||
enableFloodSubKwd = "enable-pubsub-experiment"
|
||||
// apiAddrKwd = "address-api"
|
||||
// swarmAddrKwd = "address-swarm"
|
||||
)
|
||||
@ -143,6 +143,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)"),
|
||||
@ -258,14 +259,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 {
|
||||
|
||||
@ -31,6 +31,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
|
||||
@ -43,6 +46,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")
|
||||
@ -182,7 +193,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 {
|
||||
|
||||
@ -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:] {
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user