Skip to content

Conversation

@gammazero
Copy link
Contributor

@gammazero gammazero commented Sep 22, 2025

@gammazero gammazero marked this pull request as ready for review September 23, 2025 03:25
- Set delegated routing endpoint using environ var
- Fix autoconf disabled error message
@lidel
Copy link
Member

lidel commented Sep 30, 2025

Triage note:

  • @lidel will review once Kubo 0.38 ships

@lidel lidel changed the title Autoconf feat(config): autoconf support Oct 1, 2025
@lidel lidel changed the title feat(config): autoconf support feat: autoconf support Oct 1, 2025
gammazero and others added 8 commits November 11, 2025 19:39
ensures autoconf client uses mainnet fallback config when server is unreachable or cache is empty
replaces dht.GetDefaultBootstrapPeerAddrInfos with autoconf.FallbackBootstrapPeers to align with kubo's approach
changes '--endpoing' to '--endpoint'
- set all three endpoint types (provider, peer, IPNS) to default to 'auto'
- expand and validate endpoint URLs per flag to support custom configurations
- accept both base URLs (https://example.com) and full URLs with routing paths
- strip routing paths after validation to get base URLs for HTTP client
- validate path matches flag type, error on mismatches with helpful messages
- update stdout to show routing paths explicitly (/routing/v1/providers)
- add spec references to Routing V1 and IPFS Mainnet in docs
- simplify documentation following godoc style

This ensures endpoints only receive requests they support (e.g., cid.contact
only gets provider requests, not peers or IPNS).
when the same base URL appears in multiple endpoint configs
(provider/peer/ipns), create only ONE HTTP client instead of
three separate clients with duplicate connection pools

this was not an issue with cid.contact as it only supported /providers,
but is necessary to future-proof if autoconf provides more routing systems
in the future

implementation:
- client_delegated_routing.go: new file for delegated routing client logic
- collectEndpoints: deduplicates URLs and aggregates capabilities
- createDelegatedHTTPRouters: creates one client per unique base URL
  and registers metrics once for all delegated HTTP clients
- combineRouters: simplified to combine routers without client creation
- clientRouter: moved from server_routers.go to co-locate with client creation

same client instance is reused across routing types when base URL matches,
significantly reducing memory and connection overhead
- add file-level godoc to autoconf.go
- fix parameter shadowing in createAutoConfClient
- add validation for empty strings in collectEndpoints
- add tests for collectEndpoints deduplication logic
- add trailing slash normalization tests
- inline autoconfDisabledError (single use function)
- add newDelegatedRoutingClient helper for consistent HTTP client creation
- use helper in both server and CLI code to ensure consistent options
- rename client_delegated_routing.go to server_delegated_routing.go
- add file-level documentation explaining server-side delegated routing
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.

Thank you @gammazero!

The autoconf implementation was really solid and basically feature-complete for how things (cid.contact) work today. I just tweaked a few things to match Kubo's configuration patterns better and be more future-proof if we have more routing systems in the future (so they are picked up without us having to do any code changes again):

  • Wired the endpoint configuration into all three flags (added to --peer-endpoints, --ipns-endpoints).
  • Moved things around to avoid creating duplicate HTTP clients when same URL appears in multiple places (e.g. providers, peers and ipns). Now we create one client per base URL and reuse across routing types (helps with HTTP/2+ mux).
  • Both issues above were not a problem today since cid.contact only supports /routing/v1/providers, but future-proofs us for multi-capability endpoints.
  • Added some tests and docs

If this looks good, feel free to merge, I plan to make release later this week if no concerns.

@gammazero gammazero merged commit ec76365 into main Nov 19, 2025
7 checks passed
@gammazero gammazero deleted the autoconf branch November 19, 2025 07:48
lidel added a commit that referenced this pull request Nov 19, 2025
…sabled

fixes two issues with the GetClosestPeers endpoint:

1. endpoint returned HTTP 200 with empty results instead of actual DHT peers
2. when DHT disabled, returned HTTP 200 with empty results instead of error

root cause:
during rebase of PR #124 (commit 0dad3f7) when integrating with autoconf
refactor (PR #123 / ec76365), the dhtRouters initialization was accidentally
omitted from server.go. the autoconf PR renamed getCombinedRouting to
combineRouters and changed its signature, but the rebase failed to preserve
the dhtRouters creation line that existed in commit 42bd221.

changes:
- server.go:201-208: add explicit dhtRouters creation with caching and
  sanitization, similar to original 42bd221 implementation
- server.go:232: wire dhtRouters to composableRouter.dht field
- server.go:338: update combineRouters signature to accept host.Host
  parameter needed for GetClosestPeers peerstore lookups
- server_routers.go:73-77: return routing.ErrNotSupported instead of empty
  iterator when DHT is nil, resulting in HTTP 500 instead of misleading
  HTTP 200
- server_test.go:16,20,24: update combineRouters test calls with new signature
- server_dht_test.go:355-379: add test verifying HTTP 500 when DHT disabled
hsanjuan pushed a commit that referenced this pull request Nov 20, 2025
…sabled (#127)

fixes two issues with the GetClosestPeers endpoint:

1. endpoint returned HTTP 200 with empty results instead of actual DHT peers
2. when DHT disabled, returned HTTP 200 with empty results instead of error

root cause:
during rebase of PR #124 (commit 0dad3f7) when integrating with autoconf
refactor (PR #123 / ec76365), the dhtRouters initialization was accidentally
omitted from server.go. the autoconf PR renamed getCombinedRouting to
combineRouters and changed its signature, but the rebase failed to preserve
the dhtRouters creation line that existed in commit 42bd221.

changes:
- server.go:201-208: add explicit dhtRouters creation with caching and
  sanitization, similar to original 42bd221 implementation
- server.go:232: wire dhtRouters to composableRouter.dht field
- server.go:338: update combineRouters signature to accept host.Host
  parameter needed for GetClosestPeers peerstore lookups
- server_routers.go:73-77: return routing.ErrNotSupported instead of empty
  iterator when DHT is nil, resulting in HTTP 500 instead of misleading
  HTTP 200
- server_test.go:16,20,24: update combineRouters test calls with new signature
- server_dht_test.go:355-379: add test verifying HTTP 500 when DHT disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants