Skip to content

Commit a379c66

Browse files
committed
Merge 'origin/master' into http-retr
2 parents 42d6057 + 6b55e64 commit a379c66

File tree

30 files changed

+1029
-184
lines changed

30 files changed

+1029
-184
lines changed

config/import.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package config
22

3+
import (
4+
"github.com/ipfs/boxo/ipld/unixfs/importer/helpers"
5+
"github.com/ipfs/boxo/ipld/unixfs/io"
6+
)
7+
38
const (
49
DefaultCidVersion = 0
510
DefaultUnixFSRawLeaves = false
611
DefaultUnixFSChunker = "size-262144"
712
DefaultHashFunction = "sha2-256"
813

14+
DefaultUnixFSHAMTDirectorySizeThreshold = "256KiB" // https://github.com/ipfs/boxo/blob/6c5a07602aed248acc86598f30ab61923a54a83e/ipld/unixfs/io/directory.go#L26
15+
916
// DefaultBatchMaxNodes controls the maximum number of nodes in a
1017
// write-batch. The total size of the batch is limited by
1118
// BatchMaxnodes and BatchMaxSize.
@@ -14,15 +21,26 @@ const (
1421
// write-batch. The total size of the batch is limited by
1522
// BatchMaxnodes and BatchMaxSize.
1623
DefaultBatchMaxSize = 100 << 20 // 20MiB
24+
25+
)
26+
27+
var (
28+
DefaultUnixFSFileMaxLinks = int64(helpers.DefaultLinksPerBlock)
29+
DefaultUnixFSDirectoryMaxLinks = int64(0)
30+
DefaultUnixFSHAMTDirectoryMaxFanout = int64(io.DefaultShardWidth)
1731
)
1832

1933
// Import configures the default options for ingesting data. This affects commands
2034
// that ingest data, such as 'ipfs add', 'ipfs dag put, 'ipfs block put', 'ipfs files write'.
2135
type Import struct {
22-
CidVersion OptionalInteger
23-
UnixFSRawLeaves Flag
24-
UnixFSChunker OptionalString
25-
HashFunction OptionalString
26-
BatchMaxNodes OptionalInteger
27-
BatchMaxSize OptionalInteger
36+
CidVersion OptionalInteger
37+
UnixFSRawLeaves Flag
38+
UnixFSChunker OptionalString
39+
HashFunction OptionalString
40+
UnixFSFileMaxLinks OptionalInteger
41+
UnixFSDirectoryMaxLinks OptionalInteger
42+
UnixFSHAMTDirectoryMaxFanout OptionalInteger
43+
UnixFSHAMTDirectorySizeThreshold OptionalString
44+
BatchMaxNodes OptionalInteger
45+
BatchMaxSize OptionalInteger
2846
}

config/internal.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33
type Internal struct {
44
// All marked as omitempty since we are expecting to make changes to all subcomponents of Internal
55
Bitswap *InternalBitswap `json:",omitempty"`
6-
UnixFSShardingSizeThreshold *OptionalString `json:",omitempty"`
6+
UnixFSShardingSizeThreshold *OptionalString `json:",omitempty"` // moved to Import.UnixFSHAMTDirectorySizeThreshold
77
Libp2pForceReachability *OptionalString `json:",omitempty"`
88
BackupBootstrapInterval *OptionalDuration `json:",omitempty"`
99
}
@@ -14,5 +14,6 @@ type InternalBitswap struct {
1414
EngineTaskWorkerCount OptionalInteger
1515
MaxOutstandingBytesPerPeer OptionalInteger
1616
ProviderSearchDelay OptionalDuration
17+
ProviderSearchMaxResults OptionalInteger
1718
WantHaveReplaceSize OptionalInteger
1819
}

config/profile.go

+24-4
Original file line numberDiff line numberDiff line change
@@ -266,24 +266,44 @@ fetching may be degraded.
266266
},
267267
},
268268
"legacy-cid-v0": {
269-
Description: `Makes UnixFS import produce legacy CIDv0 with no raw leaves, sha2-256 and 256 KiB chunks.`,
270-
269+
Description: `Makes UnixFS import produce legacy CIDv0 with no raw leaves, sha2-256 and 256 KiB chunks. This is likely the least optimal preset, use only if legacy behavior is required.`,
271270
Transform: func(c *Config) error {
272271
c.Import.CidVersion = *NewOptionalInteger(0)
273272
c.Import.UnixFSRawLeaves = False
274273
c.Import.UnixFSChunker = *NewOptionalString("size-262144")
275274
c.Import.HashFunction = *NewOptionalString("sha2-256")
275+
c.Import.UnixFSFileMaxLinks = *NewOptionalInteger(174)
276+
c.Import.UnixFSDirectoryMaxLinks = *NewOptionalInteger(0)
277+
c.Import.UnixFSHAMTDirectoryMaxFanout = *NewOptionalInteger(256)
278+
c.Import.UnixFSHAMTDirectorySizeThreshold = *NewOptionalString("256KiB")
276279
return nil
277280
},
278281
},
279282
"test-cid-v1": {
280-
Description: `Makes UnixFS import produce modern CIDv1 with raw leaves, sha2-256 and 1 MiB chunks.`,
281-
283+
Description: `Makes UnixFS import produce CIDv1 with raw leaves, sha2-256 and 1 MiB chunks (max 174 links per file, 256 per HAMT node, switch dir to HAMT above 256KiB).`,
282284
Transform: func(c *Config) error {
283285
c.Import.CidVersion = *NewOptionalInteger(1)
284286
c.Import.UnixFSRawLeaves = True
285287
c.Import.UnixFSChunker = *NewOptionalString("size-1048576")
286288
c.Import.HashFunction = *NewOptionalString("sha2-256")
289+
c.Import.UnixFSFileMaxLinks = *NewOptionalInteger(174)
290+
c.Import.UnixFSDirectoryMaxLinks = *NewOptionalInteger(0)
291+
c.Import.UnixFSHAMTDirectoryMaxFanout = *NewOptionalInteger(256)
292+
c.Import.UnixFSHAMTDirectorySizeThreshold = *NewOptionalString("256KiB")
293+
return nil
294+
},
295+
},
296+
"test-cid-v1-wide": {
297+
Description: `Makes UnixFS import produce CIDv1 with raw leaves, sha2-256 and 1MiB chunks and wider file DAGs (max 1024 links per every node type, switch dir to HAMT above 1MiB).`,
298+
Transform: func(c *Config) error {
299+
c.Import.CidVersion = *NewOptionalInteger(1)
300+
c.Import.UnixFSRawLeaves = True
301+
c.Import.UnixFSChunker = *NewOptionalString("size-1048576") // 1MiB
302+
c.Import.HashFunction = *NewOptionalString("sha2-256")
303+
c.Import.UnixFSFileMaxLinks = *NewOptionalInteger(1024)
304+
c.Import.UnixFSDirectoryMaxLinks = *NewOptionalInteger(0) // no limit here, use size-based Import.UnixFSHAMTDirectorySizeThreshold instead
305+
c.Import.UnixFSHAMTDirectoryMaxFanout = *NewOptionalInteger(1024)
306+
c.Import.UnixFSHAMTDirectorySizeThreshold = *NewOptionalString("1MiB") // 1MiB
287307
return nil
288308
},
289309
},

