diff --git a/main.go b/main.go index db46aee..569ef68 100644 --- a/main.go +++ b/main.go @@ -156,6 +156,12 @@ Generate an identity seed and launch a gateway: EnvVars: []string{"RAINBOW_GC_THRESHOLD"}, Usage: "Percentage of how much of the disk free space must be available", }, + &cli.BoolFlag{ + Name: "libp2p", + Value: true, + EnvVars: []string{"RAINBOW_LIBP2P"}, + Usage: "Enable or disable the usage of Libp2p", + }, &cli.IntFlag{ Name: "libp2p-connmgr-low", Value: 100, @@ -322,10 +328,10 @@ share the same seed as long as the indexes are different. bitswap := cctx.Bool("bitswap") dhtRouting := DHTRouting(cctx.String("dht-routing")) seedPeering := cctx.Bool("seed-peering") - noLibp2p := !bitswap && dhtRouting == DHTOff && !seedPeering + libp2p := cctx.Bool("libp2p") // Only load secrets if we need Libp2p. - if !noLibp2p { + if libp2p { credDir := os.Getenv("CREDENTIALS_DIRECTORY") secretsDir := ddir @@ -411,10 +417,10 @@ share the same seed as long as the indexes are different. goLog.Infof("Rainbow config: %+v", cfg) - if noLibp2p { - gnd, err = SetupNoLibp2p(cctx.Context, cfg, cdns) + if libp2p { + gnd, err = SetupWithLibp2p(cctx.Context, cfg, priv, cdns) } else { - gnd, err = Setup(cctx.Context, cfg, priv, cdns) + gnd, err = SetupNoLibp2p(cctx.Context, cfg, cdns) } if err != nil { return err diff --git a/main_test.go b/main_test.go index 5b0d9b3..33c0354 100644 --- a/main_test.go +++ b/main_test.go @@ -63,7 +63,7 @@ func mustTestNodeWithKey(t *testing.T, cfg Config, sk ic.PrivKey) *Node { _ = cdns.Close() }) - nd, err := Setup(ctx, cfg, sk, cdns) + nd, err := SetupWithLibp2p(ctx, cfg, sk, cdns) require.NoError(t, err) return nd } diff --git a/setup.go b/setup.go index 0b2eb98..f746a72 100644 --- a/setup.go +++ b/setup.go @@ -173,7 +173,11 @@ func SetupNoLibp2p(ctx context.Context, cfg Config, dnsCache *cachedDNS) (*Node, }, nil } -func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cachedDNS) (*Node, error) { +func SetupWithLibp2p(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cachedDNS) (*Node, error) { + if !cfg.Bitswap && cfg.DHTRouting == DHTOff && !cfg.SeedPeering { + return nil, errors.New("libp2p is enabled, but not used: bitswap, dht and seed peering are disabled") + } + var err error cfg.DataDir, err = filepath.Abs(cfg.DataDir) diff --git a/setup_test.go b/setup_test.go index 0d824d7..ca32ede 100644 --- a/setup_test.go +++ b/setup_test.go @@ -185,7 +185,7 @@ func testSeedPeering(t *testing.T, n int, dhtRouting DHTRouting, dhtSharedHost b SeedPeeringMaxIndex: n, } - nodes[i], err = Setup(ctx, cfgs[i], keys[i], cdns) + nodes[i], err = SetupWithLibp2p(ctx, cfgs[i], keys[i], cdns) require.NoError(t, err) }