Skip to content

Commit 91dd98c

Browse files
committed
feat(rpc): add fast-provide-root and fast-provide-wait to Add
add FastProvideRoot and FastProvideWait options to UnixfsAddSettings, allowing RPC clients to control immediate DHT providing of root CIDs for faster content discovery these options default to server config (Import.FastProvideRoot and Import.FastProvideWait) when not explicitly set by the client
1 parent 73ab037 commit 91dd98c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

client/rpc/unixfs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.Unix
5656
req.Option("raw-leaves", options.RawLeaves)
5757
}
5858

59+
if options.FastProvideRootSet {
60+
req.Option("fast-provide-root", options.FastProvideRoot)
61+
}
62+
63+
if options.FastProvideWaitSet {
64+
req.Option("fast-provide-wait", options.FastProvideWait)
65+
}
66+
5967
switch options.Layout {
6068
case caopts.BalancedLayout:
6169
// noop, default

core/coreiface/options/unixfs.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ type UnixfsAddSettings struct {
5252
PreserveMtime bool
5353
Mode os.FileMode
5454
Mtime time.Time
55+
56+
FastProvideRoot bool
57+
FastProvideRootSet bool
58+
FastProvideWait bool
59+
FastProvideWaitSet bool
5560
}
5661

5762
type UnixfsLsSettings struct {
@@ -97,6 +102,11 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
97102
PreserveMtime: false,
98103
Mode: 0,
99104
Mtime: time.Time{},
105+
106+
FastProvideRoot: false,
107+
FastProvideRootSet: false,
108+
FastProvideWait: false,
109+
FastProvideWaitSet: false,
100110
}
101111

102112
for _, opt := range opts {
@@ -396,3 +406,23 @@ func (unixfsOpts) Mtime(seconds int64, nsecs uint32) UnixfsAddOption {
396406
return nil
397407
}
398408
}
409+
410+
// FastProvideRoot sets whether to immediately provide root CID to DHT for faster discovery.
411+
// If not set, server uses Import.FastProvideRoot config value (default: true).
412+
func (unixfsOpts) FastProvideRoot(enable bool) UnixfsAddOption {
413+
return func(settings *UnixfsAddSettings) error {
414+
settings.FastProvideRoot = enable
415+
settings.FastProvideRootSet = true
416+
return nil
417+
}
418+
}
419+
420+
// FastProvideWait sets whether to block until fast provide completes.
421+
// If not set, server uses Import.FastProvideWait config value (default: false).
422+
func (unixfsOpts) FastProvideWait(enable bool) UnixfsAddOption {
423+
return func(settings *UnixfsAddSettings) error {
424+
settings.FastProvideWait = enable
425+
settings.FastProvideWaitSet = true
426+
return nil
427+
}
428+
}

0 commit comments

Comments
 (0)