core/commands/add.go

+60-21
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,26 @@ type AddEvent struct {
3737
}
3838

3939
const (
40-
quietOptionName = "quiet"
41-
quieterOptionName = "quieter"
42-
silentOptionName = "silent"
43-
progressOptionName = "progress"
44-
trickleOptionName = "trickle"
45-
wrapOptionName = "wrap-with-directory"
46-
onlyHashOptionName = "only-hash"
47-
chunkerOptionName = "chunker"
48-
pinOptionName = "pin"
49-
rawLeavesOptionName = "raw-leaves"
50-
noCopyOptionName = "nocopy"
51-
fstoreCacheOptionName = "fscache"
52-
cidVersionOptionName = "cid-version"
53-
hashOptionName = "hash"
54-
inlineOptionName = "inline"
55-
inlineLimitOptionName = "inline-limit"
56-
toFilesOptionName = "to-files"
40+
quietOptionName = "quiet"
41+
quieterOptionName = "quieter"
42+
silentOptionName = "silent"
43+
progressOptionName = "progress"
44+
trickleOptionName = "trickle"
45+
wrapOptionName = "wrap-with-directory"
46+
onlyHashOptionName = "only-hash"
47+
chunkerOptionName = "chunker"
48+
pinOptionName = "pin"
49+
rawLeavesOptionName = "raw-leaves"
50+
maxFileLinksOptionName = "max-file-links"
51+
maxDirectoryLinksOptionName = "max-directory-links"
52+
maxHAMTFanoutOptionName = "max-hamt-fanout"
53+
noCopyOptionName = "nocopy"
54+
fstoreCacheOptionName = "fscache"
55+
cidVersionOptionName = "cid-version"
56+
hashOptionName = "hash"
57+
inlineOptionName = "inline"
58+
inlineLimitOptionName = "inline-limit"
59+
toFilesOptionName = "to-files"
5760

5861
preserveModeOptionName = "preserve-mode"
5962
preserveMtimeOptionName = "preserve-mtime"
@@ -143,6 +146,9 @@ new flags may be added in the future. It is not guaranteed for the implicit
143146
defaults of 'ipfs add' to remain the same in future Kubo releases, or for other
144147
IPFS software to use the same import parameters as Kubo.
145148
149+
Use Import.* configuration options to override global implicit defaults:
150+
https://github.com/ipfs/kubo/blob/master/docs/config.md#import
151+
146152
If you need to back up or transport content-addressed data using a non-IPFS
147153
medium, CID can be preserved with CAR files.
148154
See 'dag export' and 'dag import' for more information.
@@ -166,12 +172,15 @@ See 'dag export' and 'dag import' for more information.
166172
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
167173
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
168174
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
169-
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash"),
170-
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes."),
175+
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash. Default: Import.UnixFSChunker"),
176+
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. Default: Import.UnixFSRawLeaves"),
177+
cmds.IntOption(maxFileLinksOptionName, "Limit the maximum number of links in UnixFS file nodes to this value. (experimental) Default: Import.UnixFSFileMaxLinks"),
178+
cmds.IntOption(maxDirectoryLinksOptionName, "Limit the maximum number of links in UnixFS basic directory nodes to this value. Default: Import.UnixFSDirectoryMaxLinks. WARNING: experimental, Import.UnixFSHAMTThreshold is a safer alternative."),
179+
cmds.IntOption(maxHAMTFanoutOptionName, "Limit the maximum number of links of a UnixFS HAMT directory node to this (power of 2, multiple of 8). Default: Import.UnixFSHAMTDirectoryMaxFanout WARNING: experimental, see Import.UnixFSHAMTDirectorySizeThreshold as well."),
171180
cmds.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
172181
cmds.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
173-
cmds.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. Passing version 1 will cause the raw-leaves option to default to true."),
174-
cmds.StringOption(hashOptionName, "Hash function to use. Implies CIDv1 if not sha2-256. (experimental)"),
182+
cmds.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. Passing version 1 will cause the raw-leaves option to default to true. Default: Import.CidVersion"),
183+
cmds.StringOption(hashOptionName, "Hash function to use. Implies CIDv1 if not sha2-256. Default: Import.HashFunction"),
175184
cmds.BoolOption(inlineOptionName, "Inline small blocks into CIDs. (experimental)"),
176185
cmds.IntOption(inlineLimitOptionName, "Maximum block size to inline. (experimental)").WithDefault(32),
177186
cmds.BoolOption(pinOptionName, "Pin locally to protect added files from garbage collection.").WithDefault(true),
@@ -222,6 +231,9 @@ See 'dag export' and 'dag import' for more information.
222231
chunker, _ := req.Options[chunkerOptionName].(string)
223232
dopin, _ := req.Options[pinOptionName].(bool)
224233
rawblks, rbset := req.Options[rawLeavesOptionName].(bool)
234+
maxFileLinks, maxFileLinksSet := req.Options[maxFileLinksOptionName].(int)
235+
maxDirectoryLinks, maxDirectoryLinksSet := req.Options[maxDirectoryLinksOptionName].(int)
236+
maxHAMTFanout, maxHAMTFanoutSet := req.Options[maxHAMTFanoutOptionName].(int)
225237
nocopy, _ := req.Options[noCopyOptionName].(bool)
226238
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
227239
cidVer, cidVerSet := req.Options[cidVersionOptionName].(int)
@@ -253,6 +265,21 @@ See 'dag export' and 'dag import' for more information.
253265
rawblks = cfg.Import.UnixFSRawLeaves.WithDefault(config.DefaultUnixFSRawLeaves)
254266
}
255267

