mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 21:07:45 +08:00
p2p-forge hostnames encode IP addresses directly (e.g., 1-2-3-4.peerID.libp2p.direct -> 1.2.3.4), so DNS queries are wasteful. kubo now parses these IPs in-memory. - applies to both default libp2p.direct and custom AutoTLS.DomainSuffix - TXT queries still delegate to network for ACME DNS-01 compatibility Fixes #11136
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package node
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
|
|
"github.com/ipfs/boxo/gateway"
|
|
config "github.com/ipfs/kubo/config"
|
|
doh "github.com/libp2p/go-doh-resolver"
|
|
madns "github.com/multiformats/go-multiaddr-dns"
|
|
)
|
|
|
|
func DNSResolver(cfg *config.Config) (*madns.Resolver, error) {
|
|
var dohOpts []doh.Option
|
|
if !cfg.DNS.MaxCacheTTL.IsDefault() {
|
|
dohOpts = append(dohOpts, doh.WithMaxCacheTTL(cfg.DNS.MaxCacheTTL.WithDefault(time.Duration(math.MaxUint32)*time.Second)))
|
|
}
|
|
|
|
// Replace "auto" DNS resolver placeholders with autoconf values
|
|
resolvers := cfg.DNSResolversWithAutoConf()
|
|
|
|
// Get base resolver from boxo (handles custom DoH resolvers per eTLD)
|
|
baseResolver, err := gateway.NewDNSResolver(resolvers, dohOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Build list of p2p-forge domains to resolve locally without network I/O.
|
|
// AutoTLS hostnames encode IP addresses directly (e.g., 1-2-3-4.peerID.libp2p.direct),
|
|
// so DNS lookups are wasteful. We always resolve these in-memory.
|
|
forgeDomains := []string{config.DefaultDomainSuffix}
|
|
customDomain := cfg.AutoTLS.DomainSuffix.WithDefault(config.DefaultDomainSuffix)
|
|
if customDomain != config.DefaultDomainSuffix {
|
|
forgeDomains = append(forgeDomains, customDomain)
|
|
}
|
|
forgeResolver := NewP2PForgeResolver(forgeDomains, baseResolver)
|
|
|
|
// Register p2p-forge resolver for each domain, fallback to baseResolver for others
|
|
opts := []madns.Option{madns.WithDefaultResolver(baseResolver)}
|
|
for _, domain := range forgeDomains {
|
|
opts = append(opts, madns.WithDomainResolver(domain+".", forgeResolver))
|
|
}
|
|
|
|
return madns.NewResolver(opts...)
|
|
}
|