IPFS builds a group of fx Options based on the passed BuildCfg
(ctx context.Context, bcfg *BuildCfg)
| 403 | |
| 404 | // IPFS builds a group of fx Options based on the passed BuildCfg |
| 405 | func IPFS(ctx context.Context, bcfg *BuildCfg) fx.Option { |
| 406 | if bcfg == nil { |
| 407 | bcfg = new(BuildCfg) |
| 408 | } |
| 409 | |
| 410 | bcfgOpts, cfg := bcfg.options(ctx) |
| 411 | if cfg == nil { |
| 412 | return bcfgOpts // error |
| 413 | } |
| 414 | |
| 415 | userResourceOverrides, err := bcfg.Repo.UserResourceOverrides() |
| 416 | if err != nil { |
| 417 | return fx.Error(err) |
| 418 | } |
| 419 | |
| 420 | // Migrate users of deprecated Experimental.ShardingEnabled flag |
| 421 | if cfg.Experimental.ShardingEnabled { |
| 422 | logger.Fatal("The `Experimental.ShardingEnabled` field is no longer used, please remove it from the config. Use Import.UnixFSHAMTDirectorySizeThreshold instead.") |
| 423 | } |
| 424 | if !cfg.Internal.UnixFSShardingSizeThreshold.IsDefault() { |
| 425 | msg := "The `Internal.UnixFSShardingSizeThreshold` field was renamed to `Import.UnixFSHAMTDirectorySizeThreshold`. Please update your config.\n" |
| 426 | if !cfg.Import.UnixFSHAMTDirectorySizeThreshold.IsDefault() { |
| 427 | logger.Fatal(msg) // conflicting values, hard fail |
| 428 | } |
| 429 | logger.Error(msg) |
| 430 | // Migrate the old OptionalString value to the new OptionalBytes field. |
| 431 | // Since OptionalBytes embeds OptionalString, we can construct it directly |
| 432 | // with the old value, preserving the user's original string (e.g., "256KiB"). |
| 433 | cfg.Import.UnixFSHAMTDirectorySizeThreshold = config.OptionalBytes{OptionalString: *cfg.Internal.UnixFSShardingSizeThreshold} |
| 434 | } |
| 435 | |
| 436 | // Validate Import configuration |
| 437 | if err := config.ValidateImportConfig(&cfg.Import); err != nil { |
| 438 | return fx.Error(err) |
| 439 | } |
| 440 | |
| 441 | // Validate Provide configuration |
| 442 | if err := config.ValidateProvideConfig(&cfg.Provide); err != nil { |
| 443 | return fx.Error(err) |
| 444 | } |
| 445 | |
| 446 | // Directory sharding settings from Import config. |
| 447 | // These globals affect both `ipfs add` and MFS (`ipfs files` API). |
| 448 | shardSizeThreshold := cfg.Import.UnixFSHAMTDirectorySizeThreshold.WithDefault(config.DefaultUnixFSHAMTDirectorySizeThreshold) |
| 449 | shardMaxFanout := cfg.Import.UnixFSHAMTDirectoryMaxFanout.WithDefault(config.DefaultUnixFSHAMTDirectoryMaxFanout) |
| 450 | uio.HAMTShardingSize = int(shardSizeThreshold) |
| 451 | uio.DefaultShardWidth = int(shardMaxFanout) |
| 452 | uio.HAMTSizeEstimation = cfg.Import.HAMTSizeEstimationMode() |
| 453 | |
| 454 | providerStrategy := cfg.Provide.Strategy.WithDefault(config.DefaultProvideStrategy) |
| 455 | |
| 456 | return fx.Options( |
| 457 | bcfgOpts, |
| 458 | |
| 459 | Storage(bcfg, cfg), |
| 460 | Identity(cfg), |
| 461 | IPNS, |
| 462 | Networked(bcfg, cfg, userResourceOverrides), |
no test coverage detected