268+
if !maxFileLinksSet && !cfg.Import.UnixFSFileMaxLinks.IsDefault() {
269+
maxFileLinksSet = true
270+
maxFileLinks = int(cfg.Import.UnixFSFileMaxLinks.WithDefault(config.DefaultUnixFSFileMaxLinks))
271+
}
272+
273+
if !maxDirectoryLinksSet && !cfg.Import.UnixFSDirectoryMaxLinks.IsDefault() {
274+
maxDirectoryLinksSet = true
275+
maxDirectoryLinks = int(cfg.Import.UnixFSDirectoryMaxLinks.WithDefault(config.DefaultUnixFSDirectoryMaxLinks))
276+
}
277+
278+
if !maxHAMTFanoutSet && !cfg.Import.UnixFSHAMTDirectoryMaxFanout.IsDefault() {
279+
maxHAMTFanoutSet = true
280+
maxHAMTFanout = int(cfg.Import.UnixFSHAMTDirectoryMaxFanout.WithDefault(config.DefaultUnixFSHAMTDirectoryMaxFanout))
281+
}
282+
256283
// Storing optional mode or mtime (UnixFS 1.5) requires root block
257284
// to always be 'dag-pb' and not 'raw'. Below adjusts raw-leaves setting, if possible.
258285
if preserveMode || preserveMtime || mode != 0 || mtime != 0 {
@@ -329,6 +356,18 @@ See 'dag export' and 'dag import' for more information.
329356
opts = append(opts, options.Unixfs.RawLeaves(rawblks))
330357
}
331358

359+
if maxFileLinksSet {
360+
opts = append(opts, options.Unixfs.MaxFileLinks(maxFileLinks))
361+
}
362+
363+
if maxDirectoryLinksSet {
364+
opts = append(opts, options.Unixfs.MaxDirectoryLinks(maxDirectoryLinks))
365+
}
366+
367+
if maxHAMTFanoutSet {
368+
opts = append(opts, options.Unixfs.MaxHAMTFanout(maxHAMTFanout))
369+
}
370+
332371
if trickle {
333372
opts = append(opts, options.Unixfs.Layout(options.TrickleLayout))
334373
}

core/coreapi/unixfs.go

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
5050
attribute.Int("inlinelimit", settings.InlineLimit),
5151
attribute.Bool("rawleaves", settings.RawLeaves),
5252
attribute.Bool("rawleavesset", settings.RawLeavesSet),
53+
attribute.Int("maxfilelinks", settings.MaxFileLinks),
54+
attribute.Bool("maxfilelinksset", settings.MaxFileLinksSet),
55+
attribute.Int("maxdirectorylinks", settings.MaxDirectoryLinks),
56+
attribute.Bool("maxdirectorylinksset", settings.MaxDirectoryLinksSet),
57+
attribute.Int("maxhamtfanout", settings.MaxHAMTFanout),
58+
attribute.Bool("maxhamtfanoutset", settings.MaxHAMTFanoutSet),
5359
attribute.Int("layout", int(settings.Layout)),
5460
attribute.Bool("pin", settings.Pin),
5561
attribute.Bool("onlyhash", settings.OnlyHash),
@@ -132,6 +138,16 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
132138
fileAdder.Pin = settings.Pin && !settings.OnlyHash
133139
fileAdder.Silent = settings.Silent
134140
fileAdder.RawLeaves = settings.RawLeaves
141+
if settings.MaxFileLinksSet {
142+
fileAdder.MaxLinks = settings.MaxFileLinks
143+
}
144+
if settings.MaxDirectoryLinksSet {
145+
fileAdder.MaxDirectoryLinks = settings.MaxDirectoryLinks
146+
}
147+
148+
if settings.MaxHAMTFanoutSet {
149+
fileAdder.MaxHAMTFanout = settings.MaxHAMTFanout
150+
}
135151
fileAdder.NoCopy = settings.NoCopy
136152
fileAdder.CidBuilder = prefix
137153
fileAdder.PreserveMode = settings.PreserveMode

core/corehttp/webui.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package corehttp
22

33
// WebUI version confirmed to work with this Kubo version
4-
const WebUIPath = "/ipfs/bafybeibpaa5kqrj4gkemiswbwndjqiryl65cks64ypwtyerxixu56gnvvm" // v4.6.0
4+
const WebUIPath = "/ipfs/bafybeibfd5kbebqqruouji6ct5qku3tay273g7mt24mmrfzrsfeewaal5y" // v4.7.0
55

66
// WebUIPaths is a list of all past webUI paths.
77
var WebUIPaths = []string{
88
WebUIPath,
9+
"/ipfs/bafybeibpaa5kqrj4gkemiswbwndjqiryl65cks64ypwtyerxixu56gnvvm", // v4.6.0
910
"/ipfs/bafybeiata4qg7xjtwgor6r5dw63jjxyouenyromrrb4lrewxrlvav7gzgi", // v4.5.0
1011
"/ipfs/bafybeigp3zm7cqoiciqk5anlheenqjsgovp7j7zq6hah4nu6iugdgb4nby", // v4.4.2
1112
"/ipfs/bafybeiatztgdllxnp5p6zu7bdwhjmozsmd7jprff4bdjqjljxtylitvss4", // v4.4.1

core/coreiface/options/unixfs.go

+51-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"time"
88

99
dag "github.com/ipfs/boxo/ipld/merkledag"
10+
"github.com/ipfs/boxo/ipld/unixfs/importer/helpers"
11+
"github.com/ipfs/boxo/ipld/unixfs/io"
1012
cid "github.com/ipfs/go-cid"
1113
mh "github.com/multiformats/go-multihash"
1214
)
@@ -22,10 +24,16 @@ type UnixfsAddSettings struct {
2224
CidVersion int
2325
MhType uint64
2426

25-
Inline bool
26-
InlineLimit int
27-
RawLeaves bool
28-
RawLeavesSet bool
27+
Inline bool
28+
InlineLimit int
29+
RawLeaves bool
30+
RawLeavesSet bool
31+
MaxFileLinks int
32+
MaxFileLinksSet bool
33+
MaxDirectoryLinks int
34+
MaxDirectoryLinksSet bool
35+
MaxHAMTFanout int
36+
MaxHAMTFanoutSet bool
2937

3038
Chunker string
3139
Layout Layout
@@ -60,10 +68,16 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
6068
CidVersion: -1,
6169
MhType: mh.SHA2_256,
6270

63-
Inline: false,
64-
InlineLimit: 32,
65-
RawLeaves: false,
66-
RawLeavesSet: false,
71+
Inline: false,
72+
InlineLimit: 32,
73+
RawLeaves: false,
74+
RawLeavesSet: false,
75+
MaxFileLinks: helpers.DefaultLinksPerBlock,
76+
MaxFileLinksSet: false,
77+
MaxDirectoryLinks: 0,
78+
MaxDirectoryLinksSet: false,
79+
MaxHAMTFanout: io.DefaultShardWidth,
80+
MaxHAMTFanoutSet: false,
6781

6882
Chunker: "size-262144",
6983
Layout: BalancedLayout,
@@ -190,6 +204,35 @@ func (unixfsOpts) RawLeaves(enable bool) UnixfsAddOption {
190204
}
191205
}
192206

207+
// MaxFileLinks specifies the maximum number of children for UnixFS file
208+
// nodes.
209+
func (unixfsOpts) MaxFileLinks(n int) UnixfsAddOption {
210+
return func(settings *UnixfsAddSettings) error {
211+
settings.MaxFileLinks = n
212+
settings.MaxFileLinksSet = true
213+
return nil
214+
}
215+
}
216+
217+
// MaxDirectoryLinks specifies the maximum number of children for UnixFS basic
218+
// directory nodes.
219+
func (unixfsOpts) MaxDirectoryLinks(n int) UnixfsAddOption {
220+
return func(settings *UnixfsAddSettings) error {
221+
settings.MaxDirectoryLinks = n
222+
settings.MaxDirectoryLinksSet = true
223+
return nil
224+
}
225+
}
226+
227+
// MaxHAMTFanout specifies the maximum width of the HAMT directory shards.
228+
func (unixfsOpts) MaxHAMTFanout(n int) UnixfsAddOption {
229+
return func(settings *UnixfsAddSettings) error {
230+
settings.MaxHAMTFanout = n
231+
settings.MaxHAMTFanoutSet = true
232+
return nil
233+
}
234+
}
235+
193236
// Inline tells the adder to inline small blocks into CIDs
194237
func (unixfsOpts) Inline(enable bool) UnixfsAddOption {
195238
return func(settings *UnixfsAddSettings) error {

0 commit comments

Comments
 (0)