Are /dnsaddr
multiaddr not automagically Resolve
d anymore?
#2883
Replies: 2 comments
-
I think this is working as designed. In go-libp2p, we don't dial a peer unless we know its peer id up front. If this just worked, we'd trust DNS to give us the target's peer ID which can be unsafe (depending on how you actually do DNS). Look at how Kubo uses dnsaddrs: https://github.com/ipfs/kubo/blob/master/config/bootstrap_peers.go#L18-L21. It includes the peer id. I think there is a way to dial a peer without its peer-id, but it's not easy. You essentially use a bogus peer id, and then read the actual peer id from the error. We could try to make this easier without introducing a foot gun, but I haven't seen a need for it yet. |
Beta Was this translation helpful? Give feedback.
-
I’ve done something similar before, but I used the following approach. In your DNS, you can follow this specs. But as @MarcoPolo mentioned, in your DNS record, we pass the peerid.
Example: package main
import (
"context"
"fmt"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
dnsaddr "github.com/multiformats/go-multiaddr-dns"
"os"
)
func ResolvePeerAddrFromDNS(ctx context.Context, dns string) ([]*peer.AddrInfo, error) {
m1, err := ma.NewMultiaddr(fmt.Sprintf("/dnsaddr/%s", dns))
if err != nil {
return nil, err
}
ms, err := dnsaddr.Resolve(ctx, m1)
if err != nil {
return nil, err
}
peers := make([]*peer.AddrInfo, len(ms))
for i, m := range ms {
peers[i], err = peer.AddrInfoFromP2pAddr(m)
if err != nil {
continue
}
}
return peers, nil
} |
Beta Was this translation helpful? Give feedback.
-
I'm pretty sure that this used to work:
However it now fails with "
AddrInfoFromP2pAddr error: invalid p2p multiaddr
".Is it normal that a
dnsaddr
such as/dnsaddr/api2.drand.sh
isn't resolved automagically by libp2p anymore and that I now instead have to calldnsaddr.Resolve
manually and go through extra hoops to use it?I now instead have to expect a dnsaddr value and Resolve it manually as far as I can tell:
Beta Was this translation helpful? Give feedback.
All reactions