mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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
This commit is contained in:
parent
73ab037d1d
commit
91dd98c3de
@ -56,6 +56,14 @@ func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.Unix
|
||||
req.Option("raw-leaves", options.RawLeaves)
|
||||
}
|
||||
|
||||
if options.FastProvideRootSet {
|
||||
req.Option("fast-provide-root", options.FastProvideRoot)
|
||||
}
|
||||
|
||||
if options.FastProvideWaitSet {
|
||||
req.Option("fast-provide-wait", options.FastProvideWait)
|
||||
}
|
||||
|
||||
switch options.Layout {
|
||||
case caopts.BalancedLayout:
|
||||
// noop, default
|
||||
|
||||
@ -52,6 +52,11 @@ type UnixfsAddSettings struct {
|
||||
PreserveMtime bool
|
||||
Mode os.FileMode
|
||||
Mtime time.Time
|
||||
|
||||
FastProvideRoot bool
|
||||
FastProvideRootSet bool
|
||||
FastProvideWait bool
|
||||
FastProvideWaitSet bool
|
||||
}
|
||||
|
||||
type UnixfsLsSettings struct {
|
||||
@ -97,6 +102,11 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
|
||||
PreserveMtime: false,
|
||||
Mode: 0,
|
||||
Mtime: time.Time{},
|
||||
|
||||
FastProvideRoot: false,
|
||||
FastProvideRootSet: false,
|
||||
FastProvideWait: false,
|
||||
FastProvideWaitSet: false,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
@ -396,3 +406,23 @@ func (unixfsOpts) Mtime(seconds int64, nsecs uint32) UnixfsAddOption {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// FastProvideRoot sets whether to immediately provide root CID to DHT for faster discovery.
|
||||
// If not set, server uses Import.FastProvideRoot config value (default: true).
|
||||
func (unixfsOpts) FastProvideRoot(enable bool) UnixfsAddOption {
|
||||
return func(settings *UnixfsAddSettings) error {
|
||||
settings.FastProvideRoot = enable
|
||||
settings.FastProvideRootSet = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// FastProvideWait sets whether to block until fast provide completes.
|
||||
// If not set, server uses Import.FastProvideWait config value (default: false).
|
||||
func (unixfsOpts) FastProvideWait(enable bool) UnixfsAddOption {
|
||||
return func(settings *UnixfsAddSettings) error {
|
||||
settings.FastProvideWait = enable
|
||||
settings.FastProvideWaitSet = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user