Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: prototype of ipfs config support for auto
- tests need manual inspection / being more DRY / reusable for future
  migrations
- need to see if all CI tests pass
  • Loading branch information
lidel committed Jul 24, 2025
commit 51a49f98fbded76d20c59bc23b87e085ecf17f9a
160 changes: 160 additions & 0 deletions boxo/autoconfig/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# AutoConfig Library

This package provides a client library for fetching and caching IPFS autoconfig.json files. It's designed to be generic and self-contained for easy extraction to the boxo library later.

## Features

- **HTTP Client**: Configurable HTTP client with timeout, user-agent, and TLS options
- **Caching**: Intelligent caching with ETag/Last-Modified support and version rotation
- **Version Management**: Automatic cleanup of old cached versions
- **Path Safety**: Sanitized cache directory structure based on URL hostname
- **Error Handling**: Graceful fallback to cached versions when remote fetch fails

## Usage

### Basic Usage

```go
import "github.com/ipfs/kubo/boxo/autoconfig"

// Create a client with default options
client, err := autoconfig.NewClient()
if err != nil {
return err
}

// Fetch the latest config
config, err := client.GetLatest(ctx, "https://config.ipfs-mainnet.org/autoconfig.json")
if err != nil {
return err
}

// Use the config
fmt.Printf("Bootstrap peers: %v\n", config.Bootstrap)
```

### With Custom Options

```go
client, err := autoconfig.NewClient(
autoconfig.WithCacheDir("/path/to/cache"),
autoconfig.WithUserAgent("my-app/1.0"),
autoconfig.WithCacheSize(5),
autoconfig.WithTimeout(10*time.Second),
)
```

### Integration with Applications

This library is designed to be integrated into applications that need autoconfig functionality. The client is generic and does not depend on any specific application framework.

```go
func main() {
client, err := autoconfig.NewClient(
autoconfig.WithCacheDir("/app/data/autoconfig"),
autoconfig.WithUserAgent("myapp/1.2.3"),
autoconfig.WithTimeout(10*time.Second),
)
if err != nil {
panic(err)
}

config, err := client.GetLatest(context.Background(), "https://config.ipfs-mainnet.org/autoconfig.json")
if err != nil {
panic(err)
}

fmt.Printf("Bootstrap peers: %v\n", config.Bootstrap)
fmt.Printf("DNS resolvers: %v\n", config.DNSResolvers)
}
```

### Background Updates

For applications that need periodic config updates, use the background updater:

```go
func main() {
client, err := autoconfig.NewClient(
autoconfig.WithCacheDir("/app/data/autoconfig"),
autoconfig.WithUserAgent("myapp/1.2.3"),
)
if err != nil {
panic(err)
}

// Create background updater with custom callbacks
updater, err := autoconfig.NewBackgroundUpdater(client, "https://config.ipfs-mainnet.org/autoconfig.json",
autoconfig.WithUpdateInterval(6*time.Hour), // Check every 6 hours
autoconfig.WithOnVersionChange(func(oldVersion, newVersion int64, configURL string) {
fmt.Printf("New config version %d available (was %d) - consider restarting\n", newVersion, oldVersion)
}),
autoconfig.WithOnUpdateSuccess(func(resp *autoconfig.AutoConfigResponse) {
fmt.Printf("Updated config cache at %s\n", resp.FetchTime.Format(time.RFC3339))
}),
autoconfig.WithOnUpdateError(func(err error) {
fmt.Printf("Update failed: %v\n", err)
}),
)
if err != nil {
panic(err)
}

ctx := context.Background()
if err := updater.Start(ctx); err != nil {
panic(err)
}
defer updater.Stop()

// Your application logic here...
select {}
}
```

## Cache Structure

The cache is organized by hostname and version:

```
$CACHE_DIR/
autoconfig/
config.ipfs-mainnet.org/
2025071801.json
2025071802.json
.etag
.last-modified
```

## Configuration Options

### Client Options
- `WithCacheDir(dir)`: Set custom cache directory
- `WithHTTPClient(client)`: Use custom HTTP client
- `WithCacheSize(n)`: Set maximum cached versions (default: 3)
- `WithUserAgent(ua)`: Set HTTP user-agent
- `WithTimeout(duration)`: Set HTTP timeout (default: 5s)
- `WithTLSInsecureSkipVerify(bool)`: Skip TLS verification (for testing)

### Background Updater Options
- `WithUpdateInterval(duration)`: Set update check interval (default: 24h)
- `WithOnVersionChange(callback)`: Called when new config version is detected
- `WithOnUpdateSuccess(callback)`: Called on successful update for metadata persistence
- `WithOnUpdateError(callback)`: Called when update fails

## Error Handling

The client implements graceful fallback:
1. Try to fetch from remote URL
2. If remote fails, fall back to latest cached version
3. If no cache exists, return error with details

## Testing

Run tests with:
```bash
go test .
```

## Future Extraction

This package is designed to be extracted to `github.com/ipfs/boxo` with no changes needed. It has no application-specific dependencies.
4 changes: 4 additions & 0 deletions boxo/autoconfig/autoconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package autoconfig

// This file exists to maintain backwards compatibility during the transition.
// All Kubo-specific client functions have been moved to github.com/ipfs/kubo/config
26 changes: 22 additions & 4 deletions internal/autoconfig/client.go β†’ boxo/autoconfig/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func WithTimeout(timeout time.Duration) Option {
// WithTLSInsecureSkipVerify sets whether to skip TLS verification (for testing)
func WithTLSInsecureSkipVerify(skip bool) Option {
return func(c *Client) error {
if skip {
log.Warnf("TLS certificate verification is disabled - this should only be used for testing")
}
if c.httpClient.Transport == nil {
c.httpClient.Transport = http.DefaultTransport.(*http.Transport).Clone()
}
Expand Down Expand Up @@ -148,20 +151,35 @@ func (c *Client) getCacheDir(configURL string) (string, error) {

// readCachedMetadata reads cached ETag and Last-Modified values
func (c *Client) readCachedMetadata(cacheDir string) (etag, lastModified string) {
etagData, _ := os.ReadFile(filepath.Join(cacheDir, etagFile))
lastModData, _ := os.ReadFile(filepath.Join(cacheDir, lastModifiedFile))
// Sanitize cache directory path
cleanCacheDir := filepath.Clean(cacheDir)

etagData, err := os.ReadFile(filepath.Join(cleanCacheDir, etagFile))
if err != nil {
log.Debugf("failed to read cached etag: %v", err)
}

lastModData, err := os.ReadFile(filepath.Join(cleanCacheDir, lastModifiedFile))
if err != nil {
log.Debugf("failed to read cached last-modified: %v", err)
}

return strings.TrimSpace(string(etagData)), strings.TrimSpace(string(lastModData))
}

// writeCachedMetadata writes ETag and Last-Modified values to cache
func (c *Client) writeCachedMetadata(cacheDir, etag, lastModified string) error {
// Sanitize cache directory path
cleanCacheDir := filepath.Clean(cacheDir)
if etag != "" {
if err := os.WriteFile(filepath.Join(cacheDir, etagFile), []byte(etag), 0644); err != nil {
// Use owner-only permissions (0600) for security
if err := os.WriteFile(filepath.Join(cleanCacheDir, etagFile), []byte(etag), 0600); err != nil {
return fmt.Errorf("failed to write etag: %w", err)
}
}
if lastModified != "" {
if err := os.WriteFile(filepath.Join(cacheDir, lastModifiedFile), []byte(lastModified), 0644); err != nil {
// Use owner-only permissions (0600) for security
if err := os.WriteFile(filepath.Join(cleanCacheDir, lastModifiedFile), []byte(lastModified), 0600); err != nil {
return fmt.Errorf("failed to write last-modified: %w", err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/ipfs/kubo"
)

func TestNewClient(t *testing.T) {
Expand All @@ -33,7 +32,7 @@ func TestWithOptions(t *testing.T) {
client, err := NewClient(
WithCacheDir(tmpDir),
WithCacheSize(5),
WithUserAgent(ipfs.GetUserAgentVersion()),
WithUserAgent("kubo-autoconfig-test/1.0"),
WithTimeout(10*time.Second),
)
if err != nil {
Expand All @@ -56,17 +55,13 @@ func TestGetLatest(t *testing.T) {
testConfig := &AutoConfig{
AutoConfigVersion: 2025071802,
AutoConfigSchema: 2,
Bootstrap: []string{"/ip4/127.0.0.1/tcp/4001/p2p/QmTest"},
Bootstrap: []string{"/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf"},
DNSResolvers: map[string][]string{"eth.": {"https://example.com"}},
DelegatedRouters: map[string]DelegatedRouterConfig{
"for-nodes-with-dht": {
Providers: []string{"https://cid.contact"},
},
"mainnet-for-nodes-with-dht": {"https://cid.contact/routing/v1/providers"},
},
DelegatedPublishers: map[string]DelegatedPublisherConfig{
"for-ipns-publishers-with-http": {
IPNS: []string{"https://delegated-ipfs.dev"},
},
"mainnet-for-ipns-publishers-with-http": {"https://delegated-ipfs.dev/routing/v1/ipns"},
},
}

Expand All @@ -87,7 +82,7 @@ func TestGetLatest(t *testing.T) {

client, err := NewClient(
WithCacheDir(tmpDir),
WithUserAgent(ipfs.GetUserAgentVersion()),
WithUserAgent("kubo-autoconfig-test/1.0"),
)
if err != nil {
t.Fatalf("failed to create client: %v", err)
Expand All @@ -110,9 +105,25 @@ func TestGetLatest(t *testing.T) {
t.Fatalf("failed to get cache dir: %v", err)
}

cachedFile := filepath.Join(cacheDir, "2025071802.json")
if _, err := os.Stat(cachedFile); os.IsNotExist(err) {
t.Errorf("expected cache file %s to exist", cachedFile)
// List files in cache dir for debugging
files, err := os.ReadDir(cacheDir)
if err != nil {
t.Logf("failed to read cache dir %s: %v", cacheDir, err)
} else {
t.Logf("cache dir %s contains: %v", cacheDir, files)
}

// Check that some autoconfig JSON file exists (filename may vary based on timestamp)
foundCacheFile := false
for _, file := range files {
if strings.HasSuffix(file.Name(), ".json") && strings.Contains(file.Name(), "autoconfig") {
foundCacheFile = true
t.Logf("found cache file: %s", file.Name())
break
}
}
if !foundCacheFile {
t.Errorf("expected some autoconfig cache file to exist in %s, but none found", cacheDir)
}
}

Expand Down
41 changes: 41 additions & 0 deletions boxo/autoconfig/fallbacks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package autoconfig

// Fallback defaults matching Kubo 0.36
// These are used as last-resort fallback when autoconfig fetch fails and no cache exists
var (
// FallbackBootstrapPeers are the default bootstrap peers from Kubo 0.36
// Used as last-resort fallback when autoconfig fetch fails
FallbackBootstrapPeers = []string{
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
"/dnsaddr/va1.bootstrap.libp2p.io/p2p/12D3KooWKnDdG3iXw9eTFijk3EWSunZcFi54Zka4wmtqtt6rPxc8",
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip4/104.131.131.82/udp/4001/quic-v1/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
}

// FallbackDNSResolvers are the default DNS resolvers matching mainnet autoconfig
// Used as last-resort fallback when autoconfig fetch fails
// Only "eth." has explicit fallbacks - no "." (root domain) fallback is intentional
// to ensure users' OS DNS resolver is used by default, allowing browser clients
// to make their own DoH decisions based on privacy preferences
FallbackDNSResolvers = map[string][]string{
"eth.": {
"https://dns.eth.limo/dns-query",
"https://dns.eth.link/dns-query",
},
}

// FallbackDelegatedRouters are the default delegated routing endpoints from Kubo 0.36
// Used as last-resort fallback when autoconfig fetch fails
FallbackDelegatedRouters = []string{
"https://cid.contact/routing/v1/providers",
}

// FallbackDelegatedPublishers are the default delegated IPNS publishers matching mainnet autoconfig
// Used as last-resort fallback when autoconfig fetch fails
FallbackDelegatedPublishers = []string{
"https://delegated-ipfs.dev/routing/v1/ipns",
}
)
Loading