Skip to content

fix: allow custom http provide when libp2p node is offline#10974

Merged
lidel merged 8 commits intomasterfrom
offline-http-provide
Sep 19, 2025
Merged

fix: allow custom http provide when libp2p node is offline#10974
lidel merged 8 commits intomasterfrom
offline-http-provide

Conversation

@guillaumemichel
Copy link
Contributor

@guillaumemichel guillaumemichel commented Sep 19, 2025

Fixes #10967

Current state

ipfs routing provide <cid> fails if kubo isn't connected to any other peer (libp2p). It doesn't even attempt to provide.

Problem

When custom Routing is used, it is acceptable to provide to a custom HTTP router (instead of a DHT over libp2p). If the node is configured to provide to a HTTP router, ipfs routing provide <cid> still fails if kubo isn't connected to other libp2p nodes. Such connections aren't necessary to provide to an HTTP endpoint.

Fix

Return the error cannot provide, no connected peers, only if no custom HTTP providers are configured AND kubo has no libp2p connections.

@guillaumemichel guillaumemichel requested a review from a team as a code owner September 19, 2025 09:46
@lidel lidel self-assigned this Sep 19, 2025
Routing.Type=custom is a niche power user feature without a spec,
so we don't want to bring attention to it in the changelog.
The functionality remains available for those who need it.
@lidel lidel added the skip/changelog This change does NOT require a changelog entry label Sep 19, 2025
- fixed comment/function name mismatch
- added mock server test for HTTP provide success
- clarified test names for offline scenarios
@lidel lidel force-pushed the offline-http-provide branch from 28157bc to 6fdf929 Compare September 19, 2025 14:01
use h.NewNode().Init() instead of NewNodes(1) for cleaner test setup
when no DHT is available but HTTP routers are configured for providing,
return NoopProvider instead of failing. this allows the daemon to start
and HTTP-based providing to work through the routing system.

moved HTTP provider detection to config package as HasHTTPProviderConfigured()
for better code organization and reusability.

this fix is important as SweepingProvider will become the new default in the future.
Comment on lines +356 to +361
// No DHT available, check if HTTP provider is configured
cfg, err := in.Repo.Config()
if err == nil && cfg.HasHTTPProviderConfigured() {
// HTTP provider is configured, return NoopProvider to allow HTTP-based providing
return &NoopProvider{}, keyStore, nil
}
Copy link
Member

@lidel lidel Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, tests failed because SweepingProvider failed to initialize when there's no DHT available, even when HTTP routers were configured for providing.

I've applied more surgical fix for now, will evaluate #10975 later.

@lidel lidel changed the title feat: allow custom http provide when offline fix: allow custom http provide when libp2p node is offline Sep 19, 2025
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some refactoring, hopefully not breaking anything.
We will ask Plebbit to test once 0.38.0-rc1 is tagged so low risk to merge.

@lidel lidel merged commit 6fcbba4 into master Sep 19, 2025
17 checks passed
@lidel lidel deleted the offline-http-provide branch September 19, 2025 16:55
lidel added a commit that referenced this pull request Sep 19, 2025
when SweepingProvider is enabled but no DHT is available (e.g., Routing.Type=none),
the daemon would panic with a nil pointer dereference in ResettableKeystore.ResetCids.

this fix:
- returns NoopProvider when no DHT implementation is available
- skips keystore initialization for NoopProvider to avoid unnecessary operations
- allows nodes to run without DHT when using HTTP-only routing or offline mode

the panic occurred because initKeyStore tried to access a nil keystore when
SweepingProvider returned nil for the keystore parameter. by checking if the
provider is NoopProvider and skipping keystore operations, we avoid the panic
while maintaining correct behavior for all other provider types.

cc #10974 #10975
lidel added a commit that referenced this pull request Sep 19, 2025
* fix: SweepingProvider shouldn't error when missing DHT

* fix: prevent panic when SweepingProvider has no DHT

when SweepingProvider is enabled but no DHT is available (e.g., Routing.Type=none),
the daemon would panic with a nil pointer dereference in ResettableKeystore.ResetCids.

this fix:
- returns NoopProvider when no DHT implementation is available
- skips keystore initialization for NoopProvider to avoid unnecessary operations
- allows nodes to run without DHT when using HTTP-only routing or offline mode

the panic occurred because initKeyStore tried to access a nil keystore when
SweepingProvider returned nil for the keystore parameter. by checking if the
provider is NoopProvider and skipping keystore operations, we avoid the panic
while maintaining correct behavior for all other provider types.

cc #10974 #10975

---------

Co-authored-by: Marcin Rataj <lidel@lidel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip/changelog This change does NOT require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipfs routing provide fails if we're not connected to peers even though we have HTTP routers configured

2 participants