Skip to content

Commit

Permalink
feat: add global --libp2p (RAINBOW_LIBP2P) flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed May 21, 2024
1 parent 7d0f612 commit de15394
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Check warning on line 331 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L328-L331

Added lines #L328 - L331 were not covered by tests

// Only load secrets if we need Libp2p.
if !noLibp2p {
if libp2p {
credDir := os.Getenv("CREDENTIALS_DIRECTORY")
secretsDir := ddir

Check warning on line 336 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L334-L336

Added lines #L334 - L336 were not covered by tests

Expand Down Expand Up @@ -411,10 +417,10 @@ share the same seed as long as the indexes are different.

goLog.Infof("Rainbow config: %+v", cfg)

Check warning on line 418 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L418

Added line #L418 was not covered by tests

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)

Check warning on line 423 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L420-L423

Added lines #L420 - L423 were not covered by tests
}
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ func SetupNoLibp2p(ctx context.Context, cfg Config, dnsCache *cachedDNS) (*Node,
}, nil

Check warning on line 173 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L167-L173

Added lines #L167 - L173 were not covered by tests
}

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")

Check warning on line 178 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L178

Added line #L178 was not covered by tests
}

var err error

cfg.DataDir, err = filepath.Abs(cfg.DataDir)
Expand Down
2 changes: 1 addition & 1 deletion setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit de15394

Please sign in to comment.