kubo/core/commands
Guillaume Michel d56fe3a026
Some checks are pending
CodeQL / codeql (push) Waiting to run
Docker Check / lint (push) Waiting to run
Docker Check / build (push) Waiting to run
Gateway Conformance / gateway-conformance (push) Waiting to run
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Waiting to run
Go Build / go-build (push) Waiting to run
Go Check / go-check (push) Waiting to run
Go Lint / go-lint (push) Waiting to run
Go Test / go-test (push) Waiting to run
Interop / interop-prep (push) Waiting to run
Interop / helia-interop (push) Blocked by required conditions
Interop / ipfs-webui (push) Blocked by required conditions
Sharness / sharness-test (push) Waiting to run
Spell Check / spellcheck (push) Waiting to run
feat(cli/rpc/add): fast provide of root CID (#11046)
* feat: fast provide
* Check error from provideRoot
* do not provide if nil router
* fix(commands): prevent panic from typed nil DHTClient interface

Fixes panic when ipfsNode.DHTClient is a non-nil interface containing a
nil pointer value (typed nil). This happened when Routing.Type=delegated
or when using HTTP-only routing without DHT.

The panic occurred because:
- Go interfaces can be non-nil while containing nil pointer values
- Simple `if DHTClient == nil` checks pass, but calling methods panics
- Example: `(*ddht.DHT)(nil)` stored in interface passes nil check

Solution:
- Add HasActiveDHTClient() method to check both interface and concrete value
- Update all 7 call sites to use proper check before DHT operations
- Rename provideRoot → provideCIDSync for clarity
- Add structured logging with "fast-provide" prefix for easier filtering
- Add tests covering nil cases and valid DHT configurations

Fixes: https://github.com/ipfs/kubo/pull/11046#issuecomment-3525313349

* feat(add): split fast-provide into two flags for async/sync control

Renames --fast-provide to --fast-provide-root and adds --fast-provide-wait
to give users control over synchronous vs asynchronous providing behavior.

Changes:
- --fast-provide-root (default: true): enables immediate root CID providing
- --fast-provide-wait (default: false): controls whether to block until complete
- Default behavior: async provide (fast, non-blocking)
- Opt-in: --fast-provide-wait for guaranteed discoverability (slower, blocking)
- Can disable with --fast-provide-root=false to rely on background reproviding

Implementation:
- Async mode: launches goroutine with detached context for fire-and-forget
  - Added 10 second timeout to prevent hanging on network issues
  - Timeout aligns with other kubo operations (ping, DNS resolve, p2p)
  - Sufficient for DHT with sweep provider or accelerated client
- Sync mode: blocks on provideCIDSync until completion (uses req.Context)
- Improved structured logging with "fast-provide-root:" prefix
  - Removed redundant "root CID" from messages (already in prefix)
  - Clear async/sync distinction in log messages
- Added FAST PROVIDE OPTIMIZATION section to ipfs add --help explaining:
  - The problem: background queue takes time, content not immediately discoverable
  - The solution: extra immediate announcement of just the root CID
  - The benefit: peers can find content right away while queue handles rest
  - Usage: async by default, --fast-provide-wait for guaranteed completion

Changelog:
- Added highlight section for fast root CID providing feature
- Updated TOC and overview
- Included usage examples with clear comments explaining each mode
- Emphasized this is extra announcement independent of background queue

The feature works best with sweep provider and accelerated DHT client
where provide operations are significantly faster.

* fix(add): respect Provide config in fast-provide-root

fast-provide-root should honor the same config settings as the regular
provide system:
- skip when Provide.Enabled is false
- skip when Provide.DHT.Interval is 0
- respect Provide.Strategy (all/pinned/roots/mfs/combinations)

This ensures fast-provide only runs when appropriate based on user
configuration and the nature of the content being added (pinned vs
unpinned, added to MFS or not).

* Update core/commands/add.go

---------

Co-authored-by: gammazero <11790789+gammazero@users.noreply.github.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
2025-11-14 11:08:29 -08:00
..
cmdenv chore: use go-log/v2 (#10801) 2025-05-19 13:04:05 -07:00
cmdutils feat: limit pin names to 255 bytes (#10981) 2025-09-25 23:54:04 +02:00
dag Replace use of go-car v1 with go-car/v2 (#10845) 2025-07-08 18:40:20 +02:00
e Fix typo in an error.go comment: "is adds" -> "adds". 2018-01-17 15:25:54 -08:00
keyencode chore: bump go-libp2p v0.22.0 & go1.18&go1.19 2022-09-09 17:09:38 +02:00
name feat(config): AutoConf with "auto" placeholders (#10883) 2025-08-20 05:59:11 +02:00
object core/commands!: remove deprecated object APIs (#10375) 2024-03-22 09:32:30 +01:00
pin feat: limit pin names to 255 bytes (#10981) 2025-09-25 23:54:04 +02:00
active.go refactor: use slices.Sort where appropriate (#10858) 2025-07-08 18:43:23 +02:00
add.go feat(cli/rpc/add): fast provide of root CID (#11046) 2025-11-14 11:08:29 -08:00
bitswap.go fix(rpc): restore and reprecate bitswap reprovide (#10699) 2025-02-10 16:12:53 +01:00
block.go config: introduce Import section (#10421) 2024-05-14 14:17:04 +00:00
bootstrap.go feat(config): AutoConf with "auto" placeholders (#10883) 2025-08-20 05:59:11 +02:00
cat.go chore: use errors.New to replace fmt.Errorf with no parameters (#10617) 2024-12-10 13:50:35 -08:00
cid_test.go Nonfunctional (#10753) 2025-03-11 14:04:16 -07:00
cid.go feat(ci): reusable spellcheck from unified CI (#10873) 2025-08-14 00:35:35 +00:00
commands_test.go feat(config): AutoConf with "auto" placeholders (#10883) 2025-08-20 05:59:11 +02:00
commands.go fix(cmd): exit 1 on error (#10903) 2025-08-08 17:25:05 -07:00
completion.go refactor: use slices.Sort where appropriate (#10858) 2025-07-08 18:43:23 +02:00
config_test.go test: TestEditorParsing 2025-07-08 18:43:47 +02:00
config.go feat(config): AutoConf with "auto" placeholders (#10883) 2025-08-20 05:59:11 +02:00
dht_test.go refactor: namesys cleanup, gateway /ipns/ ttl (#10115) 2023-10-18 10:23:50 +02:00
dht.go feat(cli/rpc/add): fast provide of root CID (#11046) 2025-11-14 11:08:29 -08:00
diag.go feat: add an "ipfs diag profile" command 2021-07-21 14:51:47 -07:00
external.go style: gofumpt and godot [skip changelog] (#10081) 2023-08-17 14:02:08 +02:00
extra.go refactor: get rid of cmdDetails awkwardness 2020-08-04 18:28:40 -04:00
files_test.go fix(mfs): basic UnixFS sanity checks in files cp (#10701) 2025-03-05 20:40:33 +01:00
files.go fix(mfs): add soft limit for --flush=false (#10985) 2025-09-26 01:25:23 +02:00
filestore.go Ivan386/filestore fix (#7474) 2025-06-04 14:04:20 -07:00
get_test.go cmdkit -> cmds 2019-05-10 23:00:20 -07:00
get.go feat: Support storing UnixFS 1.5 Mode and ModTime (#10478) 2024-08-21 02:02:46 +02:00
helptext_test.go gx: unrewrite 2019-03-05 18:33:56 +01:00
id.go fix(cmds): cleanup unicode identify strings (#9465) 2025-09-19 04:46:38 +02:00
keystore.go chore: use errors.New to replace fmt.Errorf with no parameters (#10617) 2024-12-10 13:50:35 -08:00
log.go feat: add query functionality to log level command (#10885) 2025-08-11 12:43:48 -07:00
ls.go refactor: use slices.Sort where appropriate (#10858) 2025-07-08 18:43:23 +02:00
mount_nofuse.go refactor(ci): optimize build workflows (#10973) 2025-09-19 14:44:38 +02:00
mount_unix.go refactor(ci): optimize build workflows (#10973) 2025-09-19 14:44:38 +02:00
mount_windows.go cmdkit -> cmds 2019-05-10 23:00:20 -07:00
multibase.go ci: add stylecheck to golangci-lint (#9334) 2022-10-06 10:18:40 -04:00
p2p.go chore: use errors.New to replace fmt.Errorf with no parameters (#10617) 2024-12-10 13:50:35 -08:00
ping.go refactor: stop using go-libp2p deprecated peer.ID.Pretty 2023-09-18 15:58:15 +02:00
profile.go profile: add trace 2024-01-12 14:55:55 +01:00
provide.go feat(cli/rpc/add): fast provide of root CID (#11046) 2025-11-14 11:08:29 -08:00
pubsub.go refactor: use slices.Sort where appropriate (#10858) 2025-07-08 18:43:23 +02:00
refs.go chore: upgrade to go 1.23 (#10486) 2024-08-28 18:56:45 +02:00
repo.go fix: migrations for Windows (#11010) 2025-10-08 18:02:04 +02:00
resolve.go docs(cli): fix spelling 2023-12-04 09:40:21 +01:00
root_test.go core/corehttp!: remove /api/v0 from gateway port 2024-03-05 08:21:13 +00:00
root.go provider: clear provide queue when reprovide strategy changes (#10863) 2025-07-16 01:28:27 -07:00
routing.go feat(cli/rpc/add): fast provide of root CID (#11046) 2025-11-14 11:08:29 -08:00
shutdown.go refactor: rename to kubo 2022-07-06 18:40:37 +02:00
stat_dht.go feat(cli/rpc/add): fast provide of root CID (#11046) 2025-11-14 11:08:29 -08:00
stat_provide.go refactor: move ipfs stat provide/reprovide to ipfs provide stat (#10896) 2025-08-07 17:17:00 -07:00
stat_reprovide.go feat(ci): reusable spellcheck from unified CI (#10873) 2025-08-14 00:35:35 +00:00
stat.go feat: Provider.WorkerCount and stats reprovide (#10779) 2025-04-30 15:32:03 +02:00
swarm.go fix(cmds): cleanup unicode identify strings (#9465) 2025-09-19 04:46:38 +02:00
sysdiag.go repo: use config api to get node root path (#10934) 2025-09-02 13:13:01 -07:00
version.go feat(cli/rpc/add): fast provide of root CID (#11046) 2025-11-14 11:08:29 -08:00