Skip to content

fix: resolve addresses from host for HTTP delegated routing#11220

Open
infektyd wants to merge 2 commits intoipfs:masterfrom
infektyd:master
Open

fix: resolve addresses from host for HTTP delegated routing#11220
infektyd wants to merge 2 commits intoipfs:masterfrom
infektyd:master

Conversation

@infektyd
Copy link

@infektyd infektyd commented Mar 2, 2026

Summary

When using custom HTTP delegated routing (Routing.Type=custom), the raw listen
addresses from config (e.g., /ip4/0.0.0.0/tcp/24199) were sent to HTTP routers
instead of resolved interface addresses.

Problem

The httpAddrsFromConfig function returned raw config addresses without resolving
0.0.0.0 to actual interface addresses. This caused provider records sent to HTTP
routers to contain unusable 0.0.0.0 addresses, forcing clients to fall back to
DHT FIND_PEER queries and defeating the purpose of HTTP routing.

Meanwhile, ipfs id correctly resolves these addresses using host.InfoFromHost().

Solution

Replace httpAddrsFromConfig(addrs) with peer.AddrInfoToP2pAddrs(host.InfoFromHost(args.Host))
to obtain resolved addresses from the libp2p host, matching the behavior of ipfs id.

Testing

This fix addresses the issue described in #11213 where
HTTP Routing V1 provider records contain raw 0.0.0.0 listen addresses instead of
resolved interface addresses.

Changes

  • core/node/libp2p/routingopt.go: Modified ConstructDelegatedRouting to use
    host-derived addresses instead of config-derived addresses.

Previously, when using custom HTTP delegated routing (Routing.Type=custom),
the raw listen addresses from config (e.g., /ip4/0.0.0.0/tcp/24199) were sent
to HTTP routers instead of resolved interface addresses.

This caused provider records to contain unusable 0.0.0.0 addresses, forcing
clients to fall back to DHT FIND_PEER queries.

The fix uses host.InfoFromHost() to get resolved addresses from the libp2p
host, matching the behavior of 'ipfs id' which correctly reports resolved
interface addresses.

Fixes: ipfs#11213
Copilot AI review requested due to automatic review settings March 2, 2026 00:41
@infektyd infektyd requested a review from a team as a code owner March 2, 2026 00:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes HTTP delegated routing (when Routing.Type=custom) so provider metadata sent to HTTP routers uses resolved interface addresses derived from the libp2p host rather than raw config listen addrs (e.g., avoiding /ip4/0.0.0.0/...).

Changes:

  • Update ConstructDelegatedRouting to derive HTTP routing addresses from host.InfoFromHost(args.Host) instead of httpAddrsFromConfig(addrs).
  • Add error handling and clarifying comments around host-derived address selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 278 to 294
@@ -281,7 +290,7 @@ func ConstructDelegatedRouting(routers config.Routers, methods config.Methods, p
},
&irouting.ExtraHTTPParams{
PeerID: peerID,
Addrs: httpAddrsFromConfig(addrs),
Addrs: httpAddrs,
PrivKeyB64: privKey,
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

peer.AddrInfoToP2pAddrs(...) returns []ma.Multiaddr, but irouting.ExtraHTTPParams.Addrs is []string (see routing/delegated.go). As written, Addrs: httpAddrs will not compile. Convert the resolved multiaddrs to strings (e.g., m.String()) before assigning to ExtraHTTPParams.Addrs.

Copilot uses AI. Check for mistakes.
Comment on lines +275 to +277
// This ensures we send resolved interface addresses (e.g., /ip4/192.168.x.x/tcp/24199)
// instead of unresolved listen addresses (e.g., /ip4/0.0.0.0/tcp/24199)
// to HTTP delegated routers, matching the behavior of `ipfs id`.
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The comment examples mention resolved addresses like /ip4/192.168.x.x/tcp/24199 (no /p2p/<peerid>), but the current implementation uses peer.AddrInfoToP2pAddrs(...), which appends /p2p/<peerid> to each multiaddr. Either update the comment examples to match the actual format or switch to using host.InfoFromHost(args.Host).Addrs (stringified) if the HTTP router expects bare transport multiaddrs.

Suggested change
// This ensures we send resolved interface addresses (e.g., /ip4/192.168.x.x/tcp/24199)
// instead of unresolved listen addresses (e.g., /ip4/0.0.0.0/tcp/24199)
// to HTTP delegated routers, matching the behavior of `ipfs id`.
// This ensures we send resolved interface addresses (e.g., /ip4/192.168.x.x/tcp/24199/p2p/<peerid>)
// instead of unresolved listen addresses (e.g., /ip4/0.0.0.0/tcp/24199/p2p/<peerid>)
// to HTTP delegated routers, matching the behavior of `ipfs id` (which includes /p2p/<peerid>).

Copilot uses AI. Check for mistakes.
Comment on lines 292 to 296
PeerID: peerID,
Addrs: httpAddrsFromConfig(addrs),
Addrs: httpAddrs,
PrivKeyB64: privKey,
HTTPRetrieval: httpRetrieval,
},
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

With this change, the addrs config.Addresses parameter to ConstructDelegatedRouting is no longer used (the prior httpAddrsFromConfig(addrs) call is gone). Consider removing that parameter (and updating the one call site) to avoid suggesting that config-derived address filtering still applies here.

Copilot uses AI. Check for mistakes.
Copy link
Author

@infektyd infektyd left a comment

Choose a reason for hiding this comment

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

Ah, I see what blew up the CI here. In , on expects , but returns . This causes the compiler to hard-fail, killing the and processes instantly. You just need to convert the multiaddrs to strings via a quick loop before passing them into the struct.

@infektyd
Copy link
Author

infektyd commented Mar 3, 2026

The CI cascade failure is due to a compilation error in core/node/libp2p/routingopt.go on line 293.

The Addrs field on irouting.ExtraHTTPParams expects a []string, but peer.AddrInfoToP2pAddrs returns variables of type []multiaddr.Multiaddr. This hard-fails the compiler during go-build and go-lint.

To fix this, you just need a quick loop to convert the types:

httpAddrs, err := peer.AddrInfoToP2pAddrs(host.InfoFromHost(args.Host))
if err != nil {
	return nil, fmt.Errorf("getting HTTP routing addresses from host: %w", err)
}

var httpAddrStrs []string
for _, addr := range httpAddrs {
	httpAddrStrs = append(httpAddrStrs, addr.String())
}

return irouting.Parse(routers, methods,
	&irouting.ExtraDHTParams{
		// ... existing params
	},
	&irouting.ExtraHTTPParams{
		PeerID:        peerID,
		Addrs:         httpAddrStrs, // Pass the converted string array
		PrivKeyB64:    privKey,
		HTTPRetrieval: httpRetrieval,
	},
)

Copy link
Author

@infektyd infektyd left a comment

Choose a reason for hiding this comment

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

Testing re-trigger

@gammazero gammazero added the need/maintainers-input Needs input from the current maintainer(s) label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need/maintainers-input Needs input from the current maintainer(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants