fix: resolve addresses from host for HTTP delegated routing#11220
fix: resolve addresses from host for HTTP delegated routing#11220infektyd wants to merge 2 commits intoipfs:masterfrom
Conversation
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
There was a problem hiding this comment.
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
ConstructDelegatedRoutingto derive HTTP routing addresses fromhost.InfoFromHost(args.Host)instead ofhttpAddrsFromConfig(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.
| @@ -281,7 +290,7 @@ func ConstructDelegatedRouting(routers config.Routers, methods config.Methods, p | |||
| }, | |||
| &irouting.ExtraHTTPParams{ | |||
| PeerID: peerID, | |||
| Addrs: httpAddrsFromConfig(addrs), | |||
| Addrs: httpAddrs, | |||
| PrivKeyB64: privKey, | |||
There was a problem hiding this comment.
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.
| // 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`. |
There was a problem hiding this comment.
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.
| // 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>). |
| PeerID: peerID, | ||
| Addrs: httpAddrsFromConfig(addrs), | ||
| Addrs: httpAddrs, | ||
| PrivKeyB64: privKey, | ||
| HTTPRetrieval: httpRetrieval, | ||
| }, |
There was a problem hiding this comment.
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.
infektyd
left a comment
There was a problem hiding this comment.
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.
|
The CI cascade failure is due to a compilation error in The 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,
},
) |
Summary
When using custom HTTP delegated routing (
Routing.Type=custom), the raw listenaddresses from config (e.g.,
/ip4/0.0.0.0/tcp/24199) were sent to HTTP routersinstead of resolved interface addresses.
Problem
The
httpAddrsFromConfigfunction returned raw config addresses without resolving0.0.0.0to actual interface addresses. This caused provider records sent to HTTProuters to contain unusable
0.0.0.0addresses, forcing clients to fall back toDHT
FIND_PEERqueries and defeating the purpose of HTTP routing.Meanwhile,
ipfs idcorrectly resolves these addresses usinghost.InfoFromHost().Solution
Replace
httpAddrsFromConfig(addrs)withpeer.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.0listen addresses instead ofresolved interface addresses.
Changes
core/node/libp2p/routingopt.go: ModifiedConstructDelegatedRoutingto usehost-derived addresses instead of config-derived addresses.