Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
4bf7f27
feat: prototype autoclient library
lidel Jul 18, 2025
a72b8e1
feat(config): prototype autoconfig profile
lidel Jul 18, 2025
120bb82
feat: prototype embedded repo migrations
lidel Jul 18, 2025
51a49f9
feat: prototype of `ipfs config` support for `auto`
lidel Jul 24, 2025
a860748
docs: MustGetConfigWithMainnetFallbacks
lidel Jul 24, 2025
302dcdf
chore: lint + cleanup redundant tests
lidel Jul 24, 2025
d23374c
refactor: use const with profile names
lidel Jul 24, 2025
355bc3d
refactor: cfg.BootstrapPeers returns raw Bootstrap
lidel Jul 24, 2025
626a99f
fix: use resolved versions for making decisions
lidel Jul 24, 2025
1d91f11
refactor: Β Bootstrap[Peers]WithAutoConfig
lidel Jul 24, 2025
f629d8b
fix(cli): bootstrap cmd with auto
lidel Jul 24, 2025
0e75e4f
refactor: cleanup
lidel Jul 25, 2025
e711c3c
test: multiple consecutive --expand-auto calls
lidel Jul 25, 2025
d18a1fe
refactor: dry and useful logs
lidel Jul 25, 2025
7088d88
refactor: autoconfig .last-refresh
lidel Jul 25, 2025
e1e4e23
fix: `ipfs bootstrap add auto`
lidel Jul 26, 2025
53a642c
docs: AutoConfig in changelog
lidel Jul 26, 2025
273e18e
chore: update func name
lidel Jul 26, 2025
24d552d
refactor: schema v4
lidel Jul 30, 2025
e2476e9
test: DNSResolver validation
lidel Jul 30, 2025
e9f8ce9
docs: autoconfig changelog
lidel Jul 30, 2025
3d34f41
test: basic ipns publishing work in ci (offline)
lidel Jul 30, 2025
e4eb581
chore: cleanup to use testdata
lidel Jul 30, 2025
2a196dc
test(coreapi): ipns name
lidel Jul 30, 2025
a68d581
fix(docker): copy boxo/autoconfig
lidel Jul 30, 2025
8fa6527
fix(autoconfig): real ipni fallback
lidel Jul 30, 2025
a57df38
fix: restore legacy defaultRepo
lidel Jul 31, 2025
9480b93
test: restore coreiface from master
lidel Jul 31, 2025
85e80d4
chore: restore previous namesys wiring
lidel Jul 31, 2025
7585807
refactor: simplify constructDefaultHTTPRouters
lidel Jul 31, 2025
b3975a2
refactor: cleanup config/autoconfig.go
lidel Jul 31, 2025
00c9d9c
fix: thread-safe cache
lidel Jul 31, 2025
82f2b59
refactor: MustGetConfig fallback handling
lidel Aug 1, 2025
2e22eba
test: ParseAndValidateRoutingURL
lidel Aug 1, 2025
24e6aa4
fix: simpler cache dir
lidel Aug 1, 2025
cf8b596
refactor(config): remove need for passing repoPath
lidel Aug 1, 2025
374ba05
chore: collapse diffs of generated data
lidel Aug 1, 2025
1df21cd
chore: restore master code
lidel Aug 1, 2025
f7c2112
test: error cases for autoconfig.json fetch
lidel Aug 1, 2025
f5fe36f
chore: placeholder
lidel Aug 1, 2025
e52befe
refactor: clenup startAutoConfigUpdater
lidel Aug 1, 2025
03a2a3c
test(autoconfig): ipfs swarm connect
lidel Aug 1, 2025
146ef49
refactor: better names for Must* funcs
lidel Aug 1, 2025
3e4a854
fix(fx): ClearCachedNode
lidel Aug 1, 2025
ef98774
test: TestHTTPCachingBehavior and cleanup
lidel Aug 1, 2025
1a7230c
test: TestAutoConfigIPNS
lidel Aug 1, 2025
814723e
test(autoconfig) Routing.Type=auto|delegated
lidel Aug 2, 2025
36acffe
fix: go vet
lidel Aug 2, 2025
332ab2f
test: migration and autoconfig sharness
lidel Aug 3, 2025
a5f6777
fix: sync.RWMutex
lidel Aug 3, 2025
70dbdc8
test(cli): migration_legacy_15_to_17_test.go
lidel Aug 4, 2025
44dec15
test: testCLIUsesCacheOnlyDaemonUpdatesBackground
lidel Aug 4, 2025
e77f434
fix: t0066-migration.sh
lidel Aug 4, 2025
a6efc94
refactor: autoconfig β†’ autoconf
lidel Aug 4, 2025
35e521d
fix: validate AutoConfSchema 1
lidel Aug 4, 2025
1a73236
docs: highlights and deprecations
lidel Aug 4, 2025
7f3bcea
test: testAutoConfWithHTTPS
lidel Aug 4, 2025
5a6c5ab
docs: boxo/autoconf
lidel Aug 4, 2025
491b1c3
docs: examples in boxo/autoconf/README.md
lidel Aug 5, 2025
c71e9d8
Merge branch 'master' into feat-mainnet-autoconfig
gammazero Aug 11, 2025
6a32e60
remove unused import
gammazero Aug 11, 2025
ea6c3e4
Merge branch 'master' into feat-mainnet-autoconfig
gammazero Aug 11, 2025
285be62
Merge branch 'master' into feat-mainnet-autoconfig
gammazero Aug 11, 2025
13357e3
chore: config β†’ conf
lidel Aug 12, 2025
8fd1829
refactor: boxo/autoconf extraction prep
lidel Aug 13, 2025
ebb948f
refactor: boxo/autoconf cleanup, part 1
lidel Aug 13, 2025
95065fd
Merge branch 'master' into feat-mainnet-autoconfig
lidel Aug 13, 2025
564382f
tests: switch to testify
lidel Aug 13, 2025
d88c0d0
fix: log warn when no cache available
lidel Aug 13, 2025
c2129d7
refactor: improve lock scopes
lidel Aug 13, 2025
a4e0671
chore: move atomicfile
lidel Aug 13, 2025
cfa0bcc
refactor: simplify the path operations
lidel Aug 13, 2025
70860e0
refactor: code simplifications
lidel Aug 13, 2025
0a9a5b7
refactor: reuse buildEndpointURL
lidel Aug 13, 2025
a0bac20
fix: Errorf
lidel Aug 13, 2025
c890bfd
chore: remove FromCache
lidel Aug 13, 2025
c0269f4
fix: panic on nil client
lidel Aug 13, 2025
3a6ec69
chore: preallocate slice
lidel Aug 13, 2025
62f67d6
refactor: slices.Contains
lidel Aug 13, 2025
af51a49
refactor: review feedback cleanup
lidel Aug 13, 2025
54df810
refactor: core/node/libp2p/host.go
lidel Aug 13, 2025
b0cdf44
refactor: move autoclient to boxo#997
lidel Aug 13, 2025
1946d45
fix: restore dockerfile
lidel Aug 13, 2025
5d4275e
chore: gofmt
lidel Aug 13, 2025
66fe0a8
Merge branch 'master' into feat-mainnet-autoconfig
gammazero Aug 14, 2025
2176ae4
merge: origin/master into feat-mainnet-autoconfig
lidel Aug 15, 2025
7f027e4
docs: concise changelog
lidel Aug 15, 2025
9321e46
chore: update to latest boxo#997
lidel Aug 15, 2025
018b73b
chore: update to boxo@main
lidel Aug 15, 2025
e4e08a3
merge: origin/master into feat-mainnet-autoconfig
lidel Aug 18, 2025
f2ca7d9
fix: telemetry bootstrap check for autoconf
lidel Aug 18, 2025
f3b8ed3
feat: autoconf telemetry
lidel Aug 18, 2025
2bb5276
test: telemetry schema regression guard
lidel Aug 18, 2025
f0314d0
test: use atomic.Int32 for cleaner counter handling
lidel Aug 18, 2025
0eb4a02
test: remove emojis from test logs
lidel Aug 18, 2025
dc41fbb
test: clarify bootstrap peer round-trip test
lidel Aug 18, 2025
9ffbf88
test: simplify IPNS error tests
lidel Aug 18, 2025
a7b0b21
refactor: rename --delegated-only to --allow-delegated
lidel Aug 19, 2025
470d4db
refactor: make AutoConf.URL implicit like AutoTLS
lidel Aug 19, 2025
0da54e0
fix: sort profile names in config help output
lidel Aug 19, 2025
8ec830b
test: AutoConf in bootstrap add default test
lidel Aug 19, 2025
ccd2388
fix: allow ipfs repo migrate to run without daemon
lidel Aug 19, 2025
6e75456
refactor: make Migration config optional
lidel Aug 19, 2025
d028a23
Merge branch 'master' into feat-mainnet-autoconfig
lidel Aug 19, 2025
2b32db3
fix(migration): use implicit defaults for AutoConf fields
lidel Aug 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,23 @@ LICENSE text eol=auto
# Binary assets
assets/init-doc/* binary
core/coreunix/test_data/** binary
test/cli/migrations/testdata/** binary

# Generated test data
test/cli/migrations/testdata/** linguist-generated=true
test/cli/autoconf/testdata/** linguist-generated=true
test/cli/fixtures/** linguist-generated=true
test/sharness/t0054-dag-car-import-export-data/** linguist-generated=true
test/sharness/t0109-gateway-web-_redirects-data/** linguist-generated=true
test/sharness/t0114-gateway-subdomains/** linguist-generated=true
test/sharness/t0115-gateway-dir-listing/** linguist-generated=true
test/sharness/t0116-gateway-cache/** linguist-generated=true
test/sharness/t0119-prometheus-data/** linguist-generated=true
test/sharness/t0165-keystore-data/** linguist-generated=true
test/sharness/t0275-cid-security-data/** linguist-generated=true
test/sharness/t0280-plugin-dag-jose-data/** linguist-generated=true
test/sharness/t0280-plugin-data/** linguist-generated=true
test/sharness/t0280-plugin-git-data/** linguist-generated=true
test/sharness/t0400-api-no-gateway/** linguist-generated=true
test/sharness/t0701-delegated-routing-reframe/** linguist-generated=true
test/sharness/t0702-delegated-routing-http/** linguist-generated=true
136 changes: 74 additions & 62 deletions cmd/ipfs/kubo/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
nodeMount "github.com/ipfs/kubo/fuse/node"
fsrepo "github.com/ipfs/kubo/repo/fsrepo"
"github.com/ipfs/kubo/repo/fsrepo/migrations"
"github.com/ipfs/kubo/repo/fsrepo/migrations/ipfsfetcher"
p2pcrypto "github.com/libp2p/go-libp2p/core/crypto"
pnet "github.com/libp2p/go-libp2p/core/pnet"
"github.com/libp2p/go-libp2p/core/protocol"
Expand Down Expand Up @@ -65,6 +64,7 @@ const (
routingOptionDHTServerKwd = "dhtserver"
routingOptionNoneKwd = "none"
routingOptionCustomKwd = "custom"
routingOptionDelegatedKwd = "delegated"
routingOptionDefaultKwd = "default"
routingOptionAutoKwd = "auto"
routingOptionAutoClientKwd = "autoclient"
Expand Down Expand Up @@ -275,7 +275,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
}

var cacheMigrations, pinMigrations bool
var fetcher migrations.Fetcher
var externalMigrationFetcher migrations.Fetcher

// acquire the repo lock _before_ constructing a node. we need to make
// sure we are permitted to access the resources (datastore, etc.)
Expand All @@ -285,74 +285,39 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
return err
case fsrepo.ErrNeedMigration:
domigrate, found := req.Options[migrateKwd].(bool)
fmt.Println("Found outdated fs-repo, migrations need to be run.")

// Get current repo version for more informative message
currentVersion, verErr := migrations.RepoVersion(cctx.ConfigRoot)
if verErr != nil {
// Fallback to generic message if we can't read version
fmt.Printf("Kubo repository at %s requires migration.\n", cctx.ConfigRoot)
} else {
fmt.Printf("Kubo repository at %s has version %d and needs to be migrated to version %d.\n",
cctx.ConfigRoot, currentVersion, version.RepoVersion)
}

if !found {
domigrate = YesNoPrompt("Run migrations now? [y/N]")
}

if !domigrate {
fmt.Println("Not running migrations of fs-repo now.")
fmt.Println("Please get fs-repo-migrations from https://dist.ipfs.tech")
fmt.Printf("Not running migrations on repository at %s. Re-run daemon with --migrate or see 'ipfs repo migrate --help'\n", cctx.ConfigRoot)
return errors.New("fs-repo requires migration")
}

// Read Migration section of IPFS config
configFileOpt, _ := req.Options[commands.ConfigFileOption].(string)
migrationCfg, err := migrations.ReadMigrationConfig(cctx.ConfigRoot, configFileOpt)
if err != nil {
return err
}

// Define function to create IPFS fetcher. Do not supply an
// already-constructed IPFS fetcher, because this may be expensive and
// not needed according to migration config. Instead, supply a function
// to construct the particular IPFS fetcher implementation used here,
// which is called only if an IPFS fetcher is needed.
newIpfsFetcher := func(distPath string) migrations.Fetcher {
return ipfsfetcher.NewIpfsFetcher(distPath, 0, &cctx.ConfigRoot, configFileOpt)
}

// Fetch migrations from current distribution, or location from environ
fetchDistPath := migrations.GetDistPathEnv(migrations.CurrentIpfsDist)

// Create fetchers according to migrationCfg.DownloadSources
fetcher, err = migrations.GetMigrationFetcher(migrationCfg.DownloadSources, fetchDistPath, newIpfsFetcher)
if err != nil {
return err
}
defer fetcher.Close()

if migrationCfg.Keep == "cache" {
cacheMigrations = true
} else if migrationCfg.Keep == "pin" {
pinMigrations = true
}

if cacheMigrations || pinMigrations {
// Create temp directory to store downloaded migration archives
migrations.DownloadDirectory, err = os.MkdirTemp("", "migrations")
if err != nil {
return err
}
// Defer cleanup of download directory so that it gets cleaned up
// if daemon returns early due to error
defer func() {
if migrations.DownloadDirectory != "" {
os.RemoveAll(migrations.DownloadDirectory)
}
}()
}

err = migrations.RunMigration(cctx.Context(), fetcher, fsrepo.RepoVersion, "", false)
// Use hybrid migration strategy that intelligently combines external and embedded migrations
err = migrations.RunHybridMigrations(cctx.Context(), version.RepoVersion, cctx.ConfigRoot, false)
if err != nil {
fmt.Println("The migrations of fs-repo failed:")
fmt.Println("Repository migration failed:")
fmt.Printf(" %s\n", err)
fmt.Println("If you think this is a bug, please file an issue and include this whole log output.")
fmt.Println(" https://github.com/ipfs/fs-repo-migrations")
fmt.Println(" https://github.com/ipfs/kubo")
return err
}

// Note: Migration caching/pinning functionality has been deprecated
// The hybrid migration system handles legacy migrations more efficiently

repo, err = fsrepo.Open(cctx.ConfigRoot)
if err != nil {
return err
Expand All @@ -379,6 +344,27 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
return err
}

// Validate autoconf setup - check for private network conflict
swarmKey, _ := repo.SwarmKey()
isPrivateNetwork := swarmKey != nil || pnet.ForcePrivateNetwork
if err := config.ValidateAutoConfWithRepo(cfg, isPrivateNetwork); err != nil {
return err
}

// Start background AutoConf updater if enabled
if cfg.AutoConf.Enabled.WithDefault(config.DefaultAutoConfEnabled) {
// Start autoconf client for background updates
client, err := config.GetAutoConfClient(cfg)
if err != nil {
log.Errorf("failed to create autoconf client: %v", err)
} else {
// Start primes cache and starts background updater
if _, err := client.Start(cctx.Context()); err != nil {
log.Errorf("failed to start autoconf updater: %v", err)
}
}
}

fmt.Printf("PeerID: %s\n", cfg.Identity.PeerID)

if !psSet {
Expand All @@ -402,8 +388,8 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
}

routingOption, _ := req.Options[routingOptionKwd].(string)
if routingOption == routingOptionDefaultKwd {
routingOption = cfg.Routing.Type.WithDefault(routingOptionAutoKwd)
if routingOption == routingOptionDefaultKwd || routingOption == "" {
routingOption = cfg.Routing.Type.WithDefault(config.DefaultRoutingType)
if routingOption == "" {
routingOption = routingOptionAutoKwd
}
Expand Down Expand Up @@ -433,6 +419,8 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
}
}

// Use config for routing construction

switch routingOption {
case routingOptionSupernodeKwd:
return errors.New("supernode routing was never fully implemented and has been removed")
Expand All @@ -448,6 +436,8 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
ncfg.Routing = libp2p.DHTServerOption
case routingOptionNoneKwd:
ncfg.Routing = libp2p.NilRouterOption
case routingOptionDelegatedKwd:
ncfg.Routing = libp2p.ConstructDelegatedOnlyRouting(cfg)
case routingOptionCustomKwd:
if cfg.Routing.AcceleratedDHTClient.WithDefault(config.DefaultAcceleratedDHTClient) {
return errors.New("Routing.AcceleratedDHTClient option is set even tho Routing.Type is custom, using custom .AcceleratedDHTClient needs to be set on DHT routers individually")
Expand Down Expand Up @@ -494,6 +484,15 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
cfg.Experimental.StrategicProviding = false
cfg.Provider.Enabled = config.False
}
if routingOption == routingOptionDelegatedKwd {
// Delegated routing is read-only mode - content providing must be disabled
if cfg.Provider.Enabled.WithDefault(config.DefaultProviderEnabled) {
log.Fatal("Routing.Type=delegated does not support content providing. Set Provider.Enabled=false in your config.")
}
if cfg.Reprovider.Interval.WithDefault(config.DefaultReproviderInterval) != 0 {
log.Fatal("Routing.Type=delegated does not support content providing. Set Reprovider.Interval='0' in your config.")
}
}

printLibp2pPorts(node)

Expand Down Expand Up @@ -525,6 +524,9 @@ take effect.
}
}()

// Clear any cached offline node and set the online daemon node
// This ensures HTTP RPC server uses the online node, not any cached offline node
cctx.ClearCachedNode()
cctx.ConstructNode = func() (*core.IpfsNode, error) {
return node, nil
}
Expand Down Expand Up @@ -578,9 +580,9 @@ take effect.
return err
}

// Add any files downloaded by migration.
if cacheMigrations || pinMigrations {
err = addMigrations(cctx.Context(), node, fetcher, pinMigrations)
// Add any files downloaded by external migrations (embedded migrations don't download files)
if externalMigrationFetcher != nil && (cacheMigrations || pinMigrations) {
err = addMigrations(cctx.Context(), node, externalMigrationFetcher, pinMigrations)
if err != nil {
fmt.Fprintln(os.Stderr, "Could not add migration to IPFS:", err)
}
Expand All @@ -589,10 +591,10 @@ take effect.
os.RemoveAll(migrations.DownloadDirectory)
migrations.DownloadDirectory = ""
}
if fetcher != nil {
if externalMigrationFetcher != nil {
// If there is an error closing the IpfsFetcher, then print error, but
// do not fail because of it.
err = fetcher.Close()
err = externalMigrationFetcher.Close()
if err != nil {
log.Errorf("error closing IPFS fetcher: %s", err)
}
Expand Down Expand Up @@ -884,6 +886,12 @@ func printLibp2pPorts(node *core.IpfsNode) {
return
}

if node.PeerHost == nil {
log.Error("PeerHost is nil - this should not happen and likely indicates an FX dependency injection issue or race condition")
fmt.Println("Swarm not properly initialized - node PeerHost is nil.")
return
}

ifaceAddrs, err := node.PeerHost.Network().InterfaceListenAddresses()
if err != nil {
log.Errorf("failed to read listening addresses: %s", err)
Expand Down Expand Up @@ -1065,6 +1073,10 @@ func serveTrustlessGatewayOverLibp2p(cctx *oldcmds.Context) (<-chan error, error
return nil, err
}

if node.PeerHost == nil {
return nil, fmt.Errorf("cannot create libp2p gateway: node PeerHost is nil (this should not happen and likely indicates an FX dependency injection issue or race condition)")
}

h := p2phttp.Host{
StreamHost: node.PeerHost,
}
Expand Down
17 changes: 17 additions & 0 deletions commands/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ func (c *Context) GetNode() (*core.IpfsNode, error) {
return c.node, err
}

// ClearCachedNode clears any cached node, forcing GetNode to construct a new one.
//
// This method is critical for mitigating racy FX dependency injection behavior
// that can occur during daemon startup. The daemon may create multiple IpfsNode
// instances during initialization - first an offline node during early init, then
// the proper online daemon node. Without clearing the cache, HTTP RPC handlers may
// end up using the first (offline) cached node instead of the intended online daemon node.
//
// This behavior was likely present forever in go-ipfs, but recent changes made it more
// prominent and forced us to proactively mitigate FX shortcomings. The daemon calls
// this method immediately before setting its ConstructNode function to ensure that
// subsequent GetNode() calls use the correct online daemon node rather than any
// stale cached offline node from initialization.
func (c *Context) ClearCachedNode() {
c.node = nil
}

// GetAPI returns CoreAPI instance backed by ipfs node.
// It may construct the node with the provided function.
func (c *Context) GetAPI() (coreiface.CoreAPI, error) {
Expand Down
Loading
Loading