ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
16.11k stars 3.01k forks source link

Binding UDP sockets to a non-IP address #10457

Closed hazae41 closed 3 months ago

hazae41 commented 3 months ago

Checklist

Description

Hello,

When deploying an IPFS node to fly.io, it requires binding UDP sockets to fly-global-services instead of 0.0.0.0, but it seems there is no way of doing this using a multiaddr on Addresses.Swarm

https://fly.io/docs/networking/udp-and-tcp/#your-app-needs-to-bind-to-the-fly-global-services-address

e.g. When using /ip4/fly-global-services/udp/4001/quic-v1 in Addresses.Swarm

Error: constructing the node (see log for full detail): failed to parse multiaddr "/ip4/fly-global-services/udp/4001/quic-v1": invalid value "fly-global-services" for protocol ip4: failed to parse ip4 addr: fly-global-services

Thanks

aschmahmann commented 3 months ago

Have you tried listening with a /dns multiaddr instead of /ip4?

The /ip4 multiaddr only takes IPv4 addresses not dns names.

hazae41 commented 3 months ago

@aschmahmann

It doesn't crash but it seems to be ignored since I get no log about it

"Swarm": [
    "/ip4/0.0.0.0/tcp/4001",
    "/dns/fly-global-services/udp/4001/quic-v1",
    "/dns/fly-global-services/udp/4001/quic-v1/webtransport"
]
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] Swarm listening on /ip4/127.0.0.1/tcp/4001
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] Swarm listening on /ip4/172.19.29.66/tcp/4001
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] Swarm listening on /ip4/172.19.29.67/tcp/4001
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] Swarm listening on /p2p-circuit
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] Swarm announcing /ip4/137.66.5.213/tcp/4001
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] RPC API access is limited by the rules defined in API.Authorizations
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] RPC API server listening on /ip4/0.0.0.0/tcp/5001
2024-07-12T04:22:57.528 app[17815122b42028] sin [info] WebUI: http://0.0.0.0:5001/webui
2024-07-12T04:22:57.529 app[17815122b42028] sin [info] Gateway server listening on /ip4/0.0.0.0/tcp/8080
2024-07-12T04:22:57.529 app[17815122b42028] sin [info] Daemon is ready

Do you know a way to test if UDP is listening?

hazae41 commented 3 months ago

@aschmahmann

I finally got it to work with /dns4

"Swarm": [
    "/ip4/0.0.0.0/tcp/4001",
    "/dns4/fly-global-services/udp/4001/quic-v1",
    "/dns4/fly-global-services/udp/4001/quic-v1/webtransport"
]
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm listening on /ip4/127.0.0.1/tcp/4001
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm listening on /ip4/172.19.29.66/tcp/4001
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm listening on /ip4/172.19.29.67/tcp/4001
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm listening on /ip4/172.19.29.67/udp/4001/quic-v1
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm listening on /ip4/172.19.29.67/udp/4001/quic-v1/webtransport/certhash/uEiDKoiVw6K7Gfnd3rc2ExVx4voS8vXaMr2MmNgLDoldOmw/certhash/uEiDMPRml9uL34V-Pr082sVFKFnSuX6oavUCpLYHHVCPV5g
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm listening on /p2p-circuit
2024-07-12T05:41:59.066 app[17815122b42028] sin [info] Swarm announcing /ip4/137.66.5.213/tcp/4001
2024-07-12T05:41:59.067 app[17815122b42028] sin [info] RPC API access is limited by the rules defined in API.Authorizations
2024-07-12T05:41:59.067 app[17815122b42028] sin [info] RPC API server listening on /ip4/0.0.0.0/tcp/5001
2024-07-12T05:41:59.067 app[17815122b42028] sin [info] WebUI: http://0.0.0.0:5001/webui
2024-07-12T05:41:59.067 app[17815122b42028] sin [info] Gateway server listening on /ip4/0.0.0.0/tcp/8080
2024-07-12T05:41:59.067 app[17815122b42028] sin [info] Daemon is ready

I found out about this by digging into go-multiaddr/net

https://github.com/multiformats/go-multiaddr/blob/14890877525b42c5d6450436929b059974f03ea4/net/net.go#L286

https://github.com/multiformats/go-multiaddr/blob/14890877525b42c5d6450436929b059974f03ea4/net/convert.go#L229

Maybe this should be better documented in

https://github.com/ipfs/kubo/blob/master/docs/config